Class: EsiAttributeLanguage::Grammar
- Inherits:
-
Object
- Object
- EsiAttributeLanguage::Grammar
- Defined in:
- lib/esi_attribute_language/grammar.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(rules) ⇒ Grammar
constructor
A new instance of Grammar.
- #parse(string) ⇒ Object
Constructor Details
#initialize(rules) ⇒ Grammar
Returns a new instance of Grammar.
43 44 45 46 47 |
# File 'lib/esi_attribute_language/grammar.rb', line 43 def initialize(rules) @root = rules.first.name @rules = {} rules.each { |r| @rules[r.name] = r } end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
34 35 36 |
# File 'lib/esi_attribute_language/grammar.rb', line 34 def rules @rules end |
Class Method Details
.parse(source) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/esi_attribute_language/grammar.rb', line 36 def self.parse(source) result = GrammarParser.new.scan_str(source) result.respond_to?(:execute) ? result : DummyNode.new(result) rescue Racc::ParseError => e raise ParseError, e. end |
Instance Method Details
#parse(string) ⇒ Object
49 50 51 52 |
# File 'lib/esi_attribute_language/grammar.rb', line 49 def parse(string) index = @rules[@root].call(string, 0, @rules) index if index == string.length end |