Ejemplo n.º 1
0
 def CreateASTFromFile(self, fileName):
     completeCode = self.engine.CreateScriptSourceFromFile(fileName)
     sourceUnit = HostingHelpers.GetSourceUnit(completeCode)
     cc = CompilerContext(sourceUnit, PythonCompilerOptions(),
                          ErrorSink.Default)
     parser = Parser.CreateParser(cc, PythonOptions())
     return parser.ParseFile(False), sourceUnit.GetCode()
Ejemplo n.º 2
0
def parse(buf, mode='exec'):
    context = CompilerContext()
    parser = Parser.FromString(sys, context, buf)
    node = parser.ParseFileInput()
    tree = Transformer().parsefile(node)
    walk(tree, FlattenVisitor())
    return tree
Ejemplo n.º 3
0
        def parse_text(text):
            errorSink = MyErrorSink()
            sourceUnit = SourceUnit(
                clr.GetCurrentRuntime().GetLanguageByName('python'),
                MyTextContentProvider(text), 'foo', SourceCodeKind.File)

            parser = Parser.CreateParser(
                CompilerContext(sourceUnit, PythonCompilerOptions(),
                                errorSink), PythonOptions())
            parser.ParseFile(True)
            return errorSink