Fix apply bug with keyword
This commit is contained in:
parent
edeff67edb
commit
cd3487dd81
1 changed files with 8 additions and 4 deletions
12
parser.ml
12
parser.ml
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue