404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.222.179.232: ~ $
"""Check for errs in the AST.

The Python parser does not catch all syntax errors.  Others, like
assignments with invalid targets, are caught in the code generation
phase.

The compiler package catches some errors in the transformer module.
But it seems clearer to write checkers that use the AST to detect
errors.
"""

from compiler import ast, walk

def check(tree, multi=None):
    v = SyntaxErrorChecker(multi)
    walk(tree, v)
    return v.errors

class SyntaxErrorChecker:
    """A visitor to find syntax errors in the AST."""

    def __init__(self, multi=None):
        """Create new visitor object.

        If optional argument multi is not None, then print messages
        for each error rather than raising a SyntaxError for the
        first.
        """
        self.multi = multi
        self.errors = 0

    def error(self, node, msg):
        self.errors = self.errors + 1
        if self.multi is not None:
            print "%s:%s: %s" % (node.filename, node.lineno, msg)
        else:
            raise SyntaxError, "%s (%s:%s)" % (msg, node.filename, node.lineno)

    def visitAssign(self, node):
        # the transformer module handles many of these
        pass
##        for target in node.nodes:
##            if isinstance(target, ast.AssList):
##                if target.lineno is None:
##                    target.lineno = node.lineno
##                self.error(target, "can't assign to list comprehension")

Filemanager

Name Type Size Permission Actions
__init__.py File 1023 B 0644
__init__.pyc File 1.27 KB 0644
__init__.pyo File 1.27 KB 0644
ast.py File 36.63 KB 0644
ast.pyc File 70.43 KB 0644
ast.pyo File 70.43 KB 0644
consts.py File 468 B 0644
consts.pyc File 737 B 0644
consts.pyo File 737 B 0644
future.py File 1.85 KB 0644
future.pyc File 2.89 KB 0644
future.pyo File 2.89 KB 0644
misc.py File 1.75 KB 0644
misc.pyc File 3.65 KB 0644
misc.pyo File 3.65 KB 0644
pyassem.py File 23.7 KB 0644
pyassem.pyc File 25.34 KB 0644
pyassem.pyo File 24.78 KB 0644
pycodegen.py File 46.69 KB 0644
pycodegen.pyc File 55.19 KB 0644
pycodegen.pyo File 54.76 KB 0644
symbols.py File 14.15 KB 0644
symbols.pyc File 17.26 KB 0644
symbols.pyo File 17.23 KB 0644
syntax.py File 1.41 KB 0644
syntax.pyc File 1.84 KB 0644
syntax.pyo File 1.84 KB 0644
transformer.py File 51.87 KB 0644
transformer.pyc File 46.53 KB 0644
transformer.pyo File 44.76 KB 0644
visitor.py File 3.8 KB 0644
visitor.pyc File 4.09 KB 0644
visitor.pyo File 4.09 KB 0644