Class: Tml::RulesEngine::Parser
- Inherits:
-
Object
- Object
- Tml::RulesEngine::Parser
- Defined in:
- lib/tml/rules_engine/parser.rb
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(expression) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
- #parse_list ⇒ Object
Constructor Details
#initialize(expression) ⇒ Parser
Returns a new instance of Parser.
39 40 41 42 43 44 |
# File 'lib/tml/rules_engine/parser.rb', line 39 def initialize(expression) @expression = expression if expression =~ /^\(/ @tokens = expression.scan(/[()]|\w+|@\w+|[\+\-\!\|\=>&<\*\/%]+|".*?"|'.*?'/) end end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
37 38 39 |
# File 'lib/tml/rules_engine/parser.rb', line 37 def expression @expression end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
37 38 39 |
# File 'lib/tml/rules_engine/parser.rb', line 37 def tokens @tokens end |
Instance Method Details
#parse ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/tml/rules_engine/parser.rb', line 46 def parse return @expression unless tokens token = tokens.shift return nil if token.nil? return parse_list if (token) == '(' return token[1..-2].to_s if token =~ /^['"].*/ return token.to_i if token =~ /\d+/ token.to_s end |
#parse_list ⇒ Object
56 57 58 59 60 61 |
# File 'lib/tml/rules_engine/parser.rb', line 56 def parse_list list = [] list << parse until tokens.empty? or tokens.first == ')' tokens.shift list end |