From 53ba62e423bcc19392365513fdeb2dbbcbe594df Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Fri, 13 Aug 2021 20:03:20 +0300 Subject: [PATCH] Add using namespace as to scanner and parser --- src/aeso_parser.erl | 9 +++++++++ src/aeso_scan.erl | 2 +- src/aeso_syntax.erl | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/aeso_parser.erl b/src/aeso_parser.erl index c29403d..e833ca0 100644 --- a/src/aeso_parser.erl +++ b/src/aeso_parser.erl @@ -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}}). diff --git a/src/aeso_scan.erl b/src/aeso_scan.erl index 2c5d301..ec47e4f 100644 --- a/src/aeso_scan.erl +++ b/src/aeso_scan.erl @@ -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, "|"), diff --git a/src/aeso_syntax.erl b/src/aeso_syntax.erl index cab8edc..44c8b7c 100644 --- a/src/aeso_syntax.erl +++ b/src/aeso_syntax.erl @@ -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()}.