Class: CSS::SAC::Parser

Inherits:
GeneratedParser show all
Defined in:
lib/css/sac/parser.rb

Constant Summary collapse

VERSION =

The version of CSSPool you’re using

'0.2.2'
TOKENIZER =
Tokenizer.new

Constants inherited from GeneratedParser

GeneratedParser::Racc_arg, GeneratedParser::Racc_debug_parser, GeneratedParser::Racc_token_to_s_table

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GeneratedParser

#_reduce_none

Constructor Details

#initialize(document_handler = StyleSheet.new(self)) ⇒ Parser

Returns a new instance of Parser.



23
24
25
26
27
28
29
# File 'lib/css/sac/parser.rb', line 23

def initialize(document_handler = StyleSheet.new(self))
  @error_handler = ErrorHandler.new
  @document_handler = document_handler
  @property_parser = PropertyParser.new()
  @tokenizer = TOKENIZER
  @logger = nil
end

Instance Attribute Details

#document_handlerObject

Returns the value of attribute document_handler.



21
22
23
# File 'lib/css/sac/parser.rb', line 21

def document_handler
  @document_handler
end

#error_handlerObject

Returns the value of attribute error_handler.



21
22
23
# File 'lib/css/sac/parser.rb', line 21

def error_handler
  @error_handler
end

#loggerObject

Returns the value of attribute logger.



21
22
23
# File 'lib/css/sac/parser.rb', line 21

def logger
  @logger
end

#property_parserObject (readonly)

Returns the value of attribute property_parser.



62
63
64
# File 'lib/css/sac/parser.rb', line 62

def property_parser
  @property_parser
end

#tokenizerObject (readonly)

Returns the value of attribute tokenizer.



63
64
65
# File 'lib/css/sac/parser.rb', line 63

def tokenizer
  @tokenizer
end

Instance Method Details

#parse_rule(rule) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/css/sac/parser.rb', line 44

def parse_rule(rule)
  returner = Class.new(DocumentHandler) {
    attr_accessor :selector
    alias :start_selector :selector=
  }.new
  old_document_handler = self.document_handler
  self.document_handler = returner
  self.parse("#{rule} { }")
  self.document_handler = old_document_handler
  returner.selector
end

#parse_style_sheet(string) ⇒ Object Also known as: parse



31
32
33
34
35
36
37
38
39
40
# File 'lib/css/sac/parser.rb', line 31

def parse_style_sheet(string)
  @yydebug = true
  @tokens = TOKENIZER.tokenize(string)
  @position = 0

  self.document_handler.start_document(string)
  do_parse
  self.document_handler.end_document(string)
  self.document_handler
end

#parser_versionObject

Returns the parser version. We return CSS2, but its actually CSS2.1. No font-face tags. Sorry.



58
59
60
# File 'lib/css/sac/parser.rb', line 58

def parser_version
  "http://www.w3.org/TR/REC-CSS2"
end