class SimpleTemplates::Parser::Text
Recognizes a set of input tokens as a Text
Constants
- STARTING_TOKENS
The starting tokens that the input can have @return [Set<Symbol>]
- UNESCAPE_METHODS
A hash containing the method for a quoted placeholder start or end @return [Hash{ Symbol => Symbol }]
Public Instance Methods
parse()
click to toggle source
It parses the stream, if it starts with a text node then it parses out the text until it is not applicable for the input anymore. @return <Array <Array>,
<Array>, <Array[SimpleTemplates::Lexer::Token]>> an +Array+ with a list of AST::Text as first element, always an Empty list of Errors and the remaining unparsed tokens.
# File lib/simple_templates/parser/text.rb, line 29 def parse txt_node = nil toks = tokens.dup while self.class.applicable?(toks) next_txt_token = toks.shift this_txt_node = AST::Text.new(unescape(next_txt_token), next_txt_token.pos, true) txt_node = txt_node.nil? ? this_txt_node : txt_node + this_txt_node end [[txt_node], [], toks || []] end
Private Instance Methods
unescape(token)
click to toggle source
# File lib/simple_templates/parser/text.rb, line 47 def unescape(token) unescapes[UNESCAPE_METHODS[token.type]] || token.content end