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::Node}s.

Methods

Public Class methods

@param str [String, StringScanner] The source text to parse @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 filename [String] The name of the file in which the SassScript appears.

  Used for error reporting

[Source]

    # File lib/sass/script/parser.rb, line 15
15:       def initialize(str, line, offset, filename = nil)
16:         @filename = filename
17:         @lexer = Lexer.new(str, line, offset, filename)
18:       end

Parses a SassScript expression.

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

[Source]

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

Public Instance methods

Parses a SassScript expression.

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

[Source]

    # File lib/sass/script/parser.rb, line 37
37:       def parse
38:         expr = assert_expr :expr
39:         assert_done
40:         expr
41:       end

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.

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

[Source]

    # File lib/sass/script/parser.rb, line 27
27:       def parse_interpolated
28:         expr = assert_expr :expr
29:         assert_tok :end_interpolation
30:         expr
31:       end

Parses the argument list for a mixin definition.

@return [Array<Script::Node>] The root nodes of the arguments. @raise [Sass::SyntaxError] if the argument list isn‘t valid SassScript

[Source]

    # File lib/sass/script/parser.rb, line 63
63:       def parse_mixin_definition_arglist
64:         args = []
65: 
66:         if try_tok(:lparen)
67:           args = defn_arglist(false) || args
68:           assert_tok(:rparen)
69:         end
70:         assert_done
71: 
72:         args
73:       end

Parses the argument list for a mixin include.

@return [Array<Script::Node>] The root nodes of the arguments. @raise [Sass::SyntaxError] if the argument list isn‘t valid SassScript

[Source]

    # File lib/sass/script/parser.rb, line 47
47:       def parse_mixin_include_arglist
48:         args = []
49: 
50:         if try_tok(:lparen)
51:           args = arglist || args
52:           assert_tok(:rparen)
53:         end
54:         assert_done
55: 
56:         args
57:       end

[Validate]