Class: HtmlConditionalComment::Parser

Inherits:
Object
  • Object
show all
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 ]

Instance Method Summary collapse

Constructor Details

#initialize(tokens) ⇒ Parser

Returns a new instance of Parser.



25
26
27
28
29
30
# File 'lib/html-conditional-comment/parser.rb', line 25

def initialize(tokens)
  @symbol = nil
  @tokens = tokens
  @max_pos = tokens.size() - 1
  @pos = -1
end

Instance Method Details

#parseObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/html-conditional-comment/parser.rb', line 32

def parse()
  self.next()

  nodes = template()

  #Tokens left, syntax error
  error() if @pos < @max_pos

  nodes
end