On Mon, May 2, 2011 at 3:20 PM, Thiel Chang <[email protected]> wrote:
> Hi guys,
>
> Due to a problem with code generation I changed my grammar rules.
>
> After running this code: parser.parse_with_debug( '1 + 2' )
>
> I got this result:
>
> {:stm=>{:ident=>"2"@4}}
> Duplicate subtrees while merging result of
> stm:EXP
> only the values of the latter will be kept. (keys: [:ident])
>
> Can anyone tell me what's wrong?
>
Hard to say without seeing the grammar, but I'm guessing you have a rule
that has duplicate ".as(:stm)" expressions?
And I also have another question: when do you have to use "space" in a
> grammar rule?
>
When you want to consume whitespace characters. generally these are
optional, so you use the "space?" idiom.
Thus
rule(:foo) { str('1') >> space? str('+') >> space? >> str('2) }
matches your above example, and also '1+2', '1 + 2' etc.
cheers
ant