Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../compiler
File: syntax.py
"""Check for errs in the AST.
[0] Fix | Delete
[1] Fix | Delete
The Python parser does not catch all syntax errors. Others, like
[2] Fix | Delete
assignments with invalid targets, are caught in the code generation
[3] Fix | Delete
phase.
[4] Fix | Delete
[5] Fix | Delete
The compiler package catches some errors in the transformer module.
[6] Fix | Delete
But it seems clearer to write checkers that use the AST to detect
[7] Fix | Delete
errors.
[8] Fix | Delete
"""
[9] Fix | Delete
[10] Fix | Delete
from compiler import ast, walk
[11] Fix | Delete
[12] Fix | Delete
def check(tree, multi=None):
[13] Fix | Delete
v = SyntaxErrorChecker(multi)
[14] Fix | Delete
walk(tree, v)
[15] Fix | Delete
return v.errors
[16] Fix | Delete
[17] Fix | Delete
class SyntaxErrorChecker:
[18] Fix | Delete
"""A visitor to find syntax errors in the AST."""
[19] Fix | Delete
[20] Fix | Delete
def __init__(self, multi=None):
[21] Fix | Delete
"""Create new visitor object.
[22] Fix | Delete
[23] Fix | Delete
If optional argument multi is not None, then print messages
[24] Fix | Delete
for each error rather than raising a SyntaxError for the
[25] Fix | Delete
first.
[26] Fix | Delete
"""
[27] Fix | Delete
self.multi = multi
[28] Fix | Delete
self.errors = 0
[29] Fix | Delete
[30] Fix | Delete
def error(self, node, msg):
[31] Fix | Delete
self.errors = self.errors + 1
[32] Fix | Delete
if self.multi is not None:
[33] Fix | Delete
print "%s:%s: %s" % (node.filename, node.lineno, msg)
[34] Fix | Delete
else:
[35] Fix | Delete
raise SyntaxError, "%s (%s:%s)" % (msg, node.filename, node.lineno)
[36] Fix | Delete
[37] Fix | Delete
def visitAssign(self, node):
[38] Fix | Delete
# the transformer module handles many of these
[39] Fix | Delete
pass
[40] Fix | Delete
## for target in node.nodes:
[41] Fix | Delete
## if isinstance(target, ast.AssList):
[42] Fix | Delete
## if target.lineno is None:
[43] Fix | Delete
## target.lineno = node.lineno
[44] Fix | Delete
## self.error(target, "can't assign to list comprehension")
[45] Fix | Delete
[46] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function