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

Instance Method Summary collapse

Instance Attribute Details

#inputObject

Returns the value of attribute input.



10
11
12
# File 'lib/re_duxml/evaluate/lexer.rb', line 10

def input
  @input
end

#string_hashObject (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

#tokensObject

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