happy icon indicating copy to clipboard operation
happy copied to clipboard

inclarity in threaded lexer docs leads to confusing failure

Open xplat opened this issue 2 years ago • 3 comments

https://www.haskell.org/happy/doc/html/sec-monads.html#sec-lexers states that

is the name of the lexical analyser function, and is a token that is to be treated as the end of file.

I had created a token named 'eof' under %token and set to eof. This seemed to work, but when I finished the rest of the grammar to a compiling state, it would immediately fail at the first token. This is because eof was taken as a variable pattern that matched everything, so everything was considered an end of file. The documentation could stand to be louder that this is a Haskell pattern matching the token type, and not the name of a token.

Cc: @Cartazio

xplat avatar Mar 06 '22 15:03 xplat

@xplat https://github.com/haskell/happy/blob/master/examples/glr/expr-monad/Expr.y does this example illustrate that?

cartazio avatar Mar 06 '22 15:03 cartazio

So the second thing will be used In pattern matching position so it needs to be a constructor or pattern synonym (I’m assuming a pattern synonym is possible?)

cartazio avatar Mar 06 '22 15:03 cartazio

Yes https://github.com/haskell/happy/blob/1e2493c38f27ec6c90cb95bd82703799d9de84d2/examples/glr/expr-monad/Expr.y#L9 is how it should actually be done ...

xplat avatar Mar 06 '22 15:03 xplat