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

SassParser, StaticParser

Constant Summary

Constants included from RX

RX::CDC, RX::CDO, RX::COMMENT, RX::DASHMATCH, RX::DEFAULT, 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::MOZ_ANY, RX::NAME, RX::NL, RX::NMCHAR, RX::NMSTART, RX::NONASCII, RX::NOT, RX::NUM, RX::NUMBER, RX::PLUS, RX::PREFIXMATCH, RX::RANGE, RX::S, RX::SINGLE_LINE_COMMENT, 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::VARIABLE, RX::W

Instance Method Summary collapse

Methods included from RX

escape_ident

Constructor Details

#initialize(str, filename, line = 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.

  • line (Fixnum) (defaults to: 1)

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



15
16
17
18
19
20
# File 'lib/sass/scss/parser.rb', line 15

def initialize(str, filename, line = 1)
  @template = str
  @filename = filename
  @line = line
  @strs = []
end

Instance Method Details

#parseSass::Tree::RootNode

Parses an SCSS document.

Returns:

Raises:



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

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

#parse_interp_identArray<String, Sass::Script::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:

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

    The interpolated identifier, or nil if none could be parsed



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

def parse_interp_ident
  init_scanner!
  interp_ident
end