Class: Oga::CSS::Parser Private
- Inherits:
-
LL::Driver
- Object
- LL::Driver
- Oga::CSS::Parser
- Defined in:
- lib/oga/css/parser.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- CONFIG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
LL::DriverConfig.new
- CACHE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
LRU.new
Class Method Summary collapse
Instance Method Summary collapse
-
#current_element ⇒ AST::Node
private
Returns the node test for the current element.
-
#each_token {|| ... } ⇒ Object
private
Yields the next token from the lexer.
-
#initialize(data) ⇒ Parser
constructor
private
A new instance of Parser.
-
#on_op_ends_with(attr, value) ⇒ AST::Node
private
Generates the AST for the
$=
operator. -
#on_op_eq(attr, value) ⇒ AST::Node
private
Generates the AST for the
=
operator. -
#on_op_hyphen_in(attr, value) ⇒ AST::Node
private
Generates the AST for the
|=
operator. -
#on_op_in(attr, value) ⇒ AST::Node
private
Generates the AST for the
*=
operator. -
#on_op_space_in(attr, value) ⇒ AST::Node
private
Generates the AST for the
~=
operator. -
#on_op_starts_with(attr, value) ⇒ AST::Node
private
Generates the AST for the
^=
operator. - #on_pseudo_class(name, arg = nil) ⇒ AST::Node private
-
#on_pseudo_class_empty ⇒ AST::Node
private
Generates the AST for the
:empty
selector. -
#on_pseudo_class_first_child ⇒ AST::Node
private
Generates the AST for the
:first-child
selector. -
#on_pseudo_class_first_of_type ⇒ AST::Node
private
Generates the AST for the
:first-of-type
selector. -
#on_pseudo_class_last_child ⇒ AST::Node
private
Generates the AST for the
:last-child
selector. -
#on_pseudo_class_last_of_type ⇒ AST::Node
private
Generates the AST for the
:last-of-type
selector. -
#on_pseudo_class_nth_child(arg) ⇒ AST::Node
private
Generates the AST for the
nth-child
pseudo class. -
#on_pseudo_class_nth_last_child(arg) ⇒ AST::Node
private
Generates the AST for the
nth-last-child
pseudo class. -
#on_pseudo_class_nth_last_of_type(arg) ⇒ AST::Node
private
Generates the AST for the
nth-last-of-type
pseudo class. -
#on_pseudo_class_nth_of_type(arg) ⇒ AST::Node
private
Generates the AST for the
nth-of-type
pseudo class. -
#on_pseudo_class_only_child ⇒ AST::Node
private
Generates the AST for the
:only-child
selector. -
#on_pseudo_class_only_of_type ⇒ AST::Node
private
Generates the AST for the
:only-of-type
selector. -
#on_pseudo_class_root ⇒ AST::Node
private
Generates the AST for the
root
pseudo class. -
#on_test(namespace, name) ⇒ AST::Node
private
Generates the AST for a node test.
-
#parse ⇒ AST::Node
private
Parses the input and returns the corresponding AST.
-
#reset ⇒ Object
private
Resets the internal state of the parser.
- #s(type, *children) ⇒ AST::Node private
Constructor Details
Class Method Details
.parse_with_cache(data) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
228 229 230 |
# File 'lib/oga/css/parser.rb', line 228 def self.parse_with_cache(data) return CACHE.get_or_set(data) { new(data).parse } end |
Instance Method Details
#current_element ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the node test for the current element.
273 274 275 |
# File 'lib/oga/css/parser.rb', line 273 def current_element @current_element ||= s(:test, nil, '*') end |
#each_token {|| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Yields the next token from the lexer.
260 261 262 263 264 265 266 |
# File 'lib/oga/css/parser.rb', line 260 def each_token @lexer.advance do |*args| yield args end yield [-1, -1] end |
#on_op_ends_with(attr, value) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the $=
operator.
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/oga/css/parser.rb', line 471 def on_op_ends_with(attr, value) s( :eq, s( :call, 'substring', attr, s( :add, s( :sub, s(:call, 'string-length', attr), s(:call, 'string-length', value) ), s(:int, 1) ), s(:call, 'string-length', value) ), value ) end |
#on_op_eq(attr, value) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the =
operator.
433 434 435 |
# File 'lib/oga/css/parser.rb', line 433 def on_op_eq(attr, value) s(:eq, attr, value) end |
#on_op_hyphen_in(attr, value) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the |=
operator.
511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/oga/css/parser.rb', line 511 def on_op_hyphen_in(attr, value) s( :or, s(:eq, attr, value), s( :call, 'starts-with', attr, s(:call, 'concat', value, s(:string, '-')) ) ) end |
#on_op_in(attr, value) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the *=
operator.
500 501 502 |
# File 'lib/oga/css/parser.rb', line 500 def on_op_in(attr, value) s(:call, 'contains', attr, value) end |
#on_op_space_in(attr, value) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the ~=
operator.
444 445 446 447 448 449 450 451 |
# File 'lib/oga/css/parser.rb', line 444 def on_op_space_in(attr, value) s( :call, 'contains', s(:call, 'concat', s(:string, ' '), attr, s(:string, ' ')), s(:call, 'concat', s(:string, ' '), value, s(:string, ' ')) ) end |
#on_op_starts_with(attr, value) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the ^=
operator.
460 461 462 |
# File 'lib/oga/css/parser.rb', line 460 def on_op_starts_with(attr, value) s(:call, 'starts-with', attr, value) end |
#on_pseudo_class(name, arg = nil) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
308 309 310 311 312 |
# File 'lib/oga/css/parser.rb', line 308 def on_pseudo_class(name, arg = nil) handler = "on_pseudo_class_#{name.gsub('-', '_')}" arg ? send(handler, arg) : send(handler) end |
#on_pseudo_class_empty ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the :empty
selector.
422 423 424 |
# File 'lib/oga/css/parser.rb', line 422 def on_pseudo_class_empty s(:call, 'not', s(:axis, 'child', s(:type_test, 'node'))) end |
#on_pseudo_class_first_child ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the :first-child
selector.
368 369 370 |
# File 'lib/oga/css/parser.rb', line 368 def on_pseudo_class_first_child generate_no_siblings('preceding-sibling') end |
#on_pseudo_class_first_of_type ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the :first-of-type
selector.
386 387 388 |
# File 'lib/oga/css/parser.rb', line 386 def on_pseudo_class_first_of_type generate_no_siblings('preceding-sibling', current_element) end |
#on_pseudo_class_last_child ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the :last-child
selector.
377 378 379 |
# File 'lib/oga/css/parser.rb', line 377 def on_pseudo_class_last_child generate_no_siblings('following-sibling') end |
#on_pseudo_class_last_of_type ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the :last-of-type
selector.
395 396 397 |
# File 'lib/oga/css/parser.rb', line 395 def on_pseudo_class_last_of_type generate_no_siblings('following-sibling', current_element) end |
#on_pseudo_class_nth_child(arg) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the nth-child
pseudo class.
329 330 331 |
# File 'lib/oga/css/parser.rb', line 329 def on_pseudo_class_nth_child(arg) generate_nth_child('preceding-sibling', arg) end |
#on_pseudo_class_nth_last_child(arg) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the nth-last-child
pseudo class.
339 340 341 |
# File 'lib/oga/css/parser.rb', line 339 def on_pseudo_class_nth_last_child(arg) generate_nth_child('following-sibling', arg) end |
#on_pseudo_class_nth_last_of_type(arg) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the nth-last-of-type
pseudo class.
359 360 361 |
# File 'lib/oga/css/parser.rb', line 359 def on_pseudo_class_nth_last_of_type(arg) generate_nth_child('following-sibling', arg, current_element) end |
#on_pseudo_class_nth_of_type(arg) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the nth-of-type
pseudo class.
349 350 351 |
# File 'lib/oga/css/parser.rb', line 349 def on_pseudo_class_nth_of_type(arg) generate_nth_child('preceding-sibling', arg, current_element) end |
#on_pseudo_class_only_child ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the :only-child
selector.
404 405 406 |
# File 'lib/oga/css/parser.rb', line 404 def on_pseudo_class_only_child s(:and, on_pseudo_class_first_child, on_pseudo_class_last_child) end |
#on_pseudo_class_only_of_type ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the :only-of-type
selector.
413 414 415 |
# File 'lib/oga/css/parser.rb', line 413 def on_pseudo_class_only_of_type s(:and, on_pseudo_class_first_of_type, on_pseudo_class_last_of_type) end |
#on_pseudo_class_root ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for the root
pseudo class.
319 320 321 |
# File 'lib/oga/css/parser.rb', line 319 def on_pseudo_class_root s(:call, 'not', s(:axis, 'parent', s(:test, nil, '*'))) end |
#on_test(namespace, name) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates the AST for a node test.
299 300 301 |
# File 'lib/oga/css/parser.rb', line 299 def on_test(namespace, name) @current_element = s(:test, namespace, name) end |
#parse ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parses the input and returns the corresponding AST.
286 287 288 289 290 |
# File 'lib/oga/css/parser.rb', line 286 def parse reset super end |
#reset ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resets the internal state of the parser.
242 243 244 |
# File 'lib/oga/css/parser.rb', line 242 def reset @current_element = nil end |
#s(type, *children) ⇒ AST::Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
251 252 253 |
# File 'lib/oga/css/parser.rb', line 251 def s(type, *children) return AST::Node.new(type, children) end |