Got an error while parsing grammar 'wrong argument type Class (expected Module)'

123 views
Skip to first unread message

Ivan Lo

unread,
Mar 18, 2017, 8:01:53 PM3/18/17
to Treetop Development
Hi everybody got the following error while parsing grammar. I saw that was similar questions related to this error but from my side I do the stuff right (but as a result it seems i do something wrong)
error that i got

     TypeError:
       wrong argument type Class (expected Module)
     # (eval):93:in `extend'
     # (eval):93:in `_nt_line'
     # (eval):21:in `block in _nt_document'
     # (eval):20:in `loop'
     # (eval):20:in `_nt_document'
     # /Users/gingray/.rvm/gems/ruby-2.2.2/gems/treetop-1.6.8/lib/treetop/runtime/compiled_parser.rb:18:in `parse'
     # ./app/services/parser/chord_parser.rb:8:in `parse'
     # ./spec/services/parser/chord_parser_spec.rb:3:in `block (2 levels) in <top (required)>'
     # ./spec/services/parser/chord_parser_spec.rb:5:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:36:in `block (2 levels) in <top (required)>'

my grammar

grammar TreetopChord
  rule document
    (line)*
  end

  rule line
    (text / chord / title ) [\r\n]+ <LineLiteral> / (text / chord / title ) <LineLiteral>
  end

  rule text
    [a-zA-Z0-9,.\s]+ <TextLiteral>
  end

  rule chord
    '{' [0-9#b/]+ '}' <ChordExpression>
  end

  rule title
    '[' [a-z]+ ']' <TitleLiteral>
  end
end


module TreetopChord
  class LineLiteral < Treetop::Runtime::SyntaxNode
  end

  class TextLiteral < Treetop::Runtime::SyntaxNode
  end

  class ChordExpression < Treetop::Runtime::SyntaxNode
  end

  class TitleLiteral < Treetop::Runtime::SyntaxNode
  end
end



I'll really grateful for any help. Thanks in advance.

mar...@reality.com

unread,
Mar 18, 2017, 11:22:48 PM3/18/17
to Treetop Development
Ivan --

It looks like the error is exactly what it says:

> TypeError:
> wrong argument type Class (expected Module)
> # (eval):93:in `extend'

That is, you are trying to extend with <TextLiteral>:

> [a-zA-Z0-9,.\s]+ <TextLiteral>

...which should be a module, but is actually a class:

> class TextLiteral < Treetop::Runtime::SyntaxNode


And likewise with LineLiteral, ChordExpression, and TitleLiteral.

> I'll really grateful for any help. Thanks in advance.

Hope that helps.

-- Markus

--
Send from PINE (GUI? Phooey!)

Clifford Heath

unread,
Mar 19, 2017, 1:18:20 AM3/19/17
to treet...@googlegroups.com
Apparently my reply from this morning did not get posted; thanks Marcus for replying.

You can only use a class on a rule that creates a new node, not on a node that has been returned from another rule.

Parentheses and alternation do not create new nodes, only terminals and sequences.

Clifford Heath.
> --
> You received this message because you are subscribed to the Google Groups "Treetop Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to treetop-dev...@googlegroups.com.
> To post to this group, send email to treet...@googlegroups.com.
> Visit this group at https://groups.google.com/group/treetop-dev.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages