Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAneesh Dogra <lionaneesh@gmail.com>2012-12-04 19:05:01 (GMT)
committer Aneesh Dogra <lionaneesh@gmail.com>2012-12-04 19:05:01 (GMT)
commit673ace74e639f19966c73b9b06b17e8c2f05cead (patch)
tree019910110903669575b1a04019cd6b96d67c407c
parentfa0bf8ee2d79bd7ae73410a4de8d051221a02e52 (diff)
Report syntax errors for plot.sugar-0.94
Fix #2466
-rw-r--r--astparser.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/astparser.py b/astparser.py
index 12506eb..f7e5b46 100644
--- a/astparser.py
+++ b/astparser.py
@@ -1,6 +1,7 @@
# -*- coding: UTF-8 -*-
# astparser.py, equation parser based on python Abstract Syntax Trees (ast)
# Reinier Heeres <reinier@heeres.eu>
+# Copyright (C) 2012 Aneesh Dogra <lionaneesh@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -73,6 +74,22 @@ class ParseError(ParserError):
msg += ": %s" % (self._msg)
return msg
+class WrongSyntaxError(ParserError):
+ """Class for reporting syntax errors."""
+
+ def __init__(self, module=None, helper=None, start=0, end=0):
+ ParserError.__init__(self,_("Syntax Error."), start, end)
+ if module != None and helper != None:
+ self.help_text = helper.get_help(module)
+ else:
+ self.help_text = None
+
+ def __str__(self):
+ msg = _("Syntax Error!")
+ if self.help_text is not None and len(self.help_text) > 0:
+ msg += "\n" + self.help_text
+ return msg
+
class RuntimeError(ParserError):
"""Class for error during executing."""
@@ -593,8 +610,15 @@ class AstParser:
try:
tree = compile(eqn, '<string>', 'exec', ast.PyCF_ONLY_AST)
except SyntaxError, e:
- msg = _('Parse error')
- raise ParseError(msg, e.offset - 1)
+ # if we don't have an offset, its a SyntaxError
+ if e.offset == None:
+ if eqn.startswith('plot'):
+ raise WrongSyntaxError('plot', self._helper, len(eqn),
+ len(eqn) + len("Syntax Error!"))
+ else:
+ raise WrongSyntaxError()
+ else:
+ raise ParseError(msg, e.offset - 1)
if isinstance(tree, ast.Module):
if len(tree.body) != 1: