Class: Rattler::BackEnd::Compiler
- Inherits:
-
Object
- Object
- Rattler::BackEnd::Compiler
- Defined in:
- lib/rattler/back_end/compiler.rb
Overview
The Compiler
compiles parser models into parser classes and methods.
Class Method Summary collapse
-
.compile(mod, rules_or_grammar) ⇒ Object
Compile rules or grammar source into match methods in the module
mod
. -
.compile_parser(base, rules_or_grammar) ⇒ Object
Compile rules or grammar source into a new parser subclass of
base
. -
.compile_rules(mod, rules) ⇒ Object
Compile
rules
into match methods in the modulemod
.
Instance Method Summary collapse
-
#compile(_) ⇒ Object
Compile the rules or grammar source into match methods in the module.
-
#compile_grammar(source) ⇒ Module
Compile
grammar
into match methods in the module. -
#compile_rules(rules) ⇒ Object
Compile
rules
into match methods in the module. -
#initialize(mod) ⇒ Compiler
constructor
Create a new compiler that compiles rules into match methods in the given module.
Methods included from Parsers
Methods included from Grammar
Constructor Details
#initialize(mod) ⇒ Compiler
Create a new compiler that compiles rules into match methods in the given module.
62 63 64 |
# File 'lib/rattler/back_end/compiler.rb', line 62 def initialize(mod) @mod = mod end |
Class Method Details
.compile(mod, rules_or_grammar) ⇒ Object
Compile rules or grammar source into match methods in the module mod
.
46 47 48 |
# File 'lib/rattler/back_end/compiler.rb', line 46 def self.compile(mod, rules_or_grammar) self.new(mod).compile(rules_or_grammar) end |
.compile_parser(base, rules) ⇒ Class .compile_parser(base, rule) ⇒ Class .compile_parser(base, grammar) ⇒ Class
Compile rules or grammar source into a new parser subclass of base
.
40 41 42 43 |
# File 'lib/rattler/back_end/compiler.rb', line 40 def self.compile_parser(base, rules_or_grammar) parser_class = Class.new(base) compile(parser_class, rules_or_grammar) end |
.compile_rules(mod, rules) ⇒ Object
Compile rules
into match methods in the module mod
.
51 52 53 |
# File 'lib/rattler/back_end/compiler.rb', line 51 def self.compile_rules(mod, rules) self.new(mod).compile_rules(rules) end |
Instance Method Details
#compile(rules) ⇒ Module #compile(rule) ⇒ Module #compile(grammar) ⇒ Module
Compile the rules or grammar source into match methods in the module.
83 84 85 86 87 88 |
# File 'lib/rattler/back_end/compiler.rb', line 83 def compile(_) case _ when Grammar, RuleSet, Rule then compile_rules(_) else compile_grammar(_.to_s) end end |
#compile_grammar(source) ⇒ Module
Compile grammar
into match methods in the module.
56 57 58 |
# File 'lib/rattler/back_end/compiler.rb', line 56 def compile_grammar(mod, source) self.new(mod).compiler_grammar(source) end |
#compile_rules(rules) ⇒ Module #compile_rules(rule) ⇒ Module
Compile rules
into match methods in the module.
102 103 104 |
# File 'lib/rattler/back_end/compiler.rb', line 102 def compile_rules(rules) compile_model(rules) end |