There is some good discussion around LR in Parslet's mailing list history.

http://librelist.com/browser//ruby.parslet/2011/11/4/ruby-parslet-left-recursion/

is the approach I would favor..

so the key is viewing the parser as only part of your solution.. that
changes your code to a tree you can manipulate.

Once it's a tree you can apply transformations to make it represent the
structure you are looking for.

You can imagine parsing your code to  (forgive my notation)
  dot ( 'x', dot ( eval( 'y', [] ) , 'z' ) )
then transforming that to
  dot ( eval ( dot ( 'x' , 'y' ) , [] ), 'z' )

Cheers
Nigel
---
"Man, I'm going to have so many chickens when this lot hatch!"


On Thu, Mar 28, 2013 at 9:30 AM, Thomas Ingram <[email protected]>wrote:

> I am working on a new language which supports method/property chaining,
> very much like JavaScript. For instance:
>
>     x.y().z
>
> `y` is a property of `x`, which happens to be a function. This makes `y` a
> method of `x`. I call the method with parens. Then I am accessing a
> property on the result of that method, `z`. I'm trying to produce a parse
> tree that looks like:
>
>     {
>       :property => {
>         :object => {
>           :regular_invocation => {
>             :callable => {
>               :property => {
>                 :object => { :reference => 'x' },
>                 :property_name => { :reference => 'y' }
>               }
>             },
>             :arguments => []
>           }
>         },
>         :property_name => { :reference => 'z' }
>       }
>     }
>
> With all that out of the way, I have some questions. :)
>
> 1) Is my target parse tree reasonable? I was talking showing this to
> somebody the other day, and they vaguely suggested that flat is better than
> nested. I think this tree is entirely reasonable, but I wanted to get some
> feedback.
>
> 2) Assuming the parse tree is reasonable, how should I go about parsing? I
> have my current best attempt on GitHub (see below), and all I can produce
> is left-recursion. My understanding is that what I have would be fine with
> support for left-recursion, and there exists a non-left-recursive way to
> parse the source, but I'm finding it difficult to write.
>
> Please help!
>
> The relevant code and associated tests are at:
>
> https://github.com/rip-lang/rip/blob/take-two/lib/rip/compiler/parser.rb#L69
>
> https://github.com/rip-lang/rip/blob/take-two/spec/rip/compiler/parser_spec.rb#L535
>
> --
>  Thomas Ingram
>

Reply via email to