summaryrefslogtreecommitdiff
path: root/scss/grammar
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <eevee.git@veekun.com>2014-09-01 21:20:27 -0700
committerEevee (Alex Munroe) <eevee.git@veekun.com>2014-09-01 21:20:27 -0700
commit3de66863bbca766c05b4b97a9621b854412ae3b3 (patch)
treefb709ce97d27ab6d2f504b965ccc684768c551ef /scss/grammar
parent66caf45e0b152c14bcec5a24e5a31ca75fe4ea73 (diff)
downloadpyscss-3de66863bbca766c05b4b97a9621b854412ae3b3.tar.gz
Fix a couple bugs with interpolation.
- Sometimes whitespace could be lost after an interpolation. - Null wasn't being correctly interpolated as empty string. - Removing String.__str__ revealed a tiny bug in apply_vars.
Diffstat (limited to 'scss/grammar')
-rw-r--r--scss/grammar/expression.g13
-rw-r--r--scss/grammar/expression.py6
-rw-r--r--scss/grammar/scanner.py3
3 files changed, 13 insertions, 9 deletions
diff --git a/scss/grammar/expression.g b/scss/grammar/expression.g
index 026f07a..df4d7e0 100644
--- a/scss/grammar/expression.g
+++ b/scss/grammar/expression.g
@@ -38,6 +38,12 @@ from scss.grammar import Scanner
%%
parser SassExpression:
+ # These need to go before the ignore, so they match first, and we don't
+ # lose spaces inside a string!
+ # Don't allow quotes or # unless they're escaped (or the # is alone)
+ token SINGLE_STRING_GUTS: '([^\'\\\\#]|[\\\\].|#(?![{]))*'
+ token DOUBLE_STRING_GUTS: "([^\"\\\\#]|[\\\\].|#(?![{]))*"
+
ignore: "[ \r\t\n]+"
token LPAR: "\\(|\\["
token RPAR: "\\)|\\]"
@@ -60,11 +66,7 @@ parser SassExpression:
token DOTDOTDOT: '[.]{3}'
token SINGLE_QUOTE: "'"
token DOUBLE_QUOTE: '"'
- # Don't allow quotes or # unless they're escaped (or the # is alone)
- token SINGLE_STRING_GUTS: '([^\'\\\\#]|[\\\\].|#(?![{]))*'
- token DOUBLE_STRING_GUTS: "([^\"\\\\#]|[\\\\].|#(?![{]))*"
- token STR: "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'"
- token QSTR: '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'
+
token UNITS: "(?<!\s)(?:[a-zA-Z]+|%)(?![-\w])"
token NUM: "(?:\d+(?:\.\d*)?|\.\d+)"
token COLOR: "#(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3})(?![a-fA-F0-9])"
@@ -92,6 +94,7 @@ parser SassExpression:
# FIXME: Also, URLs may not contain $ as it breaks urls with variables?
token BAREURL: "(?:[\\\\].|[^#$'\"()\\x00-\\x08\\x0b\\x0e-\\x1f\\x7f]|#(?![{]))*"
+ # -------------------------------------------------------------------------
# Goals:
rule goal: expr_lst END {{ return expr_lst }}
diff --git a/scss/grammar/expression.py b/scss/grammar/expression.py
index 397fa4c..cf3c9e7 100644
--- a/scss/grammar/expression.py
+++ b/scss/grammar/expression.py
@@ -42,6 +42,8 @@ class SassExpressionScanner(Scanner):
_patterns = [
('":"', ':'),
('","', ','),
+ ('SINGLE_STRING_GUTS', "([^'\\\\#]|[\\\\].|#(?![{]))*"),
+ ('DOUBLE_STRING_GUTS', '([^"\\\\#]|[\\\\].|#(?![{]))*'),
('[ \r\t\n]+', '[ \r\t\n]+'),
('LPAR', '\\(|\\['),
('RPAR', '\\)|\\]'),
@@ -64,10 +66,6 @@ class SassExpressionScanner(Scanner):
('DOTDOTDOT', '[.]{3}'),
('SINGLE_QUOTE', "'"),
('DOUBLE_QUOTE', '"'),
- ('SINGLE_STRING_GUTS', "([^'\\\\#]|[\\\\].|#(?![{]))*"),
- ('DOUBLE_STRING_GUTS', '([^"\\\\#]|[\\\\].|#(?![{]))*'),
- ('STR', "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'"),
- ('QSTR', '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'),
('UNITS', '(?<!\\s)(?:[a-zA-Z]+|%)(?![-\\w])'),
('NUM', '(?:\\d+(?:\\.\\d*)?|\\.\\d+)'),
('COLOR', '#(?:[a-fA-F0-9]{6}|[a-fA-F0-9]{3})(?![a-fA-F0-9])'),
diff --git a/scss/grammar/scanner.py b/scss/grammar/scanner.py
index 8e48d2b..5aee227 100644
--- a/scss/grammar/scanner.py
+++ b/scss/grammar/scanner.py
@@ -206,6 +206,9 @@ except ImportError:
and add the restriction to self.restrictions
"""
# Keep looking for a token, ignoring any in self.ignore
+ if DEBUG:
+ print()
+ print("Being asked to match with restriction:", repr(restrict))
token = None
while True:
best_pat = None