Class: Rattler::Parsers::Grammar
- Inherits:
-
Util::Node
- Object
- Util::Node
- Rattler::Parsers::Grammar
- Defined in:
- lib/rattler/parsers/grammar.rb
Overview
Grammar
represents a parsed grammar
Constant Summary collapse
- DEFAULT_PARSER_BASE =
The name of the default parser base class
'Rattler::Runtime::PackratParser'
- @@default_opts =
{ :grammar_name => nil, :parser_name => nil, :base_name => DEFAULT_PARSER_BASE, :requires => [], :includes => [] }
Class Method Summary collapse
Instance Method Summary collapse
-
#analysis ⇒ Analysis
A static analysis of the grammar rules.
-
#initialize(rules, opts = {}) ⇒ Grammar
constructor
A new instance of Grammar.
-
#rule(name) ⇒ Rule
The parse rule referenced by
name
. -
#with_rules(new_rules) ⇒ Grammar
A new grammar with the parse rules replaced by
new_rules
.
Methods inherited from Util::Node
#==, #[], [], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #inspect, #method_missing, #name, #pretty_print, #pretty_print_cycle, #respond_to?, #same_contents?, #to_graphviz, #with_attrs, #with_attrs!, #with_children
Constructor Details
#initialize(rules, opts = {}) ⇒ Grammar
Returns a new instance of Grammar.
33 34 35 36 37 38 39 40 41 |
# File 'lib/rattler/parsers/grammar.rb', line 33 def initialize(rules, opts={}) start_rule = opts[:start_rule] || rules.start_rule || (rules.first && rules.first.name) super rules.with_attrs(:start_rule => start_rule), @@default_opts.merge(:start_rule => start_rule).merge(opts) attrs[:name] ||= grammar_name || parser_name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rattler::Util::Node
Class Method Details
.parsed(results, *_) ⇒ Object
20 21 22 23 |
# File 'lib/rattler/parsers/grammar.rb', line 20 def self.parsed(results, *_) #:nodoc: , rules = results self.new(rules, ) end |
Instance Method Details
#analysis ⇒ Analysis
Returns a static analysis of the grammar rules.
52 53 54 |
# File 'lib/rattler/parsers/grammar.rb', line 52 def analysis rules.analysis end |
#rule(name) ⇒ Rule
Returns the parse rule referenced by name
.
47 48 49 |
# File 'lib/rattler/parsers/grammar.rb', line 47 def rule(name) rules[name] end |
#with_rules(new_rules) ⇒ Grammar
Returns a new grammar with the parse rules replaced by new_rules
.
59 60 61 |
# File 'lib/rattler/parsers/grammar.rb', line 59 def with_rules(new_rules) self.class.new new_rules, attrs end |