public void AddInvalidSourceSpan()
		{
			IronPython.Hosting.Python.CreateEngine();
			PythonCompilerSink sink = new PythonCompilerSink();
			SourceUnit source = DefaultContext.DefaultPythonContext.CreateSourceUnit(NullTextContentProvider.Null, @"D:\test.py", SourceCodeKind.InteractiveCode);
			sink.Add(source, "Test", SourceSpan.Invalid, 1000, Severity.FatalError);
		}
		void CreateTokenizer(SourceUnit source)
		{
			PythonCompilerSink sink = new PythonCompilerSink();
			PythonCompilerOptions options = new PythonCompilerOptions();
			
			tokenizer = new Tokenizer(sink, options);
			tokenizer.Initialize(source);
		}
        void CreateTokenizer(SourceUnit source)
        {
            PythonCompilerSink    sink    = new PythonCompilerSink();
            PythonCompilerOptions options = new PythonCompilerOptions();

            tokenizer = new Tokenizer(sink, options);
            tokenizer.Initialize(source);
        }
        /// <summary>
        /// Resolves the type of the variable name specified.
        /// </summary>
        /// <param name="variableName">Name of the variable.</param>
        /// <param name="code">The python code containing the variable.</param>
        public string Resolve(string variableName, string fileName, string code)
        {
            if (code != null)
            {
                ScriptEngine       scriptEngine = IronPython.Hosting.Python.CreateEngine();
                PythonCompilerSink sink         = new PythonCompilerSink();
                SourceUnit         source       = DefaultContext.DefaultPythonContext.CreateFileUnit(fileName, code);
                CompilerContext    context      = new CompilerContext(source, new PythonCompilerOptions(), sink);
                Parser             parser       = Parser.CreateParser(context, new PythonOptions());
                PythonAst          ast          = parser.ParseFile(false);

                return(Resolve(variableName, ast));
            }
            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Parses a python file and creates a PythonAst.
        /// </summary>
        public PythonAst CreateAst(string fileName, string fileContent)
        {
            if (scriptEngine == null)
            {
                scriptEngine = IronPython.Hosting.Python.CreateEngine();
            }

            PythonCompilerSink sink    = new PythonCompilerSink();
            SourceUnit         source  = DefaultContext.DefaultPythonContext.CreateFileUnit(fileName, fileContent);
            CompilerContext    context = new CompilerContext(source, new PythonCompilerOptions(), sink);

            using (Parser parser = Parser.CreateParser(context, new PythonOptions())) {
                return(parser.ParseFile(false));
            }
        }
Beispiel #6
0
		void RunAstWalkerButtonClick(object sender, EventArgs e)
		{
			try {
				IronPython.Hosting.Python.CreateEngine();
				Clear();
				PythonCompilerSink sink = new PythonCompilerSink();
				SourceUnit source = DefaultContext.DefaultPythonContext.CreateFileUnit(@"D:\Temp.py", codeTextBox.Text);
				CompilerContext context = new CompilerContext(source, new PythonCompilerOptions(), sink);
				Parser parser = Parser.CreateParser(context, new PythonOptions());
				PythonAst ast = parser.ParseFile(false);
				if (sink.Errors.Count == 0) {
					ResolveWalker walker = new ResolveWalker(this);
					ast.Walk(walker);
				} else {
					walkerOutputTextBox.Text += "\r\n";
					foreach (PythonCompilerError error in sink.Errors) {
						walkerOutputTextBox.Text += error.ToString() + "\r\n";
					}
				}
			} catch (Exception ex) {
				walkerOutputTextBox.Text = ex.ToString();
			}
		}