예제 #1
0
        private static PythonModule GenerateModuleAsSnippets(SystemState state, CompilerContext context, Stmt body, string moduleName)
        {
            SuiteStmt           suite = body as SuiteStmt;
            SnippetModuleRunner smr   = new SnippetModuleRunner(moduleName, state);

            Debug.Assert(suite != null, "invalid statement");

            //  Convert document string into assignment
            if (suite.stmts.Length > 0)
            {
                ExprStmt es = suite.stmts[0] as ExprStmt;
                if (es != null)
                {
                    ConstantExpr ce = es.expr as ConstantExpr;
                    if (ce != null && ce.value is string)
                    {
                        suite.stmts[0] = new AssignStmt(new Expr[] { new NameExpr(Name.Make("__doc__")) }, ce);
                    }
                }
            }

            foreach (Stmt stmt in suite.stmts)
            {
                // GenerateSnippet will do the binding
                smr.AddSnippet(GenerateSnippet(context, stmt, moduleName, true));
            }
            return(smr.Module);
        }
예제 #2
0
 public override string GetDocString()
 {
     if (stmts.Length > 0 && stmts[0] is ExprStmt)
     {
         ExprStmt es = (ExprStmt)stmts[0];
         if (es.expr is ConstantExpr)
         {
             object val = ((ConstantExpr)es.expr).value;
             if (val is string && !Options.StripDocStrings)
             {
                 return((string)val);
             }
         }
     }
     return(null);
 }
예제 #3
0
 // ExprStmt
 public virtual bool Walk(ExprStmt node)
 {
     return(false);
 }
예제 #4
0
 public virtual void PostWalk(ExprStmt node)
 {
 }
예제 #5
0
 // ExprStmt
 public virtual bool Walk(ExprStmt node)
 {
     return(true);
 }