summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scss/ast.py17
-rw-r--r--scss/grammar/expression.g5
-rw-r--r--scss/grammar/expression.py5
3 files changed, 23 insertions, 4 deletions
diff --git a/scss/ast.py b/scss/ast.py
index 80d9b34..90cf76a 100644
--- a/scss/ast.py
+++ b/scss/ast.py
@@ -507,3 +507,20 @@ class FunctionLiteral(Expression):
contents = child.render()
quotes = None
return Function(contents, self.function_name, quotes=quotes)
+
+
+class AlphaFunctionLiteral(Expression):
+ """Wraps an existing AST node in a literal (unevaluated) function call,
+ prepending "opacity=" to the contents.
+ """
+ def __init__(self, child):
+ self.child = child
+
+ def evaluate(self, calculator, divide=False):
+ child = self.child.evaluate(calculator, divide)
+ if isinstance(child, String):
+ contents = child.value
+ else:
+ # TODO compress
+ contents = child.render()
+ return Function('opacity=' + contents, 'alpha', quotes=None)
diff --git a/scss/grammar/expression.g b/scss/grammar/expression.g
index 6a708e3..7e8be27 100644
--- a/scss/grammar/expression.g
+++ b/scss/grammar/expression.g
@@ -25,6 +25,7 @@ from scss.ast import ListLiteral
from scss.ast import MapLiteral
from scss.ast import ArgspecLiteral
from scss.ast import FunctionLiteral
+from scss.ast import AlphaFunctionLiteral
from scss.cssdefs import unescape
from scss.types import Color
from scss.types import Function
@@ -239,8 +240,8 @@ parser SassExpression:
# filter syntax, where it appears as alpha(opacity=NN). Since = isn't
# normally valid Sass, we have to special-case it here
| ALPHA_FUNCTION LPAR (
- "opacity" "=" NUM RPAR
- {{ return FunctionLiteral(Literal(String.unquoted("opacity=" + NUM)), "alpha") }}
+ "opacity" "=" atom RPAR
+ {{ return AlphaFunctionLiteral(atom) }}
| argspec RPAR {{ return CallOp("alpha", argspec) }}
)
| LITERAL_FUNCTION LPAR interpolated_function RPAR
diff --git a/scss/grammar/expression.py b/scss/grammar/expression.py
index 282047e..71da2b9 100644
--- a/scss/grammar/expression.py
+++ b/scss/grammar/expression.py
@@ -25,6 +25,7 @@ from scss.ast import ListLiteral
from scss.ast import MapLiteral
from scss.ast import ArgspecLiteral
from scss.ast import FunctionLiteral
+from scss.ast import AlphaFunctionLiteral
from scss.cssdefs import unescape
from scss.types import Color
from scss.types import Function
@@ -334,9 +335,9 @@ class SassExpression(Parser):
if _token_ == '"opacity"':
self._scan('"opacity"')
self._scan('"="')
- NUM = self._scan('NUM')
+ atom = self.atom()
RPAR = self._scan('RPAR')
- return FunctionLiteral(Literal(String.unquoted("opacity=" + NUM)), "alpha")
+ return AlphaFunctionLiteral(atom)
else: # in self.atom_chks
argspec = self.argspec()
RPAR = self._scan('RPAR')