TypeError: wrong argument type Class (expected Module)

1,293 views
Skip to first unread message

Rick Wargo

unread,
Dec 8, 2010, 10:57:03 PM12/8/10
to Treetop Development
It appears when I use a declared module on a grouped ordered choice, I
see the error:

TypeError: wrong argument type Class (expected Module)

as in the following code:

grammar Test
...
rule true
( "true" / "on" ) <TrueLiteral>
end
end

module Test
class TrueLiteral < Treetop::Runtime::SyntaxNode
def value
return true
end
end
end

But when I move it to an anonymous module, it works!

rule true
( "true" / "on" ) {
def value
true
end
}
end

I would expect the same result. I have a very small, working example
checked into github at

https://github.com/rickwargo/tt-issue

I would appreciate any insight.

All the best,
Rick Wargo

http://www.rickwargo.com/

Clifford Heath

unread,
Dec 8, 2010, 11:18:55 PM12/8/10
to treet...@googlegroups.com
On 09/12/2010, at 2:57 PM, Rick Wargo wrote:
> It appears when I use a declared module on a grouped ordered choice, I
> see the error:
>
> TypeError: wrong argument type Class (expected Module)

You're allowing Treetop to instantiate a syntax node in the alternation
("true" / "on") and then applying a custom extension *module* to the
resulting node. Had you instead applied the *class* to each alternate
(as follows), it works with classes. Either change to modules, or:

rule true
( "true" <TrueLiteral> / "on" <TrueLiteral> )
end

Note that in your false rule, you only apply FalseLiteral to the "off"
case,
but not to the "false" case:

rule false
"false" / "off" <FalseLiteral>
end

You need to use parentheses and a module, or apply the node type to each
alternate if you must use a class:

rule false
"false" <FalseLiteral> / "off" <FalseLiteral>
end

At some time in the past, you only could create classes, and if you
search
back in the archives, you'll see all the discussion about changing
this. I
wasn't involved with it, although I might have pulled the patches into
the
trunk without insisting on documentation updates. My bad; if the doco is
still wrong, patches will be accepted :).

Clifford Heath

Rick Wargo

unread,
Dec 9, 2010, 8:54:03 AM12/9/10
to Treetop Development
Thanks, Clifford, for that insight. The solution you proposed is what
I had resolved, I just failed to type the correct code in my sample
project:) Your explanation was very helpful, though, and explained why
it worked; I'll have to go back and read those threads. Thanks for all
you do.
Reply all
Reply to author
Forward
0 new messages