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

Can't namespace parser using classes

Wardrop opened this issue · comments

Some of us have the request to use classes in our namespaces. Treetop doesn't currently allow you to do this, e.g.

class SomeClass
  grammer Accept

  end
end

It would be appreciated if this could be added. In the mean time I'm defining my grammars outside of any class or module, and using the following line of code to line my parsers into the namespace I desire, instead of Treetop.load:

class_eval Treetop::Compiler::GrammarCompiler.new.ruby_source_from_string(File.read('accept.treetop'))

Cheers

I'm not sure how to address this. Can you suggest a solution?

I imagine it would be a matter of amending the module_declaration or module_or_grammar rule in lib/treetop/compiler/metagrammar.treetop to handle class as well.

Fixed and pushed to github, and as gem version 1.6.8