Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > TreeTop help?

Reply
Thread Tools

TreeTop help?

 
 
Day
Guest
Posts: n/a
 
      02-09-2008
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

 
Reply With Quote
 
 
 
 
Daniel Brumbaugh Keeney
Guest
Posts: n/a
 
      02-10-2008
On Feb 9, 2008 2:25 PM, Day <(E-Mail Removed)> wrote:

It looks like a simple typo to me

rule item_name
[a-zA-Z]+
end


Daniel Brumbaugh Keeney

 
Reply With Quote
 
 
 
 
Day
Guest
Posts: n/a
 
      02-10-2008
On Feb 9, 2008 8:27 PM, Daniel Brumbaugh Keeney
<(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
Clifford Heath
Guest
Posts: n/a
 
      02-10-2008
Day wrote:
> 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.
 
Reply With Quote
 
Daniel Brumbaugh Keeney
Guest
Posts: n/a
 
      02-10-2008
On Feb 10, 2008 12:20 AM, Clifford Heath <(E-Mail Removed)> wrote:

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Treetop parser (or PEG in general?) questions Phrogz Ruby 18 04-22-2008 08:05 PM
Treetop: Can the parser be put inside a module? Chiyuan Zhang Ruby 3 02-04-2008 03:16 AM
treetop equal precedence MistryMan4000@Yahoo.com Ruby 1 02-02-2008 11:28 PM
Treetop Email Parser Phrogz Ruby 13 02-01-2008 05:12 AM
when to use PEP treetop vs regexp David Rose Ruby 1 01-28-2008 04:15 PM



Advertisments