Class: Sass::Script::Parser

### Home Classes Methods

### In Files

- lib/sass/script/parser.rb

### Parent

Object

### Methods

- ::associative?
- ::new
- ::parse
- ::precedence_of
- #line
- #offset
- #parse
- #parse_function_definition_arglist
- #parse_interpolated
- #parse_mixin_definition_arglist
- #parse_mixin_include_arglist
- #parse_string
- #parse_until

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# Sass::Script::Parser

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

### Constants

ASSOCIATIVE
EXPR_NAMES

  It would be possible to have unified assert and try methods, but detecting the method/token difference turns out to be quite expensive.

PRECEDENCE

### Public Class Methods

associative?(op) click to toggle source

Returns whether or not the given operation is associative.

@private

    # File lib/sass/script/parser.rb, line 212
    def associative?(op)
      ASSOCIATIVE.include?(op)
    end

new(str, line, offset, options = {}) click to toggle source

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

    Used for error reporting and sourcemap building

@param offset [Fixnum] 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}

    # File lib/sass/script/parser.rb, line 29
    def initialize(str, line, offset, options = {})
      @options = options
      @lexer = lexer_class.new(str, line, offset, options)
    end

parse(*args) click to toggle source

Parses a SassScript expression.

@overload parse(str, line, offset, filename = nil) @return [Script::Tree::Node] The root node of the parse tree @see Parser#initialize @see Parser#parse

    # File lib/sass/script/parser.rb, line 182
    def self.parse(*args)
      new(*args).parse
    end

precedence_of(op) click to toggle source

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

@private

    # File lib/sass/script/parser.rb, line 202
    def precedence_of(op)
      PRECEDENCE.each_with_index do |e, i|
        return i if Array(e).include?(op)
      end
      raise "[BUG] Unknown operator #{op.inspect}"
    end

### Public Instance Methods

line() click to toggle source

The line number of the parser's current position.

@return [Fixnum]

    # File lib/sass/script/parser.rb, line 11
    def line
      @lexer.line
    end

offset() click to toggle source

The column number of the parser's current position.

@return [Fixnum]

    # File lib/sass/script/parser.rb, line 18
    def offset
      @lexer.offset
    end

parse() click to toggle source

Parses a SassScript expression.

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

    # File lib/sass/script/parser.rb, line 61
    def parse
      expr = assert_expr :expr
      assert_done
      expr.options = @options
      expr
    rescue Sass::SyntaxError => e
      e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
      raise e
    end

parse_function_definition_arglist() click to toggle source

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

    # File lib/sass/script/parser.rb, line 140
    def parse_function_definition_arglist
      args, splat = defn_arglist!(true)
      assert_done

      args.each do |k, v|
        k.options = @options
        v.options = @options if v
      end
      splat.options = @options if splat
      return args, splat
    rescue Sass::SyntaxError => e
      e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
      raise e
    end

parse_interpolated(warn_for_color = false) click to toggle source

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

    # File lib/sass/script/parser.rb, line 43
    def parse_interpolated(warn_for_color = false)
      # Start two characters back to compensate for #{
      start_pos = Sass::Source::Position.new(line, offset - 2)
      expr = assert_expr :expr
      assert_tok :end_interpolation
      expr = Sass::Script::Tree::Interpolation.new(
        nil, expr, nil, !:wb, !:wa, !:originally_text, warn_for_color)
      expr.options = @options
      node(expr, start_pos)
    rescue Sass::SyntaxError => e
      e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
      raise e
    end

parse_mixin_definition_arglist() click to toggle source

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

    # File lib/sass/script/parser.rb, line 120
    def parse_mixin_definition_arglist
      args, splat = defn_arglist!(false)
      assert_done

      args.each do |k, v|
        k.options = @options
        v.options = @options if v
      end
      splat.options = @options if splat
      return args, splat
    rescue Sass::SyntaxError => e
      e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
      raise e
    end

parse_mixin_include_arglist() click to toggle source

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

    # File lib/sass/script/parser.rb, line 97
    def parse_mixin_include_arglist
      args, keywords = [], {}
      if try_tok(:lparen)
        args, keywords, splat, kwarg_splat = mixin_arglist
        assert_tok(:rparen)
      end
      assert_done

      args.each {|a| a.options = @options}
      keywords.each {|k, v| v.options = @options}
      splat.options = @options if splat
      kwarg_splat.options = @options if kwarg_splat
      return args, keywords, splat, kwarg_splat
    rescue Sass::SyntaxError => e
      e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
      raise e
    end

parse_string() click to toggle source

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

    # File lib/sass/script/parser.rb, line 160
    def parse_string
      unless (peek = @lexer.peek) &&
          (peek.type == :string ||
          (peek.type == :funcall && peek.value.downcase == 'url'))
        lexer.expected!("string")
      end

      expr = assert_expr :funcall
      expr.options = @options
      @lexer.unpeek!
      expr
    rescue Sass::SyntaxError => e
      e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
      raise e
    end

parse_until(tokens) click to toggle source

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

    # File lib/sass/script/parser.rb, line 77
    def parse_until(tokens)
      @stop_at = tokens
      expr = assert_expr :expr
      assert_done
      expr.options = @options
      expr
    rescue Sass::SyntaxError => e
      e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
      raise e
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.