Skip to content

Commit

Permalink
attempt to fix #102
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremie Dimino committed Feb 9, 2016
1 parent f6ba459 commit ea08595
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion camlp4/Camlp4Parsers/Camlp4OCamlParser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
| _ -> 1 ])
;

(* Yet another horrible hack, this one to improve error locations when parsing
[{ blah }] in expressions *)
value test_label_longident_equal =
Gram.Entry.of_parser "label_longident_equal" (fun strm ->
let rec loop = fun
[ [] -> ()
| [ (UIDENT _, _) :: [ (KEYWORD ".", _) :: rest ] ] -> loop rest
| [ (LIDENT _, _) :: [ (KEYWORD "=", _) :: _ ] ] -> ()
| _ -> raise Stream.Failure
]
in
loop (Stream.npeek 100 strm))
;

value lident_colon =
Gram.Entry.of_parser "lident_colon"
(fun strm ->
Expand Down Expand Up @@ -315,7 +329,7 @@ module Make (Syntax : Sig.Camlp4Syntax) = struct
expr: LEVEL "simple" (* LEFTA *)
[ [ "false" -> <:expr< False >>
| "true" -> <:expr< True >>
| "{"; lel = TRY [lel = label_expr_list; "}" -> lel] ->
| "{"; test_label_longident_equal; lel = label_expr_list; "}" ->
<:expr< { $lel$ } >>
| "{"; e = TRY [e = expr LEVEL "."; "with" -> e]; lel = label_expr_list; "}" ->
<:expr< { ($e$) with $lel$ } >>
Expand Down

0 comments on commit ea08595

Please sign in to comment.