ClassDefinition GetClassDefinition(string code) { PythonParser parser = new PythonParser(); PythonAst ast = parser.CreateAst(@"test.py", new StringTextBuffer(code)); SuiteStatement suite = ast.Body as SuiteStatement; return suite.Statements[0] as ClassDefinition; }
static Statement GetFirstStatement(string code) { PythonParser parser = new PythonParser(); PythonAst ast = parser.CreateAst(@"snippet.py", new StringTextBuffer(code)); SuiteStatement suiteStatement = (SuiteStatement)ast.Body; return suiteStatement.Statements[0]; }
/// <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 code) { if (code != null) { PythonParser parser = new PythonParser(); PythonAst ast = parser.CreateAst("resolver.py", code); return Resolve(variableName, ast); } return null; }
/// <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 code) { if (code != null) { PythonParser parser = new PythonParser(); PythonAst ast = parser.CreateAst("resolver.py", code); return(Resolve(variableName, ast)); } return(null); }
/// <summary> /// Creates a control either a UserControl or Form from the python code. /// </summary> public IComponent CreateComponent(string pythonCode) { PythonParser parser = new PythonParser(); PythonAst ast = parser.CreateAst(@"Control.py", new StringTextBuffer(pythonCode)); ast.Walk(this); // Did we find the InitializeComponent method? if (!FoundInitializeComponentMethod) { throw new PythonComponentWalkerException("Unable to find InitializeComponents method."); } return component; }
/// <summary> /// Creates a control either a UserControl or Form from the python code. /// </summary> public IComponent CreateComponent(string pythonCode) { PythonParser parser = new PythonParser(); PythonAst ast = parser.CreateAst(@"Control.py", new StringTextBuffer(pythonCode)); ast.Walk(this); // Did we find the InitializeComponent method? if (component == null) { throw new PythonComponentWalkerException("Unable to find InitializeComponents method."); } return(component); }
public void CreateAstShouldNotThrowInvalidCastException() { PythonParser parser = new PythonParser(); PythonAst ast = parser.CreateAst(@"d:\projects\test\test.py", new StringTextBuffer(code)); }