Class: Sass::SCSS::Parser

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

Overview

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

Direct Known Subclasses

SassParser, StaticParser

Constant Summary

Instance Method Summary

Methods included from RX

escape_ident

Constructor Details

- (Parser) initialize(str, filename, line = 1)

A new instance of Parser

Parameters:

  • (String, StringScanner) str — 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 Sass::Engine or Sass::CSS.
  • (String) filename — The name of the file being parsed. Used for warnings.
  • (Fixnum) line (defaults to: 1) — The line on which the source string appeared, if it’s part of another document.


14
15
16
17
18
19
# File '/var/www/sass-pages/.sass/lib/sass/scss/parser.rb', line 14

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

Instance Method Details

- (Sass::Tree::RootNode) parse

Parses an SCSS document.

Returns:

Raises:



25
26
27
28
29
30
# File '/var/www/sass-pages/.sass/lib/sass/scss/parser.rb', line 25

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

- (Array<String, Sass::Script::Node>?) parse_interp_ident

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


38
39
40
41
# File '/var/www/sass-pages/.sass/lib/sass/scss/parser.rb', line 38

def parse_interp_ident
  init_scanner!
  interp_ident
end