Add constraints to the syntax and parser
This commit is contained in:
parent
b599d581ee
commit
3f177d363f
@ -134,9 +134,20 @@ fun_block(Mods, Kind, [Decl]) ->
|
|||||||
fun_block(Mods, Kind, Decls) ->
|
fun_block(Mods, Kind, Decls) ->
|
||||||
{block, get_ann(Kind), [ add_modifiers(Mods, Kind, Decl) || Decl <- Decls ]}.
|
{block, get_ann(Kind), [ add_modifiers(Mods, Kind, Decl) || Decl <- Decls ]}.
|
||||||
|
|
||||||
|
typevar_constraint() ->
|
||||||
|
?RULE(tvar(), keyword(is), choice([tok(eq), tok(ord)]),
|
||||||
|
{constraint, element(2, _1), element(3, _1), element(1, _3)}).
|
||||||
|
|
||||||
|
typevars_constraints() ->
|
||||||
|
?RULE(comma_sep1(typevar_constraint()), tok(';'), _1).
|
||||||
|
|
||||||
|
fundecl() ->
|
||||||
|
choice([?RULE(id(), tok(':'), typevars_constraints(), type(),
|
||||||
|
{fun_decl, get_ann(_1), _1, {constrained_t, get_ann(_1), _3, _4}}),
|
||||||
|
?RULE(id(), tok(':'), type(), {fun_decl, get_ann(_1), _1, _3})]).
|
||||||
|
|
||||||
fundef_or_decl() ->
|
fundef_or_decl() ->
|
||||||
choice([?RULE(id(), tok(':'), type(), {fun_decl, get_ann(_1), _1, _3}),
|
choice([fundecl(), fundef()]).
|
||||||
fundef()]).
|
|
||||||
|
|
||||||
using() ->
|
using() ->
|
||||||
Alias = {keyword(as), con()},
|
Alias = {keyword(as), con()},
|
||||||
@ -527,6 +538,7 @@ parens(P) -> between(tok('('), P, tok(')')).
|
|||||||
braces(P) -> between(tok('{'), P, tok('}')).
|
braces(P) -> between(tok('{'), P, tok('}')).
|
||||||
brackets(P) -> between(tok('['), P, tok(']')).
|
brackets(P) -> between(tok('['), P, tok(']')).
|
||||||
comma_sep(P) -> sep(P, tok(',')).
|
comma_sep(P) -> sep(P, tok(',')).
|
||||||
|
comma_sep1(P) -> sep1(P, tok(',')).
|
||||||
|
|
||||||
paren_list(P) -> parens(comma_sep(P)).
|
paren_list(P) -> parens(comma_sep(P)).
|
||||||
brace_list(P) -> braces(comma_sep(P)).
|
brace_list(P) -> braces(comma_sep(P)).
|
||||||
|
@ -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", "using", "as", "for", "hiding"
|
"interface", "main", "using", "as", "for", "hiding", "is", "eq", "ord"
|
||||||
],
|
],
|
||||||
KW = string:join(Keywords, "|"),
|
KW = string:join(Keywords, "|"),
|
||||||
|
|
||||||
|
@ -79,11 +79,15 @@
|
|||||||
|
|
||||||
-type constructor_t() :: {constr_t, ann(), con(), [type()]}.
|
-type constructor_t() :: {constr_t, ann(), con(), [type()]}.
|
||||||
|
|
||||||
|
-type tvar_constraint() :: eq | ord.
|
||||||
|
-type constraint() :: {constraint, ann(), name(), tvar_constraint()}.
|
||||||
|
|
||||||
-type type() :: {fun_t, ann(), [named_arg_t()], [type()], type()}
|
-type type() :: {fun_t, ann(), [named_arg_t()], [type()], type()}
|
||||||
| {app_t, ann(), type(), [type()]}
|
| {app_t, ann(), type(), [type()]}
|
||||||
| {tuple_t, ann(), [type()]}
|
| {tuple_t, ann(), [type()]}
|
||||||
| {args_t, ann(), [type()]} %% old tuple syntax, old for error messages
|
| {args_t, ann(), [type()]} %% old tuple syntax, old for error messages
|
||||||
| {bytes_t, ann(), integer() | any}
|
| {bytes_t, ann(), integer() | any}
|
||||||
|
| {constrained_t, ann(), [constraint()], type()}
|
||||||
| id() | qid()
|
| id() | qid()
|
||||||
| con() | qcon() %% contracts
|
| con() | qcon() %% contracts
|
||||||
| tvar().
|
| tvar().
|
||||||
|
Loading…
x
Reference in New Issue
Block a user