module Rattler::Compiler::ModuleMethods

Compiler module methods

Public Instance Methods

compile(mod, grammar_or_parser, opts={}) click to toggle source

Compile grammar source or a parser model into match methods in a module.

@overload compile(mod, grammar, opts)

@param [Module] mod the target module for the match methods
@param [String] grammar the grammar source to compile
@return [Module] +mod+

@overload compile(mod, parser, opts)

@param [Module] mod the target module for the match methods
@param [Rattler::Parsers::Grammar,Rattler::Parsers::RuleSet,Rattler::Parsers::Rule]
  parser the parser model to compile
@return [Module] +mod+
# File lib/rattler/compiler.rb, line 51
def compile(mod, grammar_or_parser, opts={})
  model = parser_model(grammar_or_parser)
  mod.module_eval ParserGenerator.code_for(model, opts)
  mod
end
compile_parser(base, grammar_or_parser, opts={}) click to toggle source

Compile grammar source or a parser model into a new parser subclass of base.

@overload compile(base, grammar, opts)

@param [Class] base the base class for the new parser class
@param [String] grammar the grammar source to compile
@return [Class] a new sublcass of +base+ with compiled match methods

@overload compile(base, parser, opts)

@param [Class] base the base class for the new parser class
@param [Rattler::Parsers::Grammar,Rattler::Parsers::RuleSet,Rattler::Parsers::Rule]
  parser the parser model to compile
@return [Class] a new sublcass of +base+ with compiled match methods
# File lib/rattler/compiler.rb, line 33
def compile_parser(base, grammar_or_parser, opts={})
  compile(Class.new(base), grammar_or_parser, opts)
end

Private Instance Methods

parser_model(arg) click to toggle source
# File lib/rattler/compiler.rb, line 59
def parser_model(arg)
  case arg
  when Grammar, RuleSet, Rule then arg
  else GrammarParser.parse!(arg.to_str)
  end
end