Add using namespace as to scanner and parser

This commit is contained in:
Gaith Hallak 2021-08-13 20:03:20 +03:00
parent 262452fb70
commit 53ba62e423
3 changed files with 13 additions and 1 deletions

View File

@ -109,6 +109,7 @@ decl() ->
, ?RULE(keyword(namespace), con(), tok('='), maybe_block(decl()), {namespace, _1, _2, _4})
, ?RULE(keyword(include), str(), {include, get_ann(_1), _2})
, using()
, pragma()
%% Type declarations TODO: format annotation for "type bla" vs "type bla()"
@ -135,6 +136,14 @@ fundef_or_decl() ->
choice([?RULE(id(), tok(':'), type(), {fun_decl, get_ann(_1), _1, _3}),
fundef()]).
using() ->
?RULE(keyword(using), con(), optional({keyword(as), id()}), using(get_ann(_1), _2, _3)).
using(Ann, Con, none) ->
{using, Ann, Con};
using(Ann, Con, {ok, {_, Id}}) ->
{using, Ann, Con, Id}.
pragma() ->
Op = choice([token(T) || T <- ['<', '=<', '==', '>=', '>']]),
?RULE(tok('@'), id("compiler"), Op, version(), {pragma, get_ann(_1), {compiler, element(1, _3), _4}}).

View File

@ -45,7 +45,7 @@ lexer() ->
Keywords = ["contract", "include", "let", "switch", "type", "record", "datatype", "if", "elif", "else", "function",
"stateful", "payable", "true", "false", "mod", "public", "entrypoint", "private", "indexed", "namespace",
"interface", "main"
"interface", "main", "using", "as"
],
KW = string:join(Keywords, "|"),

View File

@ -44,6 +44,7 @@
| {type_def, ann(), id(), [tvar()], typedef()}
| {fun_clauses, ann(), id(), type(), [letfun() | fundecl()]}
| {block, ann(), [decl()]}
| using()
| fundecl()
| letfun()
| letval(). % Only for error msgs
@ -52,6 +53,8 @@
-type pragma() :: {compiler, '==' | '<' | '>' | '=<' | '>=', compiler_version()}.
-type using() :: {using, ann(), con()}
| {using, ann(), con(), id()}.
-type letval() :: {letval, ann(), pat(), expr()}.
-type letfun() :: {letfun, ann(), id(), [pat()], type(), expr()}.