Class: SyntaxTree::ERB::Parser

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

Defined Under Namespace

Classes: MissingTokenError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Parser

Returns a new instance of Parser.



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

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

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



16
17
18
# File 'lib/syntax_tree/erb/parser.rb', line 16

def source
  @source
end

#tokensObject (readonly)

Returns the value of attribute tokens.



16
17
18
# File 'lib/syntax_tree/erb/parser.rb', line 16

def tokens
  @tokens
end

Instance Method Details

#debug_tokensObject



33
34
35
36
37
# File 'lib/syntax_tree/erb/parser.rb', line 33

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

#parseObject



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

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