nathansobo/treetop — Issue #26: Parser trying to extend with a SyntaxNode subclass weirdness.
Author: jamesotron
Created: 2012-02-29 01:09:54+00:00
State: open

Hi.

I'm throwing together a toy language at https://github.com/jamesotron/CrimsonScript - so far it has only a simple description of nil and integer literals:

rule literal
integer_literal / nil_literal
end

rule integer_literal
hex_integer_literal / octal_integer_literal / binary_integer_literal / decimal_integer_literal / zero_integer_literal
end

rule nil_literal
"nil"
end

rule zero_integer_literal
'-'? '0'
end

rule decimal_integer_literal
'-'? [1-9] [0-9]*
end

rule binary_integer_literal
'-'? '0b' [0-1]+
end

rule octal_integer_literal
'-'? '0o' [0-7]+
end

rule hex_integer_literal
'-'? '0x' [0-9a-fA-F]+
end

However when I try and parse `0` I get:

1.9.3-p0 :001 > Crimson::Parser.parse('0')
TypeError: wrong argument type Class (expected Module)
from (eval):72:in `extend'
from (eval):72:in `_nt_integer_literal'
from (eval):24:in `_nt_literal'
from /Users/jnh/.rvm/gems/ruby-1.9.3-p0@crimsonscript/gems/treetop-1.4.10/lib/treetop/runtime/compiled_parser.rb:18:in `parse'
from /Users/jnh/Dev/Toys/CrimsonScript/lib/crimson/parser.rb:11:in `parse'
from (irb):1
from /Users/jnh/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `

'

I'm not sure what I'm doing wrong, but when I compile the grammar to ruby I can see that it's calling #extend on the result of _nt_zero_integer_literal. I'm not sure why that's happening. Is this a bug?