Module: Rattler::Compiler::ModuleMethods

Includes:
Parsers
Included in:
Rattler::Compiler
Defined in:
lib/rattler/compiler.rb

Overview

Compiler module methods

Instance Method Summary collapse

Instance Method Details

#compile(mod, grammar, opts) ⇒ Module #compile(mod, parser, opts) ⇒ Module

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

Overloads:

  • #compile(mod, grammar, opts) ⇒ Module

    Returns mod.

    Parameters:

    • mod (Module)

      the target module for the match methods

    • grammar (String)

      the grammar source to compile

    Returns:

    • (Module)

      mod

  • #compile(mod, parser, opts) ⇒ Module

    Returns mod.

    Parameters:

    Returns:

    • (Module)

      mod



51
52
53
54
55
# 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(base, grammar, opts) ⇒ Class #compile(base, parser, opts) ⇒ Class

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

Overloads:

  • #compile(base, grammar, opts) ⇒ Class

    Returns a new sublcass of base with compiled match methods.

    Parameters:

    • base (Class)

      the base class for the new parser class

    • grammar (String)

      the grammar source to compile

    Returns:

    • (Class)

      a new sublcass of base with compiled match methods

  • #compile(base, parser, opts) ⇒ Class

    Returns a new sublcass of base with compiled match methods.

    Parameters:

    Returns:

    • (Class)

      a new sublcass of base with compiled match methods



33
34
35
# File 'lib/rattler/compiler.rb', line 33

def compile_parser(base, grammar_or_parser, opts={})
  compile(Class.new(base), grammar_or_parser, opts)
end