Class: Sass::SCSS::Parser

Inherits:
Object
  • Object
show all
Includes:
RX
Defined in:
lib/sass/scss/parser.rb

Overview

The parser for SCSS. It parses a string of code into a tree of Tree::Nodes.

Direct Known Subclasses

StaticParser

Constant Summary

Constants included from RX

RX::ANY, RX::CDC, RX::CDO, RX::COMMENT, RX::DASHMATCH, RX::DOMAIN, RX::ESCAPE, RX::FUNCTION, RX::GREATER, RX::H, RX::HASH, RX::HEXCOLOR, RX::IDENT, RX::IDENT_HYPHEN_INTERP, RX::IMPORTANT, RX::INCLUDES, RX::INTERP_START, RX::NAME, RX::NL, RX::NMCHAR, RX::NMSTART, RX::NONASCII, RX::NOT, RX::NUM, RX::NUMBER, RX::OPTIONAL, RX::PLUS, RX::PREFIXMATCH, RX::RANGE, RX::S, RX::SINGLE_LINE_COMMENT, RX::STATIC_COMPONENT, RX::STATIC_SELECTOR, RX::STATIC_VALUE, RX::STRING, RX::STRING1, RX::STRING1_NOINTERP, RX::STRING2, RX::STRING2_NOINTERP, RX::STRING_NOINTERP, RX::SUBSTRINGMATCH, RX::SUFFIXMATCH, RX::TILDE, RX::UNICODE, RX::UNICODERANGE, RX::URI, RX::URL, RX::URLCHAR, RX::URL_PREFIX, RX::VARIABLE, RX::W

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RX

escape_ident

Constructor Details

#initialize(str, filename, importer, line = 1, offset = 1) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • str (String, StringScanner)

    The source document to parse. Note that Parser won't raise a nice error message if this isn't properly parsed; for that, you should use the higher-level Engine or CSS.

  • filename (String)

    The name of the file being parsed. Used for warnings and source maps.

  • importer (Sass::Importers::Base)

    The importer used to import the file being parsed. Used for source maps.

  • line (Fixnum) (defaults to: 1)

    The 1-based line on which the source string appeared, if it's part of another document.

  • offset (Fixnum) (defaults to: 1)

    The 1-based character (not byte) offset in the line on which the source string starts. Used for error reporting and sourcemap building.



25
26
27
28
29
30
31
32
33
# File 'lib/sass/scss/parser.rb', line 25

def initialize(str, filename, importer, line = 1, offset = 1)
  # rubocop:enable ParameterLists
  @template = str
  @filename = filename
  @importer = importer
  @line = line
  @offset = offset
  @strs = []
end

Instance Attribute Details

#offset

Expose for the SASS parser.



9
10
11
# File 'lib/sass/scss/parser.rb', line 9

def offset
  @offset
end

Instance Method Details

#parseSass::Tree::RootNode

Parses an SCSS document.

Returns:

Raises:



39
40
41
42
43
44
# File 'lib/sass/scss/parser.rb', line 39

def parse
  init_scanner!
  root = stylesheet
  expected("selector or at-rule") unless @scanner.eos?
  root
end

#parse_at_root_queryArray<String, Sass::Script;:Tree::Node>

Parses an at-root query.

Returns:

  • (Array<String, Sass::Script;:Tree::Node>)

    The interpolated query.

Raises:

  • (Sass::SyntaxError)

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



74
75
76
77
78
79
# File 'lib/sass/scss/parser.rb', line 74

def parse_at_root_query
  init_scanner!
  query = at_root_query
  expected("@at-root query list") unless @scanner.eos?
  query
end

#parse_interp_identArray<String, Sass::Script::Tree::Node>?

Parses an identifier with interpolation. Note that this won't assert that the identifier takes up the entire input string; it's meant to be used with StringScanners as part of other parsers.

Returns:



52
53
54
55
# File 'lib/sass/scss/parser.rb', line 52

def parse_interp_ident
  init_scanner!
  interp_ident
end

#parse_media_query_listSass::Media::QueryList

Parses a media query list.

Returns:

Raises:

  • (Sass::SyntaxError)

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



62
63
64
65
66
67
# File 'lib/sass/scss/parser.rb', line 62

def parse_media_query_list
  init_scanner!
  ql = media_query_list
  expected("media query list") unless @scanner.eos?
  ql
end

#parse_supports_conditionSass::Supports::Condition

Parses a supports query condition.

Returns:

Raises:

  • (Sass::SyntaxError)

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



86
87
88
89
90
91
# File 'lib/sass/scss/parser.rb', line 86

def parse_supports_condition
  init_scanner!
  condition = supports_condition
  expected("supports condition") unless @scanner.eos?
  condition
end