0

I'm trying to implement grammar for jade like syntax with indent/dedent:

div
  p id="text"

But i got have problems with EOF:

Error: Parse error on line 4:
div  p id="text"
----------------^
Expecting 'DEDENT', 'IDENTIFIER', got 'EOF'

Grammar: https://gist.github.com/antonmedv/7615a5322dec1736db60a87897f17f01

What am i doing wrong?

Anton Medvedev
  • 3,393
  • 3
  • 28
  • 40
  • On SO, we ask that questions be self-contained (not pointing to code on other services) and that code samples be complete and minimal. I answered your question anyway, but it would be helpful to future readers if you edited it to include a [mcve] instead of the github link. Thanks. – rici May 19 '17 at 15:18

1 Answers1

0

You generate DEDENT tokens only when you see the first non-whitespace character in a line. At EOF, there is no such character, so the final DEDENTs are never generated. The DEDENTs are required by your grammar, so you get a syntax error at EOF.

Your EOF rule must flush the indent stack before reporting the end of file.

rici
  • 234,347
  • 28
  • 237
  • 341
  • I fixed missing dedents but still get same error, can you help me to solve it? – Anton Medvedev May 19 '17 at 19:44
  • @Anton: That will be difficult without seeing your code :-) Did you read my comment to your question? Anyway, I think your first debugging exercise would be to override the lexer in order to print the tokens it produces and verify that they (a) are as you expect, and (b) satisfy the grammar. (In fact, you should be able to just repeatedly call the lexer to print out a token stream; you don't need to implement a full debugging interface :) ) – rici May 19 '17 at 23:33
  • Thanks. Will try to print each token, or implement lexer myself. – Anton Medvedev May 20 '17 at 04:34