Class: CssColorContrast::CommandInterpreter::Parser
- Inherits:
-
Object
- Object
- CssColorContrast::CommandInterpreter::Parser
- Defined in:
- lib/css_color_contrast/command_interpreter.rb
Instance Attribute Summary collapse
-
#node_tree ⇒ Object
readonly
Returns the value of attribute node_tree.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Class Method Summary collapse
Instance Method Summary collapse
- #ignore_space ⇒ Object
-
#initialize(line, env = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse! ⇒ Object
- #read_color_function(cur_pos) ⇒ Object
- #read_label ⇒ Object
- #read_separator ⇒ Object
- #root_node ⇒ Object
Constructor Details
#initialize(line, env = {}) ⇒ Parser
Returns a new instance of Parser.
131 132 133 134 135 136 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 131 def initialize(line, env = {}) @scanner = StringScanner.new(line) @env = env @tokens = [] @node_tree = [] end |
Instance Attribute Details
#node_tree ⇒ Object (readonly)
Returns the value of attribute node_tree.
129 130 131 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 129 def node_tree @node_tree end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
129 130 131 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 129 def tokens @tokens end |
Class Method Details
.parse!(line, env = {}) ⇒ Object
125 126 127 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 125 def self.parse!(line, env = {}) new(line, env).parse!.root_node end |
Instance Method Details
#ignore_space ⇒ Object
180 181 182 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 180 def ignore_space @scanner.scan(TokenRe::SPACE) end |
#parse! ⇒ Object
184 185 186 187 188 189 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 184 def parse! ignore_space read_label read_separator self end |
#read_color_function(cur_pos) ⇒ Object
160 161 162 163 164 165 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 160 def read_color_function(cur_pos) @scanner.pos = cur_pos color = Color.as_color(@scanner.scan_until(/\)/)) source = @scanner.string[cur_pos..(@scanner.pos)] Value.assign(source, @env, color) end |
#read_label ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 148 def read_label cur_pos = @scanner.pos label = @scanner.scan(TokenRe::LABEL) return unless label if TokenRe::COLOR_SCHEME.match?(label) @tokens.push read_color_function(cur_pos) else @tokens.push label end end |
#read_separator ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 167 def read_separator if @scanner.scan(TokenRe::FUNC_HEAD) @node_tree.push(Function.create(@tokens.pop, @env)) elsif @scanner.scan(TokenRe::SPACE) || @scanner.eos? token = @tokens.pop value = token.is_a?(Value) ? token : Value.assign(token, @env) current_node.push(value) end read_label read_separator unless @tokens.empty? end |
#root_node ⇒ Object
138 139 140 |
# File 'lib/css_color_contrast/command_interpreter.rb', line 138 def root_node @node_tree.first end |