TreeTop help?

D

Day

So I'm building a parser, and I thought I'd give TreeTop a go. I
recently got Practical Ruby Projects from Apress and worked through
the last chapter, so I feel like I have somewhat of an understanding
of what's going on, but I'm having a weird issue. It is apparent to me
that the order you define rules in TreeTop matters.

The stuff I'll be parsing (somewhat simplified) looks like this:

Item, name(value), name(value), name(value)...etc.

Here's my grammar and test script: http://pastie.caboo.se/149766

This fails. If I comment out the item and item_name rules and then
change the string to be parsed to just 'bar(1), baz(14)' it works. i
can't figure out what the order of the rules might imply (if I reorder
them, it breaks again). Any help or pointing at some documentation
more in-depth than that found on the TreeTop site would be much
appreciated. Thanks.


Ben
 
D

Daniel Brumbaugh Keeney

It looks like a simple typo to me

rule item_name
[a-zA-Z]+
end


Daniel Brumbaugh Keeney
 
D

Day

It looks like a simple typo to me

rule item_name
[a-zA-Z]+
end


Daniel Brumbaugh Keeney

Wow. That's how awesome I am. At life. Heh. Thanks man. Good eye.

The ordering of things DOES matter, right? Or am I hallucinating?


Ben
 
C

Clifford Heath

Day said:
The ordering of things DOES matter, right? Or am I hallucinating?

The ordering of rules in a grammar doesn't matter at all.
The compiler processes each rule into a method (and some
modules that extend objects created in that method), and
it does that without considering the existence of any other
rule. Just as order of def's in a class doesn't matter, the
order of rules in a grammar doesn't matter.

On the other hand, the order of alternatives within a rule
does matter. Once one alternative succeeds, even if it leaves
the input at a point where the calling rule cannot succeed,
no other alternative will ever be tried. You may need to use
lookahead to prevent this happening.

Finally, the success of one item in a sequence is final. If
the path chosen prevents following items in that sequence to
fail, the previous item will never be revisited, and the whole
sequence will fail. Again, you might need to use lookahead
to prevent this - especially to place limits on repetition.

This is looking like becoming an FAQ, and I hope I'm getting
better at stating it succinctly. I also hope Google starts
finding it, so I don't have to :).

Clifford Heath.
 
D

Daniel Brumbaugh Keeney

This is looking like becoming an FAQ, and I hope I'm getting
better at stating it succinctly. I also hope Google starts
finding it, so I don't have to :).

Clifford Heath.

There's been quite a bit of talk about Treetop on this list lately,
seeing as it has no mailing list, feel free to join
irc://irc.freenode.net/#treetop


Daniel Brumbaugh Keeney
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top