Module: Caps::Parser::Entrypoints

Included in:
Caps::Parser
Defined in:
lib/caps/parser/entrypoints.rb

Instance Method Summary collapse

Instance Method Details

#parse_comma_separated_component_valuesObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/caps/parser/entrypoints.rb', line 96

def parse_comma_separated_component_values
  cvls = []

  loop do
    cv = consume_component_value
    if cv.comma?
      next
    elsif cv.eof?
      break
    end

    cvls << cv
  end

  cvls
end

#parse_component_valueObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/caps/parser/entrypoints.rb', line 74

def parse_component_value
  consume_whitespace
  syntax_error! "Unexpected EOF" if peek.eof?

  ret_val = consume_component_value
  consume_whitespace
  return ret_val if peek.eof?

  syntax_error! "Expected EOF"
end

#parse_component_value_listObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/caps/parser/entrypoints.rb', line 85

def parse_component_value_list
  arr = []
  loop do
    obj = consume_component_value
    break if obj.eof?

    arr << obj
  end
  arr
end

#parse_declarationObject



57
58
59
60
61
62
63
64
# File 'lib/caps/parser/entrypoints.rb', line 57

def parse_declaration
  consume_whitespace
  syntax_error! "Unexpected #{peek.type}, expected ident" unless peek.ident?

  consume_declaration.tap do |decl|
    syntax_error! "Expected declaration to be consumed" if decl.nil?
  end
end

#parse_declaration_listObject



70
71
72
# File 'lib/caps/parser/entrypoints.rb', line 70

def parse_declaration_list
  consume_declaration_list
end

#parse_full_sheetObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/caps/parser/entrypoints.rb', line 8

def parse_full_sheet
  base = parse_stylesheet
  base[:value].map! do |obj|
    if obj[:type] == :qualified_rule
      p = Parser.new(obj.dig(:block, :value))
      obj[:block][:value] = p.parse_style_block_contents
    elsif obj[:type] == :at_rule && obj.dig(:name, :value).downcase == "font-face"
      p = Parser.new(obj.dig(:block, :value))
      obj[:block][:value] = p.parse_declaration_list
    end
    obj
  end

  base
end

#parse_ruleObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/caps/parser/entrypoints.rb', line 36

def parse_rule
  consume_whitespace
  val = peek
  if val.eof?
    # EOF. Raise syntax error.
    syntax_error! "Unexpected EOF"
  end

  ret_val = if val.at_rule?
    consume_at_rule
  else
    consume_qualified_rule
  end

  consume_whitespace

  syntax_error! "Expected EOF, found #{peek.type} instead" unless peek.eof?

  ret_val
end

#parse_rule_listObject



32
33
34
# File 'lib/caps/parser/entrypoints.rb', line 32

def parse_rule_list
  consume_list_of_rules(top_level: false)
end

#parse_style_block_contentsObject



66
67
68
# File 'lib/caps/parser/entrypoints.rb', line 66

def parse_style_block_contents
  consume_style_block_contents
end

#parse_stylesheet(location: nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/caps/parser/entrypoints.rb', line 24

def parse_stylesheet(location: nil)
  {
    type: :stylesheet,
    location:,
    value: consume_list_of_rules(top_level: true)
  }
end