librelist archives

« back to archive

[ruby.parslet] Left recursion

[ruby.parslet] Left recursion

From:
Chris Corbyn
Date:
2011-11-04 @ 15:28
In reply to:

http://www.mail-archive.com/ruby.parslet@librelist.com/msg00001.html

I just got the following working fine:

Taking:

{:multiply=>{:left=>{:int=>"2"@0}, :right=>{:sum=>{:left=>{:int=>"2"@4}, 
:right=>{:int=>"1"@8}}}}}

And re-associating it as:

{:sum=>{:left=>{:multiply=>{:left=>{:int=>"2"@0}, :right=>{:int=>"2"@4}}},
:right=>{:int=>"1"@8}}}

I'd like to make this generic, such that you can basically flag rules as 
left or right associative, inside the parser (left(:rule) vs. 
right(:rule)) and have #parse pass its result through a Transformation 
that is based on which rules have been marked as having different 
associativity.

I'll post back if I come up with anything.