Class: Sass::SCSS::StaticParser

Inherits:
Parser
  • Object
show all
Defined in:
/home/nweiz/code/sass-site/.sass/lib/sass/scss/static_parser.rb

Overview

A parser for a static SCSS tree. Parses with SCSS extensions, like nested rules and parent selectors, but without dynamic SassScript. This is useful for e.g. parsing selectors after resolving the interpolation.

Direct Known Subclasses

CssParser

Constant Summary

Instance Attribute Summary

Attributes inherited from Parser

#offset

Instance Method Summary (collapse)

Methods inherited from Parser

#parse, #parse_at_root_query, #parse_declaration_value, #parse_interp_ident, #parse_media_query_list, #parse_supports_clause, #parse_supports_condition

Methods included from RX

escape_ident

Constructor Details

- (StaticParser) initialize(str, filename, importer, line = 1, offset = 1, allow_parent_ref = true)

Returns a new instance of StaticParser

Parameters:

  • allow_parent_ref (Boolean) (defaults to: true)

    Whether to allow the parent-reference selector, &, when parsing the document.

See Also:



56
57
58
59
60
# File '/home/nweiz/code/sass-site/.sass/lib/sass/scss/static_parser.rb', line 56

def initialize(str, filename, importer, line = 1, offset = 1, allow_parent_ref = true)
  # rubocop:enable ParameterLists
  super(str, filename, importer, line, offset)
  @allow_parent_ref = allow_parent_ref
end

Instance Method Details

- parse_keyframes_selector



44
45
46
47
48
49
# File '/home/nweiz/code/sass-site/.sass/lib/sass/scss/static_parser.rb', line 44

def parse_keyframes_selector
  init_scanner!
  sel = expr!(:keyframes_selector)
  expected("keyframes selector") unless @scanner.eos?
  sel
end

- (Selector::CommaSequence) parse_selector

Parses the text as a selector.

Parameters:

  • filename (String, nil)

    The file in which the selector appears, or nil if there is no such file. Used for error reporting.

Returns:

Raises:



18
19
20
21
22
23
24
25
# File '/home/nweiz/code/sass-site/.sass/lib/sass/scss/static_parser.rb', line 18

def parse_selector
  init_scanner!
  seq = expr!(:selector_comma_sequence)
  expected("selector") unless @scanner.eos?
  seq.line = @line
  seq.filename = @filename
  seq
end

- ((Symbol, Array<String>)) parse_static_at_root_query

Parses a static at-root query.

Returns:

  • ((Symbol, Array<String>))

    The type of the query (:with or :without) and the values that are being filtered.

Raises:

  • (Sass::SyntaxError)

    if there's a syntax error in the query, or if it doesn't take up the entire input string.



33
34
35
36
37
38
39
40
41
42
# File '/home/nweiz/code/sass-site/.sass/lib/sass/scss/static_parser.rb', line 33

def parse_static_at_root_query
  init_scanner!
  tok!(/\(/); ss
  type = tok!(/\b(without|with)\b/).to_sym; ss
  tok!(/:/); ss
  directives = expr!(:at_root_directive_list); ss
  tok!(/\)/)
  expected("@at-root query list") unless @scanner.eos?
  return type, directives
end