コード例 #1
0
		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;
		}
コード例 #2
0
		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];
		}
コード例 #3
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;
		}
コード例 #4
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);
 }
コード例 #5
0
		/// <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;
		}
コード例 #6
0
        /// <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);
        }
コード例 #7
0
		public void CreateAstShouldNotThrowInvalidCastException()
		{
			PythonParser parser = new PythonParser();
			PythonAst ast = parser.CreateAst(@"d:\projects\test\test.py", new StringTextBuffer(code));
		}