Elexer (elexer v0.0.3)
Elexer: a lexing library for the Elixir programming language.
Elexer is designed to be simple and lightweight, and easy to learn.
GitHub: https://github.com/VideoCarp/Elexer
Example: https://github.com/VideoCarp/Elexer/blob/main/example.ex
Learn by-hand lexing: https://gist.github.com/VideoCarp/d7cec2195a7de370d850aead62fa09cd
Learn Elexer: not yet available. These docs should be quite helpful, though.
Link to this section Summary
Functions
'tag' describes the token. Lex takes in the following: input_str: String, singlecharh: Function/1, multicharh: Function/1, otherwise: Function/0, # optional
Does nothing. Used when a function is to be called, but no effect is desired.
The actual lexing function. Not for your use, but for your contribution. See the lex
function instead if you plan to use it.
Link to this section Functions
lex(input_str, singlecharh, multicharh, otherwise \\ ¬hing/0)
'tag' describes the token. Lex takes in the following: input_str: String, singlecharh: Function/1, multicharh: Function/1, otherwise: Function/0, # optional
input_str
the program to lex
singlecharh
the function that returns {bool, atom}
where 'bool' is given when a match is made,
and 'atom' is given as the argument for the tag to the match.
For example, a function that matches "(" to return {true, :oparen}
while also matching ")" to return {true, :cparen}
'singlecharh' should contain what tokens to match and their tag.
Code example (of a function taking 'character' as its sole argument)
cond do
char == "(" ->
{true, :oparen}
char == ")"->
{true, :cparen}
char == "!" ->
{true, :not}
true ->
{false, :pass}
end
Example on repository. This will allow the lexer to lex these characters. Given a string "()" the lexer will be able to lex that into:
[{"(", :oparen}, {")", :cparen}]
multichar
: the function that returns {bool, atom}
where 'bool' is given as 'true' when the character satisfies the required
condition, and 'atom' is the tag.
For example, a function that matches alphanumeric characters or underscore
while also matching another multi-character pattern.
Effectively used the same way as 'singlecharh'. Example in repository.
otherwise
: what to execute if elexer encounters a foreigh character.
For example, if 'otherwise' is a function that prints an error, it will print the error when a foreigh character is found.
To give lex
these arguments, you should use the &function/arity
syntax, where 'arity' is the number of arguments.
nothing()
Does nothing. Used when a function is to be called, but no effect is desired.
uglex(current, tokenstream, len, input_str, singlecharh, multicharh, otherwise, tmp)
The actual lexing function. Not for your use, but for your contribution. See the lex
function instead if you plan to use it.