Пример #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()
Пример #2
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