1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] [SCSS] Add support for @for.

This commit is contained in:
Nathan Weizenbaum 2009-12-21 22:40:03 -08:00
parent 01494e94ab
commit b3d72dbf37
3 changed files with 38 additions and 2 deletions

View file

@ -44,6 +44,8 @@ module Sass
'#{' => :begin_interpolation, '#{' => :begin_interpolation,
'}' => :end_interpolation, '}' => :end_interpolation,
';' => :semicolon, ';' => :semicolon,
'{' => :lcurly,
'}' => :rcurly,
} }
# A list of operator strings ordered with longer names first # A list of operator strings ordered with longer names first

View file

@ -42,6 +42,20 @@ module Sass
expr expr
end end
# Parses a SassScript expression,
# ending it when it encounters one of the givne identifier tokens.
#
# @param [#include?(String)] A set of strings that delimit the expression.
# @return [Script::Node] The root node of the parse tree
# @raise [Sass::SyntaxError] if the expression isn't valid SassScript
def parse_until(tokens)
@stop_at = tokens
expr = assert_expr :expr
assert_done
expr.options = @options
expr
end
# Parses the argument list for a mixin include. # Parses the argument list for a mixin include.
# #
# @return [Array<Script::Node>] The root nodes of the arguments. # @return [Array<Script::Node>] The root nodes of the arguments.
@ -142,7 +156,10 @@ RUBY
unary :not, :funcall unary :not, :funcall
def funcall def funcall
return paren unless name = try_tok(:ident) return paren unless @lexer.peek.type == :ident
return if @stop_at && @stop_at.include?(@lexer.peek.value)
name = @lexer.next
# An identifier without arguments is just a string # An identifier without arguments is just a string
unless try_tok(:lparen) unless try_tok(:lparen)
filename = @options[:filename] filename = @options[:filename]

View file

@ -36,7 +36,7 @@ module Sass
true true
end end
DIRECTIVES = Set[:mixin, :include, :debug] DIRECTIVES = Set[:mixin, :include, :debug, :for]
def directive def directive
return unless name = tok(ATRULE) return unless name = tok(ATRULE)
@ -80,6 +80,23 @@ module Sass
node(Sass::Tree::DebugNode.new(sass_script_parser.parse)) node(Sass::Tree::DebugNode.new(sass_script_parser.parse))
end end
def for
raw! '!'
var = tok! IDENT
ss
raw! 'from'
from = sass_script_parser.parse_until Set["to", "through"]
ss
@expected = '"to" or "through"'
exclusive = (raw('to') || raw!('through')) == 'to'
to = sass_script_parser.parse
ss
block(node(Sass::Tree::ForNode.new(var, from, to, exclusive)))
end
def variable def variable
return unless raw '!' return unless raw '!'
name = tok! IDENT name = tok! IDENT