Closed spundun closed 10 years ago
Your two invocations of the parser look the same to me. Should I be seeing some difference that I've overlooked?
Treetop will always attempt to match the first rule specified in the grammar, unless you pass an alternate top rule to the parse function, using the options hash. I think this probably explains your problem.
Yes the second paragraph explains the problem. In gist I put the working code (with the root rule at the top) in the tutorial from thingsaaronmade.com that rule was not at the top. I am wondering if that is a change that happened to treetop after that tutorial blog.
Nevermind, I can see that he put the correct rule at the top here: https://github.com/aarongough/treetop-sexp-parser/blob/master/sexp_parser.treetop
I don't think this aspect of Treetop has ever changed.
You are right, the author of the tutorial just skipped mentioning it. Speaking of which, it is also not mentioned in here: http://cjheath.github.io/treetop/syntactic_recognition.html I kinda discovered it by experimenting. You may want to write it down somewhere.
BTW Thanks for the prompt responses.
Hi,
It's my first time using treetop gem and I'm following this tutorial: http://thingsaaronmade.com/blog/a-quick-intro-to-writing-a-parser-using-treetop.html
I kept getting an error
Then I moved the body rule in the sexp_parser.treetop to the top of the grammar and everything works.
Is this by design? Is there a reason for it? It seems like a bug, and at least the tutorial is inconsistent with treetop 1.5 .
You can find all the code in the gist that I have created. https://gist.github.com/spundun/92ce4524c9fae95a944e