Module: Csscss::Parser::Common

Constant Summary collapse

UNITS =
%w(px em ex in cm mm pt pc)

Instance Method Summary collapse

Instance Method Details

#any_quoted(&block) ⇒ Object



75
76
77
# File 'lib/csscss/parser/common.rb', line 75

def any_quoted(&block)
  double_quoted(&block) | single_quoted(&block)
end

#between(left, right) ⇒ Object



58
59
60
61
# File 'lib/csscss/parser/common.rb', line 58

def between(left, right)
  raise "block not given" unless block_given?
  symbol(left) >> yield >> symbol(right)
end

#double_quoted(&block) ⇒ Object



67
68
69
# File 'lib/csscss/parser/common.rb', line 67

def double_quoted(&block)
  between('"', '"', &block)
end

#parens(&block) ⇒ Object



63
64
65
# File 'lib/csscss/parser/common.rb', line 63

def parens(&block)
  between("(", ")", &block)
end

#single_quoted(&block) ⇒ Object



71
72
73
# File 'lib/csscss/parser/common.rb', line 71

def single_quoted(&block)
  between("'", "'", &block)
end

#stri(str) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/csscss/parser/common.rb', line 38

def stri(str)
  key_chars = str.split(//)
  key_chars.
    collect! { |char|
      if char.upcase == char.downcase
        str(char)
      else
        match["#{char.upcase}#{char.downcase}"]
      end
    }.reduce(:>>)
end

#stri_list(list) ⇒ Object



79
80
81
# File 'lib/csscss/parser/common.rb', line 79

def stri_list(list)
  list.map {|u| stri(u) }.reduce(:|)
end

#symbol(s, label = nil) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/csscss/parser/common.rb', line 50

def symbol(s, label = nil)
  if label
    stri(s).as(label) >> space?
  else
    stri(s) >> space?
  end
end

#symbol_list(list) ⇒ Object



83
84
85
# File 'lib/csscss/parser/common.rb', line 83

def symbol_list(list)
  list.map {|u| symbol(u) }.reduce(:|)
end

#try_parse(input) ⇒ Object



87
88
89
90
# File 'lib/csscss/parser/common.rb', line 87

def try_parse(input)
  parsed = (root | nada).parse(input)
  parsed[:nada] ? false : parsed
end