(I've been trying this for several hours now and maybe someone can give me a quick hint (or better yet share some personal wisdom) on this.
Note that I've only been working with Lex+Yacc before very rarely and most of the documentation seems to be for C... okay enough with the excuses and this prolog. :) Here's my actual question: )
I would like to have proper error reporting in a parser that I'm writing and not fail on the first error.
What's the proper way to do this?
The best I could come up with so far was
let parse_error s =
printfn "%s %A" s (Parsing.symbol_start())
but that would only work (maybe) with --ml-compatibility.
Along the way I would also like to have reporting of positions of the typing errors that I'm detecting (like in F# itself, where the parts are highlighted in VS). What's the proper way to implement this?
What comes to my mind is specifying positions (start, end) for all my tokens:
%token <bool> BOOLEAN
becomes
type position = int*int // start, end
%token <bool*position> BOOLEAN
then the same for my AST:
| InfixOp of InfixOpType * Expr * Expr
becomes
| InfixOp of InfixOpType * Expr * Expr * position
Somehow this seems all wrong though and I feel that the parser generator should take care of such issues. Can anyone lead me to enlightment?