summaryrefslogtreecommitdiff
path: root/scss/errors.py
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <eevee.git@veekun.com>2014-09-02 19:29:55 -0700
committerEevee (Alex Munroe) <eevee.git@veekun.com>2014-09-02 19:29:55 -0700
commit16bcfbbac6da460faaaa6ebc9cfaf75a3aa8aa78 (patch)
treec2b516819c972d3a178b343d4b849c9db151fe10 /scss/errors.py
parentd5c7a81a47acdff00cd553bb42bc07b128fa9fe4 (diff)
downloadpyscss-16bcfbbac6da460faaaa6ebc9cfaf75a3aa8aa78.tar.gz
Make scanner errors slightly more friendly to read.
Diffstat (limited to 'scss/errors.py')
-rw-r--r--scss/errors.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/scss/errors.py b/scss/errors.py
index 8be3019..8ab5652 100644
--- a/scss/errors.py
+++ b/scss/errors.py
@@ -107,6 +107,41 @@ class SassBaseError(Exception):
)
+class SassSyntaxError(SassBaseError):
+ """Generic syntax error thrown by the guts of the expression parser;
+ usually caught and wrapped later on.
+ """
+ def __init__(self, input_string, position, desired_tokens):
+ self.input_string = input_string
+ self.position = position
+ self.desired_tokens = desired_tokens
+
+ def __str__(self):
+ if self.position == 0:
+ after = "Syntax error"
+ else:
+ after = "Syntax error after {0!r}".format(
+ self.input_string[max(0, self.position - 20):self.position])
+
+ found = "Found {0!r}".format(
+ self.input_string[self.position:self.position + 10])
+
+ if not self.desired_tokens:
+ expected = "but can't figure out what that means"
+ elif len(self.desired_tokens) == 1:
+ expected = "but expected {0}".format(
+ ''.join(self.desired_tokens))
+ else:
+ expected = "but expected one of {0}".format(
+ ', '.join(sorted(self.desired_tokens)))
+
+ return "{after}: {found} {expected}".format(
+ after=after,
+ found=found,
+ expected=expected,
+ )
+
+
class SassImportError(SassBaseError):
"""Error raised when unable to resolve an @import."""