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