Class: Fmt::TemplateParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/fmt/parsers/template_parser.rb

Overview

Parses a template from a string and builds an AST (Abstract Syntax Tree)

Constant Summary collapse

EMBED_PEEK =

: Regexp – detects start of an embed prefix (look ahead)

%r{(?=#{esc Sigils::EMBED_PREFIX})}ou
PIPELINE_PEEK =

: Regexp – detects start of a pipeline (look ahead)

%r{(?=[#{Sigils::FORMAT_PREFIX}][^#{Sigils::FORMAT_PREFIX}])}ou
PERCENT_LITERAL =

: Regexp – detects a percent literal

%r{[#{Sigils::FORMAT_PREFIX}]{2}}ou
WHITESPACE =

: Regexp – detects whitespace

%r{\s}ou

Constants inherited from Parser

Parser::Cache

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

esc

Constructor Details

#initialize(urtext = "") ⇒ TemplateParser

Constructor



15
16
17
# File 'lib/fmt/parsers/template_parser.rb', line 15

def initialize(urtext = "")
  @urtext = urtext.to_s.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "?")
end

Instance Attribute Details

#urtextObject (readonly)

: String – original source code



19
20
21
# File 'lib/fmt/parsers/template_parser.rb', line 19

def urtext
  @urtext
end

Instance Method Details

#parseObject

Parses the urtext (original source code)



23
24
25
# File 'lib/fmt/parsers/template_parser.rb', line 23

def parse
  cache(urtext) { super }
end