Fix apply bug with keyword

This commit is contained in:
백현웅 2022-02-08 22:03:16 +09:00
parent edeff67edb
commit cd3487dd81

View file

@ -80,6 +80,10 @@ let token_to_op tok =
let token_is_operator tok =
Hashtbl.mem operators tok
let is_keyword = function
| "if" | "then" | "else" | "let" -> true
| _ -> false
(* common parsers *)
let any seq =
@ -175,13 +179,12 @@ and let_value seq =
*)
and expr pre seq =
seq |> oneof [
(either unary value) @> binop pre;
ifexpr;
oneof [apply; unary; value] @> binop pre;
level;
assoc;
lambda;
extern_value;
apply;
]
(* level := "level" {"get" | "set"} [op] *)
@ -260,6 +263,7 @@ and value seq =
match seq () with
| Seq.Nil -> raise End_of_tokens
| Seq.Cons (x, seq) -> begin match x with
| Ident id when is_keyword id -> failwith "value"
| Ident "true" -> Nbool true, seq
| Ident "false" -> Nbool false, seq
| Ident id -> Var id, seq
@ -293,8 +297,8 @@ and binop pre left seq =
else
left, Seq.cons x seq
| RParen | Ident "then" | Ident "else" ->
left, Seq.cons x seq
| RParen -> left, Seq.cons x seq
| Ident id when is_keyword id -> left, Seq.cons x seq
| _ -> unexpected_token x
end