Hi all,
I have been making progress understanding how to use parboiled2 to write a very simple parser for reading C/C++ files into a very simple custom AST.
My problem is in understanding how separatedBy / using a separator and EOI works.
The simplified code is in
http://pastebin.com/nHTZRF8aExample string:
#ifdef A
test
#endif
This is what I get:
Unexpected end of input, expected '\n' or '\r' (line 3, column 7): #endif
I do understand that it expects a sep, as I wrote in the grammar, but if I change the sep rule to be :
def sep = rule{ch(EOI) | "\n" | "\r\n" }
the program does not terminate.
Now, I can use instead
rule{ zeroOrMore(line).separatedBy(sep)
which will work fine, except that it adds an extra empty line in my result, e.g. Vector(YourChoice(defined(A),Vector(Textline(test),
Textline()),None))
I simplified my example, and I would prefer to use this separatedBy but how do I get it to not add an extra line? I do not understand where does that come from...
What am I missing, what am I doing wrong? (Quite a beginner in parsing, though I am trying to learn and understand better).
Thanks in advance for your time!