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