class Sass::SCSS::Parser

The parser for SCSS. It parses a string of code into a tree of {Sass::Tree::Node}s.

Constants

DIRECTIVES
EXPR_NAMES
NEWLINE

Avoid allocating lots of new strings for `tok`. This is important because `tok` is called all the time.

PREFIXED_DIRECTIVES
TOK_NAMES

Public Class Methods

new(str, filename, line = 1) click to toggle source

@param 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 {Sass::Engine} or {Sass::CSS}.

@param filename [String] The name of the file being parsed. Used for warnings. @param line [Fixnum] The line on which the source string appeared,

if it's part of another document.
# File lib/sass/scss/parser.rb, line 14
def initialize(str, filename, line = 1)
  @template = str
  @filename = filename
  @line = line
  @strs = []
end

Public Instance Methods

parse() click to toggle source

Parses an SCSS document.

@return [Sass::Tree::RootNode] The root node of the document tree @raise [Sass::SyntaxError] if there's a syntax error in the document

# File lib/sass/scss/parser.rb, line 25
def parse
  init_scanner!
  root = stylesheet
  expected("selector or at-rule") unless @scanner.eos?
  root
end
parse_interp_ident() click to toggle source

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 `StringScanner`s as part of other parsers.

@return [Array<String, Sass::Script::Node>, nil]

The interpolated identifier, or nil if none could be parsed
# File lib/sass/scss/parser.rb, line 38
def parse_interp_ident
  init_scanner!
  interp_ident
end