From bb173d58ace600519d8167dc89a2b63a433651ea Mon Sep 17 00:00:00 2001 From: "German M. Bravo" Date: Wed, 14 Aug 2013 13:50:02 -0500 Subject: Scanner in sync with C code and test scanner.py --- scss/_native.py | 10 +++++++--- 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 -- cgit v1.2.1