Use id() for constraints instead of keywords

This commit is contained in:
Gaith Hallak 2022-06-11 21:52:23 +04:00
parent 3f177d363f
commit f56eeb0b2b
4 changed files with 6 additions and 8 deletions

View File

@ -98,10 +98,10 @@ namespace String =
private function
to_int_([], _, x, _) = Some(x)
to_int_(i :: is, value, x, b) =
to_int_(i :: ints, value, x, b) =
switch(value(i))
None => None
Some(n) => to_int_(is, value, x * b + n, b)
Some(i) => to_int_(ints, value, x * b + i, b)
private function ch_to_int_10(ch) =
let c = Char.to_int(ch)

View File

@ -135,8 +135,7 @@ fun_block(Mods, Kind, 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)}).
?RULE(tvar(), keyword(is), id(), {constraint, get_ann(_1), _1, _3}).
typevars_constraints() ->
?RULE(comma_sep1(typevar_constraint()), tok(';'), _1).

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", "using", "as", "for", "hiding", "is", "eq", "ord"
"interface", "main", "using", "as", "for", "hiding", "is"
],
KW = string:join(Keywords, "|"),

View File

@ -79,15 +79,14 @@
-type constructor_t() :: {constr_t, ann(), con(), [type()]}.
-type tvar_constraint() :: eq | ord.
-type constraint() :: {constraint, ann(), name(), tvar_constraint()}.
-type tvar_constraint() :: {constraint, ann(), tvar(), id()}.
-type type() :: {fun_t, ann(), [named_arg_t()], [type()], type()}
| {app_t, ann(), type(), [type()]}
| {tuple_t, ann(), [type()]}
| {args_t, ann(), [type()]} %% old tuple syntax, old for error messages
| {bytes_t, ann(), integer() | any}
| {constrained_t, ann(), [constraint()], type()}
| {constrained_t, ann(), [tvar_constraint()], type()}
| id() | qid()
| con() | qcon() %% contracts
| tvar().