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
Attributes
@private
Expose for the SASS parser.
Public Class Methods
Source
# File lib/sass/scss/parser.rb, line 1288 def self.expected(scanner, expected, line) pos = scanner.pos after = scanner.string[0...pos] # Get rid of whitespace between pos and the last token, # but only if there's a newline in there after.gsub!(/\s*\n\s*$/, '') # Also get rid of stuff before the last newline after.gsub!(/.*\n/, '') after = "..." + after[-15..-1] if after.size > 18 was = scanner.rest.dup # Get rid of whitespace between pos and the next token, # but only if there's a newline in there was.gsub!(/^\s*\n\s*/, '') # Also get rid of stuff after the next newline was.gsub!(/\n.*/, '') was = was[0...15] + "..." if was.size > 18 raise Sass::SyntaxError.new( "Invalid CSS after \"#{after}\": expected #{expected}, was \"#{was}\"", :line => line) end
@private
Source
# File lib/sass/scss/parser.rb, line 23 def initialize(str, filename, importer, line = 1, offset = 1) @template = str @filename = filename @importer = importer @line = line @offset = offset @strs = [] @expected = nil @throw_error = false end
@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 and source maps.
@param importer [Sass::Importers::Base] The importer used to import the
file being parsed. Used for source maps.
@param line [Integer] The 1-based line on which the source string appeared,
if it's part of another document.
@param offset [Integer] The 1-based character (not byte) offset in the line on
which the source string starts. Used for error reporting and sourcemap building.
Public Instance Methods
Source
# File lib/sass/scss/parser.rb, line 38 def parse init_scanner! root = stylesheet expected("selector or at-rule") unless root && @scanner.eos? root end
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
Source
# File lib/sass/scss/parser.rb, line 82 def parse_at_root_query init_scanner! query = at_root_query expected("@at-root query list") unless query && @scanner.eos? query end
Parses an at-root query.
@return [Array<String, Sass::Script;:Tree::Node>] The interpolated query. @raise [Sass::SyntaxError] if there’s a syntax error in the query,
or if it doesn't take up the entire input string.
Source
# File lib/sass/scss/parser.rb, line 106 def parse_declaration_value init_scanner! value = declaration_value expected('"}"') unless value && @scanner.eos? value end
Parses a custom property value.
@return [Array<String, Sass::Script;:Tree::Node>] The interpolated value. @raise [Sass::SyntaxError] if there’s a syntax error in the value,
or if it doesn't take up the entire input string.
Source
# File lib/sass/scss/parser.rb, line 51 def parse_interp_ident init_scanner! interp_ident end
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::Tree::Node>, nil]
The interpolated identifier, or nil if none could be parsed
Source
# File lib/sass/scss/parser.rb, line 70 def parse_media_query_list init_scanner! ql = media_query_list expected("media query list") unless ql && @scanner.eos? ql end
Parses a media query list.
@return [Sass::Media::QueryList] The parsed query list @raise [Sass::SyntaxError] if there’s a syntax error in the query list,
or if it doesn't take up the entire input string.
Source
# File lib/sass/scss/parser.rb, line 57 def parse_supports_clause init_scanner! ss clause = supports_clause ss clause end
Parses a supports clause for an @import directive
Source
# File lib/sass/scss/parser.rb, line 94 def parse_supports_condition init_scanner! condition = supports_condition expected("supports condition") unless condition && @scanner.eos? condition end
Parses a supports query condition.
@return [Sass::Supports::Condition] The parsed condition @raise [Sass::SyntaxError] if there’s a syntax error in the condition,
or if it doesn't take up the entire input string.