### Home Classes Methods

### In Files

- lib/sass/script/lexer.rb

### Parent

Object

### Methods

- ::new
- #after_interpolation?
- #done?
- #expected!
- #next
- #peek
- #str
- #unpeek!
- #whitespace?

### Included Modules

- Sass::SCSS::RX

### Class/Module Index

Quicksearch

- Sass
- 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::Generic
- Sass::Exec::Sass
- Sass::Exec::SassConvert
- Sass::Exec::Scss
- 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::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::ArgList
- Sass::Script::Bool
- Sass::Script::Color
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Interpolation
- Sass::Script::Lexer
- Sass::Script::List
- Sass::Script::Literal
- Sass::Script::Node
- Sass::Script::Null
- Sass::Script::Number
- Sass::Script::Operation
- Sass::Script::Parser
- Sass::Script::String
- Sass::Script::StringInterpolation
- Sass::Script::UnaryOperation
- Sass::Script::Variable
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Interpolation
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::SelectorPseudoClass
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::Shared
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- 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::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::MultibyteStringScanner
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object

No matching classes.

# Sass::Script::Lexer

The lexical analyzer for SassScript. It takes a raw string and converts it to individual tokens that are easier to parse.

### Constants

IDENT_OP_NAMES

  A sub-list of {OP_NAMES} that only includes operators with identifier names.

OPERATORS

  A hash from operator strings to the corresponding token types.

OPERATORS_REVERSE
OP_NAMES

  A list of operator strings ordered with longer names first so that `>` and `<` don't clobber `>=` and `<=`.

REGULAR_EXPRESSIONS

  A hash of regular expressions that are used for tokenizing.

STRING_REGULAR_EXPRESSIONS

  A hash of regular expressions that are used for tokenizing strings.

  The key is a `[Symbol, Boolean]` pair. The symbol represents which style of quotation to use, while the boolean represents whether or not the string is following an interpolated segment.

TOKEN_NAMES
Token

  A struct containing information about an individual token.

  `type`: [`Symbol`] : The type of token.

  `value`: [`Object`] : The Ruby object corresponding to the value of the token.

  `line`: [`Fixnum`] : The line of the source file on which the token appears.

  `offset`: [`Fixnum`] : The number of bytes into the line the SassScript token appeared.

  `pos`: [`Fixnum`] : The scanner position at which the SassScript token appeared.

### Attributes

line[R]

The line number of the lexer's current position.

@return [Fixnum]

offset[R]

The number of bytes into the current line of the lexer's current position.

@return [Fixnum]

### Public Class Methods

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

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

    Used for error reporting

@param offset [Fixnum] The number of characters in on which the SassScript appears.

    Used for error reporting

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

    see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}

    # File lib/sass/script/lexer.rb, line 131
    def initialize(str, line, offset, options)
      @scanner = str.is_a?(StringScanner) ? str : Sass::Util::MultibyteStringScanner.new(str)
      @line = line
      @offset = offset
      @options = options
      @interpolation_stack = []
      @prev = nil
    end

### Public Instance Methods

after_interpolation?() click to toggle source

@return [Boolean] Whether or not the last token lexed was `:end_interpolation`.

    # File lib/sass/script/lexer.rb, line 182
    def after_interpolation?
      @prev && @prev.type == :end_interpolation
    end

done?() click to toggle source

@return [Boolean] Whether or not there's more source text to lex.

    # File lib/sass/script/lexer.rb, line 176
    def done?
      whitespace unless after_interpolation? && @interpolation_stack.last
      @scanner.eos? && @tok.nil?
    end

expected!(name) click to toggle source

Raise an error to the effect that `name` was expected in the input stream and wasn't found.

This calls {#unpeek!} to rewind the scanner to immediately after the last returned token.

@param name [String] The name of the entity that was expected but not found @raise [Sass::SyntaxError]

    # File lib/sass/script/lexer.rb, line 194
    def expected!(name)
      unpeek!
      Sass::SCSS::Parser.expected(@scanner, name, @line)
    end

next() click to toggle source

Moves the lexer forward one token.

@return [Token] The token that was moved past

    # File lib/sass/script/lexer.rb, line 143
    def next
      @tok ||= read_token
      @tok, tok = nil, @tok
      @prev = tok
      return tok
    end

peek() click to toggle source

Returns the next token without moving the lexer forward.

@return [Token] The next token

    # File lib/sass/script/lexer.rb, line 165
    def peek
      @tok ||= read_token
    end

str() click to toggle source

Records all non-comment text the lexer consumes within the block and returns it as a string.

@yield A block in which text is recorded @return [String]

    # File lib/sass/script/lexer.rb, line 204
    def str
      old_pos = @tok ? @tok.pos : @scanner.pos
      yield
      new_pos = @tok ? @tok.pos : @scanner.pos
      @scanner.string[old_pos...new_pos]
    end

unpeek!() click to toggle source

Rewinds the underlying StringScanner to before the token returned by {#peek}.

    # File lib/sass/script/lexer.rb, line 171
    def unpeek!
      @scanner.pos = @tok.pos if @tok
    end

whitespace?(tok = @tok) click to toggle source

Returns whether or not there's whitespace before the next token.

@return [Boolean]

    # File lib/sass/script/lexer.rb, line 153
    def whitespace?(tok = @tok)
      if tok
        @scanner.string[0...tok.pos] =~ /\s\Z/
      else
        @scanner.string[@scanner.pos, 1] =~ /^\s/ ||
          @scanner.string[@scanner.pos - 1, 1] =~ /\s\Z/
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.