Class: Sass::Script::Parser
- Inherits:
-
Object
- Object
- Sass::Script::Parser
- Defined in:
- lib/sass/script/parser.rb
Overview
The parser for SassScript. It parses a string of code into a tree of Nodes.
Direct Known Subclasses
Constant Summary collapse
- PRECEDENCE =
[ :comma, :single_eq, :concat, :or, :and, [:eq, :neq], [:gt, :gte, :lt, :lte], [:plus, :minus], [:times, :div, :mod], ]
Class Method Summary collapse
-
.parse(str, line, offset, filename = nil) ⇒ Script::Node
Parses a SassScript expression.
Instance Method Summary collapse
-
#initialize(str, line, offset, options = {}) ⇒ Parser
constructor
A new instance of Parser.
-
#line ⇒ Fixnum
The line number of the parser's current position.
-
#parse ⇒ Script::Node
Parses a SassScript expression.
-
#parse_interpolated ⇒ Script::Node
Parses a SassScript expression within an interpolated segment (
#{}
). -
#parse_mixin_definition_arglist ⇒ Array<Script::Node>
Parses the argument list for a mixin definition.
-
#parse_mixin_include_arglist ⇒ Array<Script::Node>
Parses the argument list for a mixin include.
-
#parse_until(tokens) ⇒ Script::Node
Parses a SassScript expression, ending it when it encounters one of the given identifier tokens.
Constructor Details
#initialize(str, line, offset, options = {}) ⇒ Parser
Returns a new instance of Parser.
22 23 24 25 |
# File 'lib/sass/script/parser.rb', line 22
def initialize(str, line, offset, options = {})
@options = options
@lexer = lexer_class.new(str, line, offset, options)
end
|
Class Method Details
.parse(str, line, offset, filename = nil) ⇒ Script::Node
Parses a SassScript expression.
119 120 121 |
# File 'lib/sass/script/parser.rb', line 119
def self.parse(*args)
new(*args).parse
end
|
Instance Method Details
#line ⇒ Fixnum
The line number of the parser's current position.
11 12 13 |
# File 'lib/sass/script/parser.rb', line 11
def line
@lexer.line
end
|
#parse ⇒ Script::Node
Parses a SassScript expression.
48 49 50 51 52 53 54 55 56 |
# File 'lib/sass/script/parser.rb', line 48
def parse
expr = assert_expr :expr
assert_done
expr.options = @options
expr
rescue Sass::SyntaxError => e
e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
raise e
end
|
#parse_interpolated ⇒ Script::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.
34 35 36 37 38 39 40 41 42 |
# File 'lib/sass/script/parser.rb', line 34
def parse_interpolated
expr = assert_expr :expr
assert_tok :end_interpolation
expr.options = @options
expr
rescue Sass::SyntaxError => e
e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
raise e
end
|
#parse_mixin_definition_arglist ⇒ Array<Script::Node>
Parses the argument list for a mixin definition.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/sass/script/parser.rb', line 99
def parse_mixin_definition_arglist
args = defn_arglist!(false)
assert_done
args.each do |k, v|
k.options = @options
v.options = @options if v
end
args
rescue Sass::SyntaxError => e
e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
raise e
end
|
#parse_mixin_include_arglist ⇒ Array<Script::Node>
Parses the argument list for a mixin include.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sass/script/parser.rb', line 79
def parse_mixin_include_arglist
args = []
if try_tok(:lparen)
args = arglist || args
assert_tok(:rparen)
end
assert_done
args.each {|a| a.options = @options}
args
rescue Sass::SyntaxError => e
e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
raise e
end
|
#parse_until(tokens) ⇒ Script::Node
Parses a SassScript expression, ending it when it encounters one of the given identifier tokens.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sass/script/parser.rb', line 64
def parse_until(tokens)
@stop_at = tokens
expr = assert_expr :expr
assert_done
expr.options = @options
expr
rescue Sass::SyntaxError => e
e.modify_backtrace :line => @lexer.line, :filename => @options[:filename]
raise e
end
|