Class: Rattler::Grammar::Grammar
- Inherits:
-
Util::Node
- Object
- Util::Node
- Rattler::Grammar::Grammar
- Defined in:
- lib/rattler/grammar/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 => [] }
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
- #analysis ⇒ Object
-
#initialize(rules, opts = {}) ⇒ Grammar
constructor
A new instance of Grammar.
- #rule(name) ⇒ Object
- #with_rules(new_rules) ⇒ Object
Methods inherited from Util::Node
#==, #[], [], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #inspect, #method_missing, #name, #respond_to?, #same_contents?, #to_graphviz, #with_attrs, #with_attrs!, #with_children
Constructor Details
#initialize(rules, opts = {}) ⇒ Grammar
Returns a new instance of Grammar.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rattler/grammar/grammar.rb', line 41 def initialize(rules, opts={}) super @@default_opts.merge(opts) case attrs[:start_rule] when Symbol then attrs[:start_rule] = rules[start_rule] when nil then attrs[:start_rule] = rules.first end @rules = rules.with_attrs(:start_rule => start_rule.name) 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
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
54 55 56 |
# File 'lib/rattler/grammar/grammar.rb', line 54 def rules @rules end |
Class Method Details
.parsed(results, *_) ⇒ Object
28 29 30 31 |
# File 'lib/rattler/grammar/grammar.rb', line 28 def self.parsed(results, *_) #:nodoc: , rules = results self.new(rules, ) end |
Instance Method Details
#analysis ⇒ Object
60 61 62 |
# File 'lib/rattler/grammar/grammar.rb', line 60 def analysis rules.analysis end |
#rule(name) ⇒ Object
56 57 58 |
# File 'lib/rattler/grammar/grammar.rb', line 56 def rule(name) rules[name] end |
#with_rules(new_rules) ⇒ Object
64 65 66 |
# File 'lib/rattler/grammar/grammar.rb', line 64 def with_rules(new_rules) self.class.new new_rules, attrs end |