Class: Hexp::CssSelector::Parser
- Inherits:
-
Object
- Object
- Hexp::CssSelector::Parser
- Defined in:
- lib/hexp/css_selector/parser.rb
Overview
A parser of CSS selectors
This is a wrapper around the SASS parser. This way we are isolated from changes in SASS. It also makes things easier should we decide to switch to a different parsing library or roll our own parser. We only use a fraction of the functionality of SASS so this might be worth it, although at this point I want to avoid reinventing that wheel.
The classes that make up the parse tree largely mimic the ones from SASS, like CommaSequence, SimpleSequence, Class, Id, etc. By having them in our own namespace however we can easily add Hexp-specific helper functions.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Parser) initialize(selector)
constructor
A new instance of Parser.
- - (Object) parse
Constructor Details
- (Parser) initialize(selector)
A new instance of Parser
16 17 18 |
# File 'lib/hexp/css_selector/parser.rb', line 16 def initialize(selector) @selector = selector.freeze end |
Class Method Details
+ (Object) call(selector)
24 25 26 |
# File 'lib/hexp/css_selector/parser.rb', line 24 def self.call(selector) new(selector).parse end |
Instance Method Details
- (Object) parse
20 21 22 |
# File 'lib/hexp/css_selector/parser.rb', line 20 def parse rewrite_comma_sequence(SassParser.call(@selector)) end |