Class: Deadfire::FrontEnd::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens, error_reporter) ⇒ Parser

Returns a new instance of Parser.



8
9
10
11
12
13
# File 'lib/deadfire/front_end/parser.rb', line 8

def initialize(tokens, error_reporter)
  @error_reporter = error_reporter
  @tokens = tokens
  @current = 0
  @stylesheet = StylesheetNode.new
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



6
7
8
# File 'lib/deadfire/front_end/parser.rb', line 6

def current
  @current
end

#error_reporterObject (readonly)

Returns the value of attribute error_reporter.



6
7
8
# File 'lib/deadfire/front_end/parser.rb', line 6

def error_reporter
  @error_reporter
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/deadfire/front_end/parser.rb', line 6

def options
  @options
end

#tokensObject (readonly)

Returns the value of attribute tokens.



6
7
8
# File 'lib/deadfire/front_end/parser.rb', line 6

def tokens
  @tokens
end

Instance Method Details

#parseObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/deadfire/front_end/parser.rb', line 15

def parse
  while !is_at_end?
    if check(:comment)
      comment = add_comment
      @stylesheet << comment unless Deadfire.configuration.compressed
    elsif check(:newline)
      newline = add_newline
      @stylesheet << newline unless Deadfire.configuration.compressed
    elsif matches_at_rule?
      @stylesheet << at_rule_declaration
    else
      @stylesheet << ruleset_declaration
    end
  end
  @stylesheet
end