Add using namespace as to scanner and parser
This commit is contained in:
parent
262452fb70
commit
53ba62e423
@ -109,6 +109,7 @@ decl() ->
|
|||||||
|
|
||||||
, ?RULE(keyword(namespace), con(), tok('='), maybe_block(decl()), {namespace, _1, _2, _4})
|
, ?RULE(keyword(namespace), con(), tok('='), maybe_block(decl()), {namespace, _1, _2, _4})
|
||||||
, ?RULE(keyword(include), str(), {include, get_ann(_1), _2})
|
, ?RULE(keyword(include), str(), {include, get_ann(_1), _2})
|
||||||
|
, using()
|
||||||
, pragma()
|
, pragma()
|
||||||
|
|
||||||
%% Type declarations TODO: format annotation for "type bla" vs "type bla()"
|
%% 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}),
|
choice([?RULE(id(), tok(':'), type(), {fun_decl, get_ann(_1), _1, _3}),
|
||||||
fundef()]).
|
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() ->
|
pragma() ->
|
||||||
Op = choice([token(T) || T <- ['<', '=<', '==', '>=', '>']]),
|
Op = choice([token(T) || T <- ['<', '=<', '==', '>=', '>']]),
|
||||||
?RULE(tok('@'), id("compiler"), Op, version(), {pragma, get_ann(_1), {compiler, element(1, _3), _4}}).
|
?RULE(tok('@'), id("compiler"), Op, version(), {pragma, get_ann(_1), {compiler, element(1, _3), _4}}).
|
||||||
|
@ -45,7 +45,7 @@ lexer() ->
|
|||||||
|
|
||||||
Keywords = ["contract", "include", "let", "switch", "type", "record", "datatype", "if", "elif", "else", "function",
|
Keywords = ["contract", "include", "let", "switch", "type", "record", "datatype", "if", "elif", "else", "function",
|
||||||
"stateful", "payable", "true", "false", "mod", "public", "entrypoint", "private", "indexed", "namespace",
|
"stateful", "payable", "true", "false", "mod", "public", "entrypoint", "private", "indexed", "namespace",
|
||||||
"interface", "main"
|
"interface", "main", "using", "as"
|
||||||
],
|
],
|
||||||
KW = string:join(Keywords, "|"),
|
KW = string:join(Keywords, "|"),
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
| {type_def, ann(), id(), [tvar()], typedef()}
|
| {type_def, ann(), id(), [tvar()], typedef()}
|
||||||
| {fun_clauses, ann(), id(), type(), [letfun() | fundecl()]}
|
| {fun_clauses, ann(), id(), type(), [letfun() | fundecl()]}
|
||||||
| {block, ann(), [decl()]}
|
| {block, ann(), [decl()]}
|
||||||
|
| using()
|
||||||
| fundecl()
|
| fundecl()
|
||||||
| letfun()
|
| letfun()
|
||||||
| letval(). % Only for error msgs
|
| letval(). % Only for error msgs
|
||||||
@ -52,6 +53,8 @@
|
|||||||
|
|
||||||
-type pragma() :: {compiler, '==' | '<' | '>' | '=<' | '>=', compiler_version()}.
|
-type pragma() :: {compiler, '==' | '<' | '>' | '=<' | '>=', compiler_version()}.
|
||||||
|
|
||||||
|
-type using() :: {using, ann(), con()}
|
||||||
|
| {using, ann(), con(), id()}.
|
||||||
|
|
||||||
-type letval() :: {letval, ann(), pat(), expr()}.
|
-type letval() :: {letval, ann(), pat(), expr()}.
|
||||||
-type letfun() :: {letfun, ann(), id(), [pat()], type(), expr()}.
|
-type letfun() :: {letfun, ann(), id(), [pat()], type(), expr()}.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user