Class: CSS::SAC::PropertyParser

Inherits:
GeneratedPropertyParser show all
Defined in:
lib/css/sac/property_parser.rb

Constant Summary

Constants inherited from GeneratedPropertyParser

GeneratedPropertyParser::Racc_arg, GeneratedPropertyParser::Racc_debug_parser, GeneratedPropertyParser::Racc_token_to_s_table

Instance Method Summary collapse

Methods inherited from GeneratedPropertyParser

#_reduce_none

Constructor Details

#initializePropertyParser

Returns a new instance of PropertyParser.



6
7
8
9
# File 'lib/css/sac/property_parser.rb', line 6

def initialize
  @tokens = []
  @token_table = Racc_arg[10]
end

Instance Method Details

#parse_tokens(tokens) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/css/sac/property_parser.rb', line 11

def parse_tokens(tokens)
  negate = false # Nasty hack for unary minus
  @tokens = tokens.find_all { |x| x.name != :S }.map { |token|
    tok = if @token_table.has_key?(token.value)
            [token.value, token.value]
          else
            if token.name == :delim && !@token_table.has_key?(token.value)
              negate = true if token.value == '-'
              nil
            else
              token.to_racc_token
            end
          end

    if negate && tok
      tok[1] = "-#{tok[1]}"
      negate = false
    end

    tok
  }.compact

  begin
    return do_parse
  rescue ParseError => e
    return nil
  end
end