lib/sass/script/parser.rb in sass-3.3.0.alpha.231 vs lib/sass/script/parser.rb in sass-3.3.0.alpha.243

- old
+ new

@@ -251,15 +251,38 @@ end # @private def lexer_class; Lexer; end + def map + start_pos = source_position + return unless e = interpolation + return list e, start_pos unless @lexer.peek && @lexer.peek.type == :colon + + key, value = map_pair(e) + map = node(Sass::Script::Tree::MapLiteral.new([[key, value]]), start_pos) + while tok = try_tok(:comma) + key, value = assert_expr(:map_pair) + map.pairs << [key, value] + end + map + end + + def map_pair(key=nil) + return unless key ||= interpolation + assert_tok :colon + return key, assert_expr(:interpolation) + end + def expr - interp = try_ops_after_interp([:comma], :expr) and return interp start_pos = source_position return unless e = interpolation - list = node(Sass::Script::Tree::ListLiteral.new([e], :comma), start_pos) + list e, start_pos + end + + def list(first, start_pos) + list = node(Sass::Script::Tree::ListLiteral.new([first], :comma), start_pos) while tok = try_tok(:comma) if interp = try_op_before_interp(tok, list) return interp unless other_interp = try_ops_after_interp([:comma], :expr, interp) return other_interp end @@ -445,14 +468,14 @@ def paren return variable unless try_tok(:lparen) was_in_parens = @in_parens @in_parens = true start_pos = source_position - e = expr + e = map end_pos = source_position assert_tok(:rparen) - return e || node(Sass::Script::Tree::ListLiteral.new([], :space), start_pos, end_pos) + return e || node(Sass::Script::Tree::ListLiteral.new([], nil), start_pos, end_pos) ensure @in_parens = was_in_parens end def variable @@ -500,10 +523,10 @@ (t = try_tok(*names)) && (return t) @lexer.expected!(names.map {|tok| Lexer::TOKEN_NAMES[tok] || tok}.join(" or ")) end def try_tok(*names) - peeked = @lexer.peek + peeked = @lexer.peek peeked && names.include?(peeked.type) && @lexer.next end def assert_done return if @lexer.done?