Class: XDry::SelectorDef
- Inherits:
-
Object
show all
- Defined in:
- lib/xdry/parsing/parts/selectors.rb
Class Method Summary
collapse
Class Method Details
.parse(string) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/xdry/parsing/parts/selectors.rb', line 6
def self.parse string
string = string.strip
if string =~ /^\w+$/
SimpleSelectorDef.new(string)
else
comps = string.split(/\s+(?!\*)/).collect do |component_string|
if component_string =~ /^(\w+:)\s*(?:\(([^)]+)\)\s*)?(\w*)$/
keyword, type_decl, arg_name = $1, $2, $3
type = if type_decl then VarType.parse(type_decl) else nil end
SelectorComponent.new(keyword, arg_name, type)
else
raise StandardError, "Cannot parse selector component '#{component_string}' for selector '#{string}'"
end
end
CompoundSelectorDef.new(comps)
end
end
|