Hello everybody !
I'd like your advice concerning a recurring problem concerning my usage of Treetop,that I cannot fix...from time to time. I'm probably missing something.
I suspect many of you have the right idiom or habits to solve that.
I generally use Treetop like the following :
1) I define my grammar
2) I modify it to emit custom parse tree objets (that inherit Treetop::Runtime::SyntaxNode). These classes are defined in a "parsetree.rb" file.
3) these custom objects have a to_ast method to turn them recursively into "pure" Treetop-independent classes (that constitute my final AST). I have two separate modules (ParseTree & AST) for that.
However, I hit a classical error message, that I cannot generally fix :
parsetree.rb:380:in `to_ast': undefined method `to_ast' for SyntaxNode offset=149, "":Treetop::Runtime::SyntaxNode (NoMethodError)
In this example, on this line 380 I have the following code ( it is about a finite state machine)
# in parsetree.rb
class Next < Tree
def to_ast
ret=Ldl::Ast::Next.new
ret.name=ns.to_ast
if cond
ret.condition=cond.c.to_ast
end
ret.actions=acts.to_ast # <==== line 380
ret
end
end
class NextActions < Tree
def to_ast
eqs.elements.collect{|eq| eq.to_ast}
end
end
And my piece of grammar concerned by the error is :
rule nextstate
space? 'next' space ns:identifier space? cond:('?' space? c:expression)? space
acts:next_actions? <Ldl::ParseTree::Next>
end
rule next_actions
space? eqs:equation+ space 'end' space <Ldl::ParseTree::NextActions>
end
I am puzzled here because it seems to me that Treetop emits a sort of "space" in place of one of my custom node...
Any idea ?
Thanks for your time
JCLL