Class Sass::Script::Parser
In: lib/sass/script/parser.rb
Parent: Object

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

Methods

Constants

PRECEDENCE = [ :comma, :single_eq, :space, :or, :and, [:eq, :neq], [:gt, :gte, :lt, :lte], [:plus, :minus], [:times, :div, :mod], ]
ASSOCIATIVE = [:plus, :times]
VALID_CSS_OPS = [:comma, :single_eq, :space, :div]
EXPR_NAMES = { :string => "string", :default => "expression (e.g. 1px, bold)", :mixin_arglist => "mixin argument", :fn_arglist => "function argument", :splat => "...", :special_fun => '")"', }   It would be possible to have unified assert and try methods, but detecting the method/token difference turns out to be quite expensive.

Public Class methods

Returns whether or not the given operation is associative.

@private

@param str [String, StringScanner] The source text to parse @param line [Integer] The line on which the SassScript appears.

  Used for error reporting and sourcemap building

@param offset [Integer] The character (not byte) offset where the script starts in the line.

  Used for error reporting and sourcemap building

@param options [{Symbol => Object}] An options hash; see

  {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
  This supports an additional `:allow_extra_text` option that controls
  whether the parser throws an error when extra text is encountered
  after the parsed construct.

Parses a SassScript expression.

@return [Script::Tree::Node] The root node of the parse tree @see Parser#initialize @see Parser#parse

Returns an integer representing the precedence of the given operator. A lower integer indicates a looser binding.

@private

Public Instance methods

The line number of the parser‘s current position.

@return [Integer]

The column number of the parser‘s current position.

@return [Integer]

Parses a SassScript expression.

@param css_variable [Boolean] Whether this is the value of a CSS variable. @return [Script::Tree::Node] The root node of the parse tree @raise [Sass::SyntaxError] if the expression isn‘t valid SassScript

Parses the argument list for a function definition.

@return [(Array<Script::Tree::Node>, Script::Tree::Node)]

  The root nodes of the arguments, and the splat argument.

@raise [Sass::SyntaxError] if the argument list isn‘t valid SassScript

Parses a SassScript expression within an interpolated segment (`#{}`). This means that it stops when it comes across an unmatched `}`, which signals the end of an interpolated segment, it returns rather than throwing an error.

@param warn_for_color [Boolean] Whether raw color values passed to

  interoplation should cause a warning.

@return [Script::Tree::Node] The root node of the parse tree @raise [Sass::SyntaxError] if the expression isn‘t valid SassScript

Parses the argument list for a mixin definition.

@return [(Array<Script::Tree::Node>, Script::Tree::Node)]

  The root nodes of the arguments, and the splat argument.

@raise [Sass::SyntaxError] if the argument list isn‘t valid SassScript

Parses the argument list for a mixin include.

@return [(Array<Script::Tree::Node>,

         {String => Script::Tree::Node},
         Script::Tree::Node,
         Script::Tree::Node)]
  The root nodes of the positional arguments, keyword arguments, and
  splat argument(s). Keyword arguments are in a hash from names to values.

@raise [Sass::SyntaxError] if the argument list isn‘t valid SassScript

Parse a single string value, possibly containing interpolation. Doesn‘t assert that the scanner is finished after parsing.

@return [Script::Tree::Node] The root node of the parse tree. @raise [Sass::SyntaxError] if the string isn‘t valid SassScript

Parses a SassScript expression, ending it when it encounters one of the given identifier tokens.

@param tokens [include?(String)] A set of strings that delimit the expression. @return [Script::Tree::Node] The root node of the parse tree @raise [Sass::SyntaxError] if the expression isn‘t valid SassScript

[Validate]