recognize all simple tokens
still need to do delimiters but those require some special handling
This commit is contained in:
parent
a0c03e8cfe
commit
294239abb9
1 changed files with 7 additions and 3 deletions
|
@ -16,13 +16,16 @@ This module contains functions for tokenizing Akhamoth source code.
|
|||
-define(is_space(C), C =:= $\s; C =:= $\t).
|
||||
|
||||
-define(is_op2(T), T =:= <<"|>">>; T =:= <<"=>">>; T =:= <<"->">>; T =:= <<"==">>).
|
||||
-define(is_op1(T),
|
||||
-define(is_single(T),
|
||||
T =:= <<"+">>;
|
||||
T =:= <<"-">>;
|
||||
T =:= <<"*">>;
|
||||
T =:= <<"/">>;
|
||||
T =:= <<"=">>;
|
||||
T =:= <<".">>
|
||||
T =:= <<".">>;
|
||||
T =:= <<",">>;
|
||||
T =:= <<";">>;
|
||||
T =:= <<":">>
|
||||
).
|
||||
|
||||
-doc """
|
||||
|
@ -40,6 +43,7 @@ Tokens for which the category is the same as the content.
|
|||
| '->'
|
||||
| '=='
|
||||
| ','
|
||||
| ';'
|
||||
| ':'
|
||||
| '('
|
||||
| ')'
|
||||
|
@ -98,7 +102,7 @@ next(#lexer{source = <<C, Rest/binary>>} = Lx) when ?is_space(C) ->
|
|||
next(Lx#lexer{source = Rest, offset = Lx#lexer.offset + 1});
|
||||
next(#lexer{source = <<T:2/binary, Rest/binary>>, offset = Offset} = Lx) when ?is_op2(T) ->
|
||||
{ok, {binary_to_atom(T), Offset}, Lx#lexer{source = Rest, offset = Offset + 2}};
|
||||
next(#lexer{source = <<T:1/binary, Rest/binary>>, offset = Offset} = Lx) when ?is_op1(T) ->
|
||||
next(#lexer{source = <<T:1/binary, Rest/binary>>, offset = Offset} = Lx) when ?is_single(T) ->
|
||||
{ok, {binary_to_atom(T), Offset}, Lx#lexer{source = Rest, offset = Offset + 1}};
|
||||
next(#lexer{source = <<$\n, Rest/binary>>} = Lx) ->
|
||||
new_line(Lx#lexer{source = Rest, offset = Lx#lexer.offset + 1});
|
||||
|
|
Loading…
Add table
Reference in a new issue