mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Sass] [SCSS] Add support for declaring variables.
No way to use them as of yet.
This commit is contained in:
parent
11bd2274b7
commit
6b1c52ac63
3 changed files with 48 additions and 2 deletions
|
@ -43,6 +43,7 @@ module Sass
|
||||||
'<' => :lt,
|
'<' => :lt,
|
||||||
'#{' => :begin_interpolation,
|
'#{' => :begin_interpolation,
|
||||||
'}' => :end_interpolation,
|
'}' => :end_interpolation,
|
||||||
|
';' => :semicolon,
|
||||||
}
|
}
|
||||||
|
|
||||||
# A list of operator strings ordered with longer names first
|
# A list of operator strings ordered with longer names first
|
||||||
|
@ -113,6 +114,12 @@ module Sass
|
||||||
@tok ||= read_token
|
@tok ||= read_token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Rewinds the underlying StringScanner
|
||||||
|
# to before the token returned by \{#peek}.
|
||||||
|
def unpeek!
|
||||||
|
@scanner.pos -= @scanner.matched_size if @tok
|
||||||
|
end
|
||||||
|
|
||||||
# @return [Boolean] Whether or not there's more source text to lex.
|
# @return [Boolean] Whether or not there's more source text to lex.
|
||||||
def done?
|
def done?
|
||||||
whitespace unless after_interpolation?
|
whitespace unless after_interpolation?
|
||||||
|
|
|
@ -42,6 +42,19 @@ module Sass
|
||||||
expr
|
expr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Parses a single SassScript expression.
|
||||||
|
# Unlike \{#parse}, doesn't expect this expression
|
||||||
|
# to consume the entire input stream.
|
||||||
|
#
|
||||||
|
# @return [Script::Node] The root node of the parse tree
|
||||||
|
# @raise [Sass::SyntaxError] if the expression isn't valid SassScript
|
||||||
|
def parse_some
|
||||||
|
expr = assert_expr :expr
|
||||||
|
expr.options = @options
|
||||||
|
@lexer.unpeek!
|
||||||
|
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.
|
||||||
|
|
|
@ -73,6 +73,23 @@ module Sass
|
||||||
node
|
node
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def variable
|
||||||
|
return unless raw '!'
|
||||||
|
name = tok! IDENT
|
||||||
|
ss
|
||||||
|
|
||||||
|
if raw '|'
|
||||||
|
raw! '|'
|
||||||
|
guarded = true
|
||||||
|
end
|
||||||
|
|
||||||
|
raw! '='
|
||||||
|
ss
|
||||||
|
expr = sass_script_parser.parse_some
|
||||||
|
|
||||||
|
node(Sass::Tree::VariableNode.new(name, expr, guarded))
|
||||||
|
end
|
||||||
|
|
||||||
def operator
|
def operator
|
||||||
# Many of these operators (all except / and ,)
|
# Many of these operators (all except / and ,)
|
||||||
# are disallowed by the CSS spec,
|
# are disallowed by the CSS spec,
|
||||||
|
@ -115,14 +132,18 @@ module Sass
|
||||||
# A block may contain declarations and/or rulesets
|
# A block may contain declarations and/or rulesets
|
||||||
def block_contents(node)
|
def block_contents(node)
|
||||||
block_given? ? yield : ss
|
block_given? ? yield : ss
|
||||||
node << (child = directive || declaration_or_ruleset)
|
node << (child = block_child)
|
||||||
while raw(';') || (child && !child.children.empty?)
|
while raw(';') || (child && !child.children.empty?)
|
||||||
block_given? ? yield : ss
|
block_given? ? yield : ss
|
||||||
node << (child = directive || declaration_or_ruleset)
|
node << (child = block_child)
|
||||||
end
|
end
|
||||||
node
|
node
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def block_child
|
||||||
|
variable || directive || declaration_or_ruleset
|
||||||
|
end
|
||||||
|
|
||||||
# This is a nasty hack, and the only place in the parser
|
# This is a nasty hack, and the only place in the parser
|
||||||
# that requires backtracking.
|
# that requires backtracking.
|
||||||
# The reason is that we can't figure out if certain strings
|
# The reason is that we can't figure out if certain strings
|
||||||
|
@ -324,6 +345,11 @@ module Sass
|
||||||
node
|
node
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sass_script_parser
|
||||||
|
Sass::Script::Parser.new(@scanner, @line,
|
||||||
|
@scanner.pos - @scanner.string.rindex("\n"))
|
||||||
|
end
|
||||||
|
|
||||||
EXPR_NAMES = {
|
EXPR_NAMES = {
|
||||||
:medium => "medium (e.g. print, screen)",
|
:medium => "medium (e.g. print, screen)",
|
||||||
:pseudo_expr => "expression (e.g. fr, 2n+1)",
|
:pseudo_expr => "expression (e.g. fr, 2n+1)",
|
||||||
|
|
Loading…
Add table
Reference in a new issue