Class: SyntaxTree::ERB::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/erb/parser.rb

Defined Under Namespace

Classes: MissingTokenError, ParseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Parser

Returns a new instance of Parser.



20
21
22
23
24
# File 'lib/syntax_tree/erb/parser.rb', line 20

def initialize(source)
  @source = source
  @tokens = make_tokens
  @found_doctype = false
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



18
19
20
# File 'lib/syntax_tree/erb/parser.rb', line 18

def source
  @source
end

#tokensObject (readonly)

Returns the value of attribute tokens.



18
19
20
# File 'lib/syntax_tree/erb/parser.rb', line 18

def tokens
  @tokens
end

Instance Method Details

#debug_tokensObject



35
36
37
38
39
# File 'lib/syntax_tree/erb/parser.rb', line 35

def debug_tokens
  @tokens.each do |key, value, index, line|
    puts("#{key} #{value.inspect} #{index} #{line}")
  end
end

#parseObject



26
27
28
29
30
31
32
33
# File 'lib/syntax_tree/erb/parser.rb', line 26

def parse
  elements = many { parse_any_tag }

  location =
    elements.first.location.to(elements.last.location) if elements.any?

  Document.new(elements: elements, location: location)
end