class Glaemscribe::API::Eval::Lexer
Constants
- EXP_TOKENS
- TOKEN_END
Attributes
exp[R]
token_chain[R]
Public Class Methods
new(exp)
click to toggle source
# File lib/api/eval.rb, line 81 def initialize(exp) @exp = exp @token_chain = [] @retain_last = false end
Public Instance Methods
advance()
click to toggle source
# File lib/api/eval.rb, line 91 def advance @exp.strip! if @retain_last @retain_last = false return @token_chain.last end if(@exp == TOKEN_END.expression) t = TOKEN_END.clone("") @token_chain << t return t end EXP_TOKENS.each{ |token| if(token.regexp?) if(token.expression =~ @exp) @exp = $' # Eat the token t = token.clone($~.to_s) @token_chain << t return t end else if(@exp.start_with?(token.expression)) @exp = @exp[token.expression.length..-1] t = token.clone(token.expression) @token_chain << t return t end end } raise UnknownToken end
uneat()
click to toggle source
# File lib/api/eval.rb, line 87 def uneat @retain_last = true end