The lexer splits an input stream into tokens. These are handed to the parser. Ritex::Parser takes care of setting up and configuring the lexer.
In order to support macros, the lexer maintains a stack of strings. Pushing a string onto the stack will cause lex to yield tokens from that string, until it reaches the end, at which point it will discard the string and resume yielding tokens from the previous string.
To handle macros, the lexer is stateful. Normally it ignores all spacing. After hitting an ENV token it will start returning SPACE tokens for each space until it hits a ‘}’.
s is an initial string to push on the stack, or nil.
# File lib/ritex/lexer.rb, line 34 def initialize parser, s = nil @parser = parser @s = [] push s unless s.nil? end
Yield token and value pairs from the string stack.
# File lib/ritex/lexer.rb, line 44 def lex #:yields: token, value ## actually this function does nothing right now except call ## lex_inner. if we switch to more stateful tokenization this ## might do something more. lex_inner do |sym, val| yield [sym, val] end end
push an additional string on to the stack.
# File lib/ritex/lexer.rb, line 41 def push s; @s.unshift [s, 0]; end