Sha256: ee6d37a02b708fce855f586f4f6065b348a59363071179012518195eae7f4dad

Contents?: true

Size: 650 Bytes

Versions: 2

Compression:

Stored size: 650 Bytes

Contents

class Template
  class Parser < ::Code::Parser
    Version = Gem::Version.new("0.1.8")

    def parse
      parts = []

      while !end_of_input?
        c = consume

        if c == OPENING_CURLY_BRACKET
          parts << { text: escape(buffer!) } if buffer?
          parts << { code: parse_code }
          match(CLOSING_CURLY_BRACKET)
          buffer!
        elsif c == BACKSLASH
          match(OPENING_CURLY_BRACKET)
        end
      end

      parts << { text: escape(buffer!) } if buffer?

      parts
    end

    private

    def escape(text)
      text.gsub(BACKSLASH + OPENING_CURLY_BRACKET, OPENING_CURLY_BRACKET)
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
template-ruby-parser-0.1.8 lib/template/parser.rb
code-ruby-parser-0.1.8 lib/template/parser.rb