Class: Excession::Parser::CssParser

Inherits:
Parslet::Parser
  • Object
show all
Defined in:
lib/excession/parser/css_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(strict = false) ⇒ CssParser

Returns a new instance of CssParser.



10
11
12
13
# File 'lib/excession/parser/css_parser.rb', line 10

def initialize(strict=false)
  @strict=strict
  super()
end

Instance Method Details

#cimatch(char) ⇒ Object

Case insensitive character match with escaped character codes.

TODO: The CSS2.1 spec allows all letters apart from a,c,d and e to be specified like ā€œgā€. This is not supported here.



143
144
145
146
147
148
149
150
151
# File 'lib/excession/parser/css_parser.rb', line 143

def cimatch(char)
  upper = char.upcase.force_encoding("BINARY")
  lower = char.downcase.force_encoding("BINARY")
  return match["#{upper}#{lower}"] | 
    ( str("\\") >> 
      str("0").repeat(0,4) >>
      (str(upper[0].ord.to_s(16)) | str(lower[0].ord.to_s(16))) >>
      (str("\r\n") | match[" \t\r\n\f"]).maybe )
end

#cimatch_word(word) ⇒ Object



154
155
156
# File 'lib/excession/parser/css_parser.rb', line 154

def cimatch_word(word)
  word.each_char.map{|c| self.cimatch(c)}.reduce(:>>)
end