Class: HtmlConditionalComment::Parser
- Inherits:
-
Object
- Object
- HtmlConditionalComment::Parser
- Defined in:
- lib/html-conditional-comment/parser.rb
Overview
Parse tokens into a tree of nodes
Pseudo grammar
template = { html | statement } statement = “<!” , [ “–” ] , “if” , expression , “]” , [ “–” ] , “>” , template , “<!” , [ “–” ] , “endif” , “]” , [ “–” ] , “>” expression = term [ “|” , term ] term = factor [ “&” , factor ] factor = subexpression | “!” , factor | “(” , expression , “)” subexpression = [ operator ] browser | boolean operator = “gt” | “gte” | “lt” | “lte” boolean = “true” | “false” browser = feature [ version_vector ]
Constant Summary collapse
- OPEN =
/\-\->$/- CLOSE =
/<!\-\-$/
Instance Method Summary collapse
-
#initialize(tokens) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(tokens) ⇒ Parser
Returns a new instance of Parser.
28 29 30 31 32 33 |
# File 'lib/html-conditional-comment/parser.rb', line 28 def initialize(tokens) @symbol = nil @tokens = tokens @max_pos = tokens.size() - 1 @pos = -1 end |
Instance Method Details
#parse ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/html-conditional-comment/parser.rb', line 35 def parse() self.next() nodes = template() #Tokens left, syntax error error() if @pos < @max_pos nodes end |