cjheath / treetop

A Ruby-based parsing DSL based on parsing expression grammars.

Home Page:https://cjheath.github.io/treetop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generated parser extends same module twice

mojavelinux opened this issue · comments

If a rule matches zero or more occurrences of a pattern, and that rule has a block, then the module that represents that block is extended twice in the generated parser.

Here's a simple grammar that demonstrates the issue:

grammar Names
  rule names
    (name spaces?)* {
      def content
        elements.size
      end
    }
  end

  rule name
    [a-z_]+
  end

  rule spaces
    ' '+
  end
end

Run tt names.treetop. In the generated file, you'll find:

r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
r0.extend(Names1)
r0.extend(Names1)

where Names1 is:

module Names1
  def content
    elements.size
  end
end

The Names1 module should only be extended once. This is a regression (from what I can tell) from the 1.5.x series.

Not sure what happened there. Gem version 1.6.2 did not match any committed version, I must have released from an unclean work area. My bad. Rolled to 1.6.3.