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::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::W

Instance Method Summary collapse

Methods included from RX

escape_ident

Constructor Details

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

  • line (Fixnum) (defaults to: 1)

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



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

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

Instance Method Details

#parseSass::Tree::RootNode

Parses an SCSS document.

Returns:

Raises:



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

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



37
38
39
40
# File 'lib/sass/scss/parser.rb', line 37

def parse_interp_ident
  init_scanner!
  interp_ident
end