The parser for SCSS. It parses a string of code into a tree of {Sass::Tree::Node}s.
Expose for the SASS parser.
@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 [Fixnum] The 1-based line on which the source string appeared,
if it's part of another document.
@param offset [Fixnum] The 1-based character (not byte) offset in the line on
which the source string starts. Used for error reporting and sourcemap building.
@comment
rubocop:disable ParameterLists
# File lib/sass/scss/parser.rb, line 25 def initialize(str, filename, importer, line = 1, offset = 1) # rubocop:enable ParameterLists @template = str @filename = filename @importer = importer @line = line @offset = offset @strs = [] 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
# File lib/sass/scss/parser.rb, line 39 def parse init_scanner! root = stylesheet expected("selector or at-rule") unless root && @scanner.eos? root 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.
# File lib/sass/scss/parser.rb, line 74 def parse_at_root_query init_scanner! query = at_root_query expected("@at-root query list") unless query && @scanner.eos? query 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
# File lib/sass/scss/parser.rb, line 52 def parse_interp_ident init_scanner! interp_ident 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.
# File lib/sass/scss/parser.rb, line 62 def parse_media_query_list init_scanner! ql = media_query_list expected("media query list") unless ql && @scanner.eos? ql 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.
# File lib/sass/scss/parser.rb, line 86 def parse_supports_condition init_scanner! condition = supports_condition expected("supports condition") unless condition && @scanner.eos? condition end