Thanks a lot, Cliff.
I will try to search some clue to solve it myself.
<clifford.he
...@gmail.com> wrote:
> Sorry Moon, but I'm going on vacation for a week - back on the 4th.
> I hope someone else can help you.
> You need to iterate through the elements - there are examples on the
> website.
> Clifford Heath.
> On 26/12/2010, at 2:09 AM, Moon Ho Hwang wrote:
>> Thanks a lot, Cliff!
>> Let me focus the left-recursive rule of PEG rather than handling white
>> spaces in this mail.
>> (I will try out your recommendation of white space handling later).
>> I changed the "edge" rule as below.
>> rule edge
>> word ('=>' edge)*
>> {
>> def MakeG(v)
>> elements[0].MakeG(v)
>> elements[2].MakeG(v) if elements[2] != nil
>> end
>> }
>> end
>> I expected I can get 8 vertices but I can only 4 vertices when I run
>> test_graph.rb.
>> Let me attached tt file and rb so you can take a look at them.
>> Thanks.
>> Moon
>> On Fri, Dec 24, 2010 at 6:03 PM, Clifford Heath
>> <clifford.he...@gmail.com> wrote:
>>> On 25/12/2010, at 8:59 AM, Moon Ho Hwang wrote:
>>>> I have a grammar file named simple_graph.tt
>>>> rule edge
>>>> edge "=>" word
>>>> Above one has no stack level too deep error but I could not parse the
>>>> following form of edges.
>>> Your grammar is left-recursive. PEGs cannot handle left recursion
>>> (at least, without some tweaks that Treetop doesn't have). You're
>>> saying to Treetop "to get an edge, first get an edge".
>>> In this case, it looks easy to refactor like this:
>>> rule edge
>>> word "=>" edge
>>> / word
>>> end
>>> or
>>> rule edge
>>> word ("=>" edge)*
>>> end
>>> I don't like the way you're embedding all your white-space
>>> handling into "word". it might work for now, but it's not a good
>>> pattern. I try to arrange for each invoked rule to skip trailing
>>> whitespace, and then insert any additional skipping where
>>> needed.
>>> Clifford Heath.
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Treetop Development" group.
>>> To post to this group, send email to treetop-dev@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> treetop-dev+unsubscribe@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/treetop-dev?hl=en.
>> --
>> Moon Ho Hwang
>> http://moonho.hwang.googlepages.com/
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Treetop Development" group.
>> To post to this group, send email to treetop-dev@googlegroups.com.
>> To unsubscribe from this group, send email to
>> treetop-dev+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/treetop-dev?hl=en.
>> <test_simple_graph.rb><comment.tt><simple_graph.tt>
> --
> You received this message because you are subscribed to the Google Groups
> "Treetop Development" group.
> To post to this group, send email to treetop-dev@googlegroups.com.
> To unsubscribe from this group, send email to
> treetop-dev+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/treetop-dev?hl=en.