Class: Sass::Script::Parser

Inherits:
Object show all
Defined in:
lib/sass/script/parser.rb

Overview

The parser for SassScript. It parses a string of code into a tree of Nodes.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, line, offset, filename = nil) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • str (String, StringScanner)

    The source text to parse

  • line (Fixnum)

    The line on which the SassScript appears. Used for error reporting

  • offset (Fixnum)

    The number of characters in on which the SassScript appears. Used for error reporting

  • filename (String) (defaults to: nil)

    The name of the file in which the SassScript appears. Used for error reporting



15
16
17
18
# File 'lib/sass/script/parser.rb', line 15

def initialize(str, line, offset, filename = nil)
  @filename = filename
  @lexer = Lexer.new(str, line, offset, filename)
end

Class Method Details

.parse(str, line, offset, filename = nil) ⇒ Script::Node

Parses a SassScript expression.

Returns:

See Also:



81
82
83
# File 'lib/sass/script/parser.rb', line 81

def self.parse(*args)
  new(*args).parse
end

Instance Method Details

#parseScript::Node

Parses a SassScript expression.

Returns:

Raises:



37
38
39
40
41
# File 'lib/sass/script/parser.rb', line 37

def parse
  expr = assert_expr :expr
  assert_done
  expr
end

#parse_interpolatedScript::Node

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.

Returns:

Raises:



27
28
29
30
31
# File 'lib/sass/script/parser.rb', line 27

def parse_interpolated
  expr = assert_expr :expr
  assert_tok :end_interpolation
  expr
end

#parse_mixin_definition_arglistArray<Script::Node>

Parses the argument list for a mixin definition.

Returns:

  • (Array<Script::Node>)

    The root nodes of the arguments.

Raises:



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sass/script/parser.rb', line 63

def parse_mixin_definition_arglist
  args = []

  if try_tok(:lparen)
    args = defn_arglist(false) || args
    assert_tok(:rparen)
  end
  assert_done

  args
end

#parse_mixin_include_arglistArray<Script::Node>

Parses the argument list for a mixin include.

Returns:

  • (Array<Script::Node>)

    The root nodes of the arguments.

Raises:



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sass/script/parser.rb', line 47

def parse_mixin_include_arglist
  args = []

  if try_tok(:lparen)
    args = arglist || args
    assert_tok(:rparen)
  end
  assert_done

  args
end