Class: Sass::Script::Parser
Overview
The parser for SassScript. It parses a string of code into a tree of Nodes.
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.
-
#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.
Constructor Details
#initialize(str, line, offset, options = {}) ⇒ Parser
Returns a new instance of Parser.
15 16 17 18 |
# File 'lib/sass/script/parser.rb', line 15
def initialize(str, line, offset, options = {})
@options = options
@lexer = Lexer.new(str, line, offset, options)
end
|
Class Method Details
.parse(str, line, offset, filename = nil) ⇒ Script::Node
Parses a SassScript expression.
88 89 90 |
# File 'lib/sass/script/parser.rb', line 88
def self.parse(*args)
new(*args).parse
end
|
Instance Method Details
#parse ⇒ Script::Node
Parses a SassScript expression.
38 39 40 41 42 43 |
# File 'lib/sass/script/parser.rb', line 38
def parse
expr = assert_expr :expr
assert_done
expr.options = @options
expr
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.
27 28 29 30 31 32 |
# File 'lib/sass/script/parser.rb', line 27
def parse_interpolated
expr = assert_expr :expr
assert_tok :end_interpolation
expr.options = @options
expr
end
|
#parse_mixin_definition_arglist ⇒ Array<Script::Node>
Parses the argument list for a mixin definition.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sass/script/parser.rb', line 66
def parse_mixin_definition_arglist
args = []
if try_tok(:lparen)
args = defn_arglist(false) || args
assert_tok(:rparen)
end
assert_done
args.each do |k, v|
k.options = @options
v.options = @options if v
end
args
end
|
#parse_mixin_include_arglist ⇒ Array<Script::Node>
Parses the argument list for a mixin include.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sass/script/parser.rb', line 49
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
end
|