diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-07-31 18:59:05 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2013-07-31 18:59:05 -0700 |
commit | 3f75ec2517e9b1a2a900406d8b0bce06b7ab29ac (patch) | |
tree | 989ad58d036a1b5193e3770f361f4dd02910d799 /scss/src | |
parent | a28c9cf51625877643b761b47090ba8e5047067d (diff) | |
download | pyscss-3f75ec2517e9b1a2a900406d8b0bce06b7ab29ac.tar.gz |
Some parser fixes. Allow arbitrary units.
The C-based scanner ignored restriction lists due to only accepting
tuples and lists, whereas yapps usually passes in sets. It should now
be in line with the Python scanner.
Also, it turns out that variables in functions could cause parse errors
that were being ignored; this is now fixed.
Diffstat (limited to 'scss/src')
-rw-r--r-- | scss/src/_speedups.c | 14 | ||||
-rw-r--r-- | scss/src/grammar/grammar.g | 5 | ||||
-rw-r--r-- | scss/src/grammar/grammar.py | 5 | ||||
-rw-r--r-- | scss/src/scanner.c | 6 |
4 files changed, 15 insertions, 15 deletions
diff --git a/scss/src/_speedups.c b/scss/src/_speedups.c index 67f9676..67e02af 100644 --- a/scss/src/_speedups.c +++ b/scss/src/_speedups.c @@ -161,8 +161,9 @@ scss_Scanner_rewind(scss_Scanner *self, PyObject *args) static PyObject * scss_Scanner_token(scss_Scanner *self, PyObject *args) { + PyObject *iter; PyObject *item; - int i, is_tuple; + int i; long size; Token *p_token; @@ -173,18 +174,19 @@ scss_Scanner_token(scss_Scanner *self, PyObject *args) int restrictions_sz = 0; if (self->scanner != NULL) { if (PyArg_ParseTuple(args, "i|O", &token_num, &restrictions)) { - is_tuple = PyTuple_Check(restrictions); - if (is_tuple || PyList_Check(restrictions)) { - size = is_tuple ? PyTuple_Size(restrictions) : PyList_Size(restrictions); + size = PySequence_Size(restrictions); + if (size != -1) { _restrictions = PyMem_New(Pattern, size); - for (i = 0; i < size; ++i) { - item = is_tuple ? PyTuple_GetItem(restrictions, i) : PyList_GetItem(restrictions, i); + iter = PyObject_GetIter(restrictions); + while (item = PyIter_Next(iter)) { if (PyString_Check(item)) { _restrictions[restrictions_sz].tok = PyString_AsString(item); _restrictions[restrictions_sz].expr = NULL; restrictions_sz++; } + Py_DECREF(item); } + Py_DECREF(iter); } p_token = Scanner_token(self->scanner, token_num, _restrictions, restrictions_sz); diff --git a/scss/src/grammar/grammar.g b/scss/src/grammar/grammar.g index 31363fc..6be39d4 100644 --- a/scss/src/grammar/grammar.g +++ b/scss/src/grammar/grammar.g @@ -1,7 +1,6 @@ # python yapps2.py grammar.g grammar.py ################################################################################ -#'(?<!\\s)(?:' + '|'.join(_units) + ')(?![-\\w])' ## Grammar compiled using Yapps: %% parser SassExpression: @@ -27,7 +26,7 @@ parser SassExpression: token GT: ">" token STR: "'[^']*'" token QSTR: '"[^"]*"' - token UNITS: "(?<!\s)(?:px|cm|mm|hz|%)(?![-\w])" + 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])" token VAR: "\$[-a-zA-Z0-9_]+" @@ -83,7 +82,7 @@ parser SassExpression: argspec {{ v = argspec }} ] RPAR {{ return CallOp(FNCT, v) }} | NUM [ - UNITS {{ return Literal(NumberValue(float(NUM), unit=UNITS)) }} + UNITS {{ return Literal(NumberValue(float(NUM), unit=UNITS.lower())) }} ] {{ return Literal(NumberValue(float(NUM))) }} | STR {{ return Literal(String(STR[1:-1], quotes="'")) }} | QSTR {{ return Literal(String(QSTR[1:-1], quotes='"')) }} diff --git a/scss/src/grammar/grammar.py b/scss/src/grammar/grammar.py index 27e0175..2b736d9 100644 --- a/scss/src/grammar/grammar.py +++ b/scss/src/grammar/grammar.py @@ -1,7 +1,6 @@ # python yapps2.py grammar.g grammar.py ################################################################################ -#'(?<!\\s)(?:' + '|'.join(_units) + ')(?![-\\w])' ## Grammar compiled using Yapps: import re @@ -35,7 +34,7 @@ class SassExpressionScanner(Scanner): ('GT', '>'), ('STR', "'[^']*'"), ('QSTR', '"[^"]*"'), - ('UNITS', '(?<!\\s)(?:px|cm|mm|hz|%)(?![-\\w])'), + ('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])'), ('VAR', '\\$[-a-zA-Z0-9_]+'), @@ -186,7 +185,7 @@ class SassExpression(Parser): NUM = self._scan('NUM') if self._peek(self.atom_rsts_) == 'UNITS': UNITS = self._scan('UNITS') - return Literal(NumberValue(float(NUM), unit=UNITS)) + return Literal(NumberValue(float(NUM), unit=UNITS.lower())) return Literal(NumberValue(float(NUM))) elif _token_ == 'STR': STR = self._scan('STR') diff --git a/scss/src/scanner.c b/scss/src/scanner.c index 1b9f3d7..de0d596 100644 --- a/scss/src/scanner.c +++ b/scss/src/scanner.c @@ -182,7 +182,7 @@ _Scanner_scan(Scanner *self, Pattern *restrictions, int restrictions_sz) if (skip) { max = (restrictions_sz > self->ignore_sz) ? restrictions_sz : self->ignore_sz; for (k = 0; k < max; k++) { - if (k < restrictions_sz && regex == Pattern_regex(restrictions[k].tok, restrictions[k].expr)) { + if (k < restrictions_sz && strcmp(regex->tok, restrictions[k].tok) == 0) { skip = 0; break; } @@ -255,7 +255,7 @@ _Scanner_scan(Scanner *self, Pattern *restrictions, int restrictions_sz) p_restriction->patterns = PyMem_New(Pattern *, restrictions_sz); p_restriction->patterns_sz = 0; for (j = 0; j < restrictions_sz; j++) { - regex = Pattern_regex(restrictions[k].tok, restrictions[k].expr); + regex = Pattern_regex(restrictions[j].tok, restrictions[j].expr); if (regex) { p_restriction->patterns[p_restriction->patterns_sz++] = regex; } @@ -416,7 +416,7 @@ Scanner_token(Scanner *self, int i, Pattern restrictions[], int restrictions_sz) found = 0; for (k = 0; k < self->restrictions[i].patterns_sz; k++) { regex = Pattern_regex(restrictions[j].tok, restrictions[j].expr); - if (regex == self->restrictions[i].patterns[k]) { + if (strcmp(restrictions[j].tok, self->restrictions[i].patterns[k]->tok) == 0) { found = 1; break; } |