Class: EsiAttributeLanguage::SimpleGrammar
- Inherits:
-
Object
- Object
- EsiAttributeLanguage::SimpleGrammar
- 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) ⇒ SimpleGrammar
constructor
A new instance of SimpleGrammar.
- #parse(string) ⇒ Object
Constructor Details
#initialize(rules) ⇒ SimpleGrammar
Returns a new instance of SimpleGrammar.
20 21 22 23 24 |
# File 'lib/esi_attribute_language/grammar.rb', line 20 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.
11 12 13 |
# File 'lib/esi_attribute_language/grammar.rb', line 11 def rules @rules end |
Class Method Details
.parse(source) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/esi_attribute_language/grammar.rb', line 13 def self.parse(source) result = SimpleGrammarParser.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
26 27 28 29 |
# File 'lib/esi_attribute_language/grammar.rb', line 26 def parse(string) index = @rules[@root].call(string, 0, @rules) index if index == string.length end |