diff options
author | German M. Bravo <german.mb@deipi.com> | 2013-08-14 13:50:02 -0500 |
---|---|---|
committer | German M. Bravo <german.mb@deipi.com> | 2013-08-16 09:59:33 -0500 |
commit | bb173d58ace600519d8167dc89a2b63a433651ea (patch) | |
tree | 85e8714c772da5136dfe2853b0102f3fe99b3bae | |
parent | 044369a595e2bd76fbcbeef484146aa5583e8ac6 (diff) | |
download | pyscss-bb173d58ace600519d8167dc89a2b63a433651ea.tar.gz |
Scanner in sync with C code and test scanner.py
-rw-r--r-- | scss/_native.py | 10 | ||||
-rwxr-xr-x | scss/src/scanner.py | 9 |
2 files changed, 13 insertions, 6 deletions
diff --git a/scss/_native.py b/scss/_native.py index 6d7960f..b6e2b81 100644 --- a/scss/_native.py +++ b/scss/_native.py @@ -136,6 +136,8 @@ def locate_blocks(codestr): ################################################################################ # Parser +DEBUG = False + class NoMoreTokens(Exception): """ @@ -185,6 +187,7 @@ class Scanner(object): # Keep looking for a token, ignoring any in self.ignore token = None while True: + tok = None best_pat = None # Search the patterns for a match, with earlier # tokens in the list having preference @@ -208,9 +211,9 @@ class Scanner(object): # If we didn't find anything, raise an error if best_pat is None: - msg = "Bad Token" + msg = "Bad token: %s" % ("???" if tok is None else repr(tok),) if restrict: - msg = "Trying to find one of " + ", ".join(restrict) + msg = "%s found while trying to find one of the restricted tokens: %s" % ("???" if tok is None else repr(tok), ", ".join(repr(r) for r in restrict)) raise SyntaxError("SyntaxError[@ char %s: %s]" % (repr(self.pos), msg)) # If we found something that isn't to be ignored, return it @@ -246,9 +249,10 @@ class Scanner(object): tokens_len = len(self.tokens) if i == tokens_len: # We are at the end, get the next... tokens_len += self._scan(restrict) - if i < tokens_len: + elif i >= 0 and i < tokens_len: if restrict and self.restrictions[i] and restrict > self.restrictions[i]: raise NotImplementedError("Unimplemented: restriction set changed") + if i >= 0 and i < tokens_len: return self.tokens[i] raise NoMoreTokens diff --git a/scss/src/scanner.py b/scss/src/scanner.py index 6d86d70..fd1da81 100755 --- a/scss/src/scanner.py +++ b/scss/src/scanner.py @@ -41,7 +41,6 @@ def profile(fn): return wrapper -DEBUG = False ################################################################################ # Helpers @@ -82,6 +81,9 @@ PATTERNS = [ ################################################################################ +# Parser +DEBUG = False + class NoMoreTokens(Exception): """ @@ -131,6 +133,7 @@ class Scanner(object): # Keep looking for a token, ignoring any in self.ignore token = None while True: + tok = None best_pat = None # Search the patterns for a match, with earlier # tokens in the list having preference @@ -154,9 +157,9 @@ class Scanner(object): # If we didn't find anything, raise an error if best_pat is None: - msg = "Bad Token" + msg = "Bad token: %s" % ("???" if tok is None else repr(tok),) if restrict: - msg = "Trying to find one of " + ", ".join(restrict) + msg = "%s found while trying to find one of the restricted tokens: %s" % ("???" if tok is None else repr(tok), ", ".join(repr(r) for r in restrict)) raise SyntaxError("SyntaxError[@ char %s: %s]" % (repr(self.pos), msg)) # If we found something that isn't to be ignored, return it |