reasonml / reason

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
http://reasonml.github.io
MIT License
10.15k stars 428 forks source link

Use lookahead token to decide which error message to use #588

Open yunxing opened 8 years ago

yunxing commented 8 years ago

Today when we use menhir's compile_errors option to generate error messages table in ocaml, the only input is the error state. It generates something like:

let message = 
fun s-> 
  match s with
  | 0 -> 
    "syntax error blah blah blah"
  ...

But sometimes for the same state, we want to have different error messages for different lookahead token. I'm thinking maybe we can use lookahead token as another input to error messages. So the generated ocaml error table file would look like this:

let message = 
fun s token -> 
  match (s, token) with
    | (0, MINUSGREATER) ->
      "Doesn't expect '->' here! Maybe you mean '=>' ?" 
    | (0, DIV) -> 
      ...
    | (0, _) ->
     ...
yunxing commented 8 years ago

Touch based with Menhir people. For now I think the we should just develop our own interpretation tool to generate an augmented ".ml" to achieve this.