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,
|
||||
'#{' => :begin_interpolation,
|
||||
'}' => :end_interpolation,
|
||||
';' => :semicolon,
|
||||
}
|
||||
|
||||
# A list of operator strings ordered with longer names first
|
||||
|
@ -113,6 +114,12 @@ module Sass
|
|||
@tok ||= read_token
|
||||
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.
|
||||
def done?
|
||||
whitespace unless after_interpolation?
|
||||
|
|
|
@ -42,6 +42,19 @@ module Sass
|
|||
expr
|
||||
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.
|
||||
#
|
||||
# @return [Array<Script::Node>] The root nodes of the arguments.
|
||||
|
|
|
@ -73,6 +73,23 @@ module Sass
|
|||
node
|
||||
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
|
||||
# Many of these operators (all except / and ,)
|
||||
# are disallowed by the CSS spec,
|
||||
|
@ -115,14 +132,18 @@ module Sass
|
|||
# A block may contain declarations and/or rulesets
|
||||
def block_contents(node)
|
||||
block_given? ? yield : ss
|
||||
node << (child = directive || declaration_or_ruleset)
|
||||
node << (child = block_child)
|
||||
while raw(';') || (child && !child.children.empty?)
|
||||
block_given? ? yield : ss
|
||||
node << (child = directive || declaration_or_ruleset)
|
||||
node << (child = block_child)
|
||||
end
|
||||
node
|
||||
end
|
||||
|
||||
def block_child
|
||||
variable || directive || declaration_or_ruleset
|
||||
end
|
||||
|
||||
# This is a nasty hack, and the only place in the parser
|
||||
# that requires backtracking.
|
||||
# The reason is that we can't figure out if certain strings
|
||||
|
@ -324,6 +345,11 @@ module Sass
|
|||
node
|
||||
end
|
||||
|
||||
def sass_script_parser
|
||||
Sass::Script::Parser.new(@scanner, @line,
|
||||
@scanner.pos - @scanner.string.rindex("\n"))
|
||||
end
|
||||
|
||||
EXPR_NAMES = {
|
||||
:medium => "medium (e.g. print, screen)",
|
||||
:pseudo_expr => "expression (e.g. fr, 2n+1)",
|
||||
|
|
Loading…
Add table
Reference in a new issue