Class Ritex::Lexer
In: lib/ritex/lexer.rb
Parent: Object

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 ’}’.

Methods

lex   new   push  

Constants

TOKENS = '+-\/\*|\.,;:<>=()#&\[\]^_!?~%\'{} '
OPERATOR_TOKENS = ' ,'
WORDS = %w(array arrayopts define left right rowopts cellopts colalign rowalign align padding equalcols equalrows rowlines collines frame rowspan colspan)
WORDS_SEARCH = WORDS.map { |w| [/\A\\(#{Regexp.escape w})\b/, w.upcase.intern] }

Public Class methods

s is an initial string to push on the stack, or nil.

Public Instance methods

Yield token and value pairs from the string stack.

push an additional string on to the stack.

[Validate]