How to push a synthetic token (which is not related to any symbol) in Menhir Incremental?

132 views Asked by At

I am parsing the Elm lang-like syntax. And look at the pattern matching (inside pattern matching)

case a of
 1 -> case b of
  "hello" -> 'h'
  _ -> 'w'
 _ -> 'e'

We see there is a significant identification case. I catch conflicts because I can't express the significant identification inside BNF. Because it isn't a context-free case. But I am creating the "synthetic token" to satisfy Menhir, and I want to push the token not inside lexer or parser files but inside the OCaml code and implicitly (for .mly and mll) push this token. Without the terminal token, I catch conflicts.

And this synthetic token is DEDENT:

| CASE expr=exprs_top OF NEWLINE
   items=separated_nonempty_list(NEWLINE, expr_case) DEDENT
        { Case_of({ expr; items })}

I need an example of implementing the pushing of the synthetic token inside the on_fail function.

and loop lexbuf result =
  let supplier = I.lexer_lexbuf_to_supplier get_token lexbuf in
  I.loop_handle_undo succeed on_fail supplier result

And also,is it even a good idea to do this (to have a synthetic token that isn't related to a symbol)?

0

There are 0 answers