ale64bit
ale64bit

Reputation: 6242

How to display location info from a parser?

How can I display the location information when a Stream.Error occurs inside a parser? For example:

let p = parser
  | [< '1; '2 ?? "1 expected at line L, column C" >] -> ()

how to get the location in the stream? Is there a way to use Stream.count without having to count the newline characters manually?

Upvotes: 0

Views: 74

Answers (1)

ivg
ivg

Reputation: 35210

You have to build the position manually (represented with Lexing.position for example). I wouldn't touch the lexer/parser itself, though, but rather write a simple function that will translate a file offset (represented with Stream.count) into the (line, column) coordinate system.

Upvotes: 0

Related Questions