Class: Curly::Parser

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

Defined Under Namespace

Classes: Block, Comment, Component, Root, Text

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens) ⇒ Parser

Returns a new instance of Parser.



104
105
106
107
108
# File 'lib/curly/parser.rb', line 104

def initialize(tokens)
  @tokens = tokens
  @root = Root.new
  @stack = [@root]
end

Class Method Details

.parse(tokens) ⇒ Object



100
101
102
# File 'lib/curly/parser.rb', line 100

def self.parse(tokens)
  new(tokens).parse
end

Instance Method Details

#parseObject



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/curly/parser.rb', line 110

def parse
  @tokens.each do |token, *args|
    send("parse_#{token}", *args)
  end

  unless @stack.size == 1
    raise Curly::IncompleteBlockError,
      "block `#{@stack.last}` is not closed"
  end

  @root.nodes
end