Module: Lexer
- Included in:
- ReDuxml::Parser
- Defined in:
- lib/re_duxml/evaluate/lexer.rb
Constant Summary collapse
- TOKEN_TYPES =
{ string: /STRING[\d]+/, function: /log|exp|sqrt/, bool: /true|false/, param: Regexp.identifier, num: /\d+/, grouping: /[\(\):,]/ }
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#string_hash ⇒ Object
readonly
Returns the value of attribute string_hash.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Instance Method Summary collapse
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
10 11 12 |
# File 'lib/re_duxml/evaluate/lexer.rb', line 10 def input @input end |
#string_hash ⇒ Object (readonly)
Returns the value of attribute string_hash.
9 10 11 |
# File 'lib/re_duxml/evaluate/lexer.rb', line 9 def string_hash @string_hash end |
#tokens ⇒ Object
Returns the value of attribute tokens.
10 11 12 |
# File 'lib/re_duxml/evaluate/lexer.rb', line 10 def tokens @tokens end |
Instance Method Details
#lex(expr) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/re_duxml/evaluate/lexer.rb', line 23 def lex(expr) @input = tag_strings(expr).split(/\b/).reverse.collect do |s| s.strip end @tokens = [] while (sub_str = input.pop) do type = get_type sub_str value = formatted_value(sub_str, type) tokens << (@last_token = Struct::Token.new(type, value)) unless value.nil? end @last_token = nil tokens end |