示例#1
0
 public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, NamedBlockAst beginBlock, NamedBlockAst processBlock, NamedBlockAst endBlock, NamedBlockAst dynamicParamBlock) : base(extent)
 {
     if (paramBlock != null)
     {
         this.ParamBlock = paramBlock;
         base.SetParent(paramBlock);
     }
     if (beginBlock != null)
     {
         this.BeginBlock = beginBlock;
         base.SetParent(beginBlock);
     }
     if (processBlock != null)
     {
         this.ProcessBlock = processBlock;
         base.SetParent(processBlock);
     }
     if (endBlock != null)
     {
         this.EndBlock = endBlock;
         base.SetParent(endBlock);
     }
     if (dynamicParamBlock != null)
     {
         this.DynamicParamBlock = dynamicParamBlock;
         base.SetParent(dynamicParamBlock);
     }
 }
示例#2
0
 public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, NamedBlockAst beginBlock, NamedBlockAst processBlock, NamedBlockAst endBlock, NamedBlockAst dynamicParamBlock) : base(extent)
 {
     if (paramBlock != null)
     {
         this.ParamBlock = paramBlock;
         base.SetParent(paramBlock);
     }
     if (beginBlock != null)
     {
         this.BeginBlock = beginBlock;
         base.SetParent(beginBlock);
     }
     if (processBlock != null)
     {
         this.ProcessBlock = processBlock;
         base.SetParent(processBlock);
     }
     if (endBlock != null)
     {
         this.EndBlock = endBlock;
         base.SetParent(endBlock);
     }
     if (dynamicParamBlock != null)
     {
         this.DynamicParamBlock = dynamicParamBlock;
         base.SetParent(dynamicParamBlock);
     }
 }
示例#3
0
 public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, NamedBlockAst beginBlock, NamedBlockAst processBlock, NamedBlockAst endBlock, NamedBlockAst dynamicParamBlock)
     : base(extent)
 {
     this.BeginBlock = beginBlock;
     this.DynamicParamBlock = dynamicParamBlock;
     this.EndBlock = endBlock;
     this.ParamBlock = paramBlock;
     this.ProcessBlock = processBlock;
 }
示例#4
0
 public ScriptBlockAst(IScriptExtent extent, ParamBlockAst paramBlock, NamedBlockAst beginBlock, NamedBlockAst processBlock, NamedBlockAst endBlock, NamedBlockAst dynamicParamBlock)
     : base(extent)
 {
     this.BeginBlock        = beginBlock;
     this.DynamicParamBlock = dynamicParamBlock;
     this.EndBlock          = endBlock;
     this.ParamBlock        = paramBlock;
     this.ProcessBlock      = processBlock;
 }
示例#5
0
    public System.Object VisitNamedBlock(System.Management.Automation.Language.NamedBlockAst namedBlockAst)
    {
        IScriptExtent mappedExtent = MapExtent(namedBlockAst.Extent);

        LinkedList <StatementAst> mappedStatements = new LinkedList <StatementAst>();

        foreach (StatementAst s in namedBlockAst.Statements)
        {
            mappedStatements.AddLast(_VisitStatement(s));
        }
        LinkedList <TrapStatementAst> mappedTraps = new LinkedList <TrapStatementAst>();

        if (namedBlockAst.Traps != null)
        {
            foreach (TrapStatementAst ts in namedBlockAst.Traps)
            {
                mappedTraps.AddLast((TrapStatementAst)VisitTrap(ts));
            }
        }
        // this doesn't really map the statement block
        StatementBlockAst mappedStatementBlock = new StatementBlockAst(mappedExtent, mappedStatements, mappedTraps);

        return(new NamedBlockAst(mappedExtent, namedBlockAst.BlockKind, mappedStatementBlock, namedBlockAst.Unnamed));
    }
示例#6
0
 /// <summary/>
 public virtual AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(AstVisitAction.Continue);
 }
示例#7
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(false);
 }
示例#8
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst ast)
 {
     return(Check(ast));
 }
示例#9
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return false;
 }
示例#10
0
 /// <summary/>
 public virtual AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst) => DefaultVisit(namedBlockAst);
示例#11
0
 public virtual AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return AstVisitAction.Continue;
 }
示例#12
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst ast)
 {
     return this.Check(ast);
 }
 /// <summary/>
 public virtual object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return _decorated.VisitNamedBlock(namedBlockAst);
 }
 public object VisitNamedBlock(NamedBlockAst namedBlockAst) { throw new UnexpectedElementException(); }
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(AstVisitAction.Continue);
 }
示例#16
0
        private ScriptBlockAst NamedBlockListRule(Token lCurly, List<UsingStatementAst> usingStatements, ParamBlockAst paramBlockAst)
        {
            //G  named-block-list:
            //G      named-block
            //G      named-block-list   named-block
            //G  named-block:
            //G      statement-terminators:opt   block-name   statement-block
            //G  block-name:  one of
            //G      'dynamicparam'   'begin'   'process'    'end'

            NamedBlockAst dynamicParamBlock = null;
            NamedBlockAst beginBlock = null;
            NamedBlockAst processBlock = null;
            NamedBlockAst endBlock = null;
            IScriptExtent startExtent = lCurly != null
                                            ? lCurly.Extent
                                            : (paramBlockAst != null) ? paramBlockAst.Extent : null;
            IScriptExtent endExtent = null;
            IScriptExtent extent;

            while (true)
            {
                Token blockNameToken = NextToken();
                switch (blockNameToken.Kind)
                {
                    default:
                        UngetToken(blockNameToken);
                        goto finished_named_block_list;

                    case TokenKind.Dynamicparam:
                    case TokenKind.Begin:
                    case TokenKind.Process:
                    case TokenKind.End:
                        break;
                }

                if (startExtent == null)
                {
                    startExtent = blockNameToken.Extent;
                }
                endExtent = blockNameToken.Extent;

                StatementBlockAst statementBlock = StatementBlockRule();

                if (statementBlock == null)
                {
                    // ErrorRecovery: Eat the block name and keep going, there might be a valid block next.

                    ReportIncompleteInput(After(blockNameToken.Extent),
                        () => ParserStrings.MissingNamedStatementBlock, blockNameToken.Kind.Text());
                    statementBlock = new StatementBlockAst(blockNameToken.Extent, Utils.EmptyArray<StatementAst>(), null);
                }
                else
                {
                    endExtent = statementBlock.Extent;
                }

                extent = ExtentOf(blockNameToken, endExtent);
                if (blockNameToken.Kind == TokenKind.Begin && beginBlock == null)
                {
                    beginBlock = new NamedBlockAst(extent, TokenKind.Begin, statementBlock, false);
                }
                else if (blockNameToken.Kind == TokenKind.Process && processBlock == null)
                {
                    processBlock = new NamedBlockAst(extent, TokenKind.Process, statementBlock, false);
                }
                else if (blockNameToken.Kind == TokenKind.End && endBlock == null)
                {
                    endBlock = new NamedBlockAst(extent, TokenKind.End, statementBlock, false);
                }
                else if (blockNameToken.Kind == TokenKind.Dynamicparam && dynamicParamBlock == null)
                {
                    dynamicParamBlock = new NamedBlockAst(extent, TokenKind.Dynamicparam, statementBlock, false);
                }
                else
                {
                    // ErrorRecovery: this is a semantic error, we can keep parsing w/o trouble.

                    ReportError(extent,
                        () => ParserStrings.DuplicateScriptCommandClause, blockNameToken.Kind.Text());
                }

                SkipNewlinesAndSemicolons();
            }
        finished_named_block_list:

            IScriptExtent scriptBlockExtent;
            extent = ExtentOf(startExtent, endExtent);
            CompleteScriptBlockBody(lCurly, ref extent, out scriptBlockExtent);

            return new ScriptBlockAst(scriptBlockExtent, usingStatements, paramBlockAst, beginBlock, processBlock, endBlock,
                dynamicParamBlock);
        }
示例#17
0
        public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
        {
            Diagnostics.Assert(_allowEnvironmentVariables || FoundError, "VisitScriptBlock should have already reported an error");

            return AstVisitAction.Continue;
        }
示例#18
0
        public override AstVisitAction VisitConfigurationDefinition(ConfigurationDefinitionAst configurationDefinitionAst)
        {
            //
            // Check if the ScriptBlockAst contains NamedBlockAst other than the End block
            //
            ScriptBlockAst configBody = configurationDefinitionAst.Body.ScriptBlock;
            if (configBody.BeginBlock != null || configBody.ProcessBlock != null || configBody.DynamicParamBlock != null)
            {
                var unsupportedNamedBlocks = new NamedBlockAst[] { configBody.BeginBlock, configBody.ProcessBlock, configBody.DynamicParamBlock };
                foreach (NamedBlockAst namedBlock in unsupportedNamedBlocks)
                {
                    if (namedBlock != null)
                    {
                        _parser.ReportError(namedBlock.OpenCurlyExtent, () => ParserStrings.UnsupportedNamedBlockInConfiguration);
                    }
                }

                // ToRemove: No need to continue the parsing if there is no EndBlock, check if (configBody.EndBlock == null)
            }

            return AstVisitAction.Continue;
        }
示例#19
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst ast) { return CheckParent(ast); }
示例#20
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     if (namedBlockAst.Traps.Any())
     {
         return VisitNamedBlockWithTraps(namedBlockAst);
     }
     foreach (var stmt in namedBlockAst.Statements)
     {
         VisitStatement(stmt);
     }
     return AstVisitAction.SkipChildren;
 }
 /// <summary>
 /// Visit named block
 /// </summary>
 /// <param name="namedBlockAst"></param>
 /// <returns></returns>
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     if (namedBlockAst == null) return null;
     // Don't visit traps - they get their own scope
     return VisitStatementBlock(namedBlockAst.Statements);
 }
示例#22
0
文件: Compiler.cs 项目: nickchal/pash
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return null;
 }
示例#23
0
        public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
        {
            if (namedBlockAst.Traps.Any())
            {
                return VisitNamedBlockWithTraps(namedBlockAst);
            }

            // just iterate over children
            return base.VisitNamedBlock(namedBlockAst);
        }
示例#24
0
文件: Compiler.cs 项目: nickchal/pash
 private Expression<Action<FunctionContext>> CompileNamedBlock(NamedBlockAst namedBlockAst, string funcName)
 {
     IScriptExtent entryExtent = null;
     IScriptExtent exitExtent = null;
     if (namedBlockAst.Unnamed)
     {
         ScriptBlockAst parent = (ScriptBlockAst) namedBlockAst.Parent;
         if ((parent.Parent != null) && (parent.Extent is InternalScriptExtent))
         {
             InternalScriptExtent extent = (InternalScriptExtent) parent.Extent;
             entryExtent = new InternalScriptExtent(extent.PositionHelper, extent.StartOffset, extent.StartOffset + 1);
             exitExtent = new InternalScriptExtent(extent.PositionHelper, extent.EndOffset - 1, extent.EndOffset);
         }
     }
     else
     {
         entryExtent = namedBlockAst.OpenCurlyExtent;
         exitExtent = namedBlockAst.CloseCurlyExtent;
     }
     return this.CompileSingleLambda(namedBlockAst.Statements, namedBlockAst.Traps, funcName, entryExtent, exitExtent);
 }
示例#25
0
        private AstVisitAction VisitNamedBlockWithTraps(NamedBlockAst namedBlockAst)
        {
            foreach (StatementAst statement in namedBlockAst.Statements)
            {
                try
                {
                    VisitStatement(statement);
                }
                catch (FlowControlException)
                {
                    // flow control as Exit, Return, Break, and Continue doesn't concern the user and is propagated
                    throw;
                }
                catch (Exception ex)
                {
                    TrapStatementAst trapStatementAst = FindMatchingTrapStatement(namedBlockAst.Traps, ex);
                    if (trapStatementAst == null)
                    {
                        throw;
                    }

                    SetUnderscoreVariable(ex);
                    AstVisitAction visitAction = VisitTrapBody(trapStatementAst);

                    if (visitAction != AstVisitAction.Continue)
                    {
                        return AstVisitAction.SkipChildren;
                    }
                }
            }

            return AstVisitAction.SkipChildren;
        }
示例#26
0
文件: Parser.cs 项目: nickchal/pash
 private ScriptBlockAst NamedBlockListRule(Token lCurly, ParamBlockAst paramBlockAst)
 {
     IScriptExtent extent = null;
     IScriptExtent scriptExtent;
     Token token;
     IScriptExtent scriptExtent1 = null;
     IScriptExtent extent1;
     NamedBlockAst namedBlockAst = null;
     NamedBlockAst namedBlockAst1 = null;
     NamedBlockAst namedBlockAst2 = null;
     NamedBlockAst namedBlockAst3 = null;
     if (lCurly != null)
     {
         extent1 = lCurly.Extent;
     }
     else
     {
         if (paramBlockAst != null)
         {
             extent1 = paramBlockAst.Extent;
         }
         else
         {
             extent1 = null;
         }
     }
     IScriptExtent extent2 = extent1;
     while (true)
     {
         token = this.NextToken();
         TokenKind kind = token.Kind;
         if (kind > TokenKind.Dynamicparam)
         {
             if (kind != TokenKind.End && kind != TokenKind.Process)
             {
                 break;
             }
         }
         else
         {
             if (kind != TokenKind.Begin && kind != TokenKind.Dynamicparam)
             {
                 break;
             }
         }
         if (extent2 == null)
         {
             extent2 = token.Extent;
         }
         extent = token.Extent;
         StatementBlockAst statementBlockAst = this.StatementBlockRule();
         if (statementBlockAst != null)
         {
             extent = statementBlockAst.Extent;
         }
         else
         {
             object[] objArray = new object[1];
             objArray[0] = token.Kind.Text();
             this.ReportIncompleteInput(Parser.After(token.Extent), ParserStrings.MissingNamedStatementBlock, objArray);
             statementBlockAst = new StatementBlockAst(token.Extent, new StatementAst[0], null);
         }
         scriptExtent = Parser.ExtentOf(token, extent);
         if (token.Kind != TokenKind.Begin || namedBlockAst1 != null)
         {
             if (token.Kind != TokenKind.Process || namedBlockAst2 != null)
             {
                 if (token.Kind != TokenKind.End || namedBlockAst3 != null)
                 {
                     if (token.Kind != TokenKind.Dynamicparam || namedBlockAst != null)
                     {
                         object[] objArray1 = new object[1];
                         objArray1[0] = token.Kind.Text();
                         this.ReportError(scriptExtent, ParserStrings.DuplicateScriptCommandClause, objArray1);
                     }
                     else
                     {
                         namedBlockAst = new NamedBlockAst(scriptExtent, TokenKind.Dynamicparam, statementBlockAst, false);
                     }
                 }
                 else
                 {
                     namedBlockAst3 = new NamedBlockAst(scriptExtent, TokenKind.End, statementBlockAst, false);
                 }
             }
             else
             {
                 namedBlockAst2 = new NamedBlockAst(scriptExtent, TokenKind.Process, statementBlockAst, false);
             }
         }
         else
         {
             namedBlockAst1 = new NamedBlockAst(scriptExtent, TokenKind.Begin, statementBlockAst, false);
         }
         this.SkipNewlinesAndSemicolons();
     }
     this.UngetToken(token);
     scriptExtent = Parser.ExtentOf(extent2, extent);
     this.CompleteScriptBlockBody(lCurly, ref scriptExtent, out scriptExtent1);
     return new ScriptBlockAst(scriptExtent1, paramBlockAst, namedBlockAst1, namedBlockAst2, namedBlockAst3, namedBlockAst);
 }
示例#27
0
        private AstVisitAction VisitNamedBlockWithTraps(NamedBlockAst namedBlockAst)
        {
            foreach (StatementAst statement in namedBlockAst.Statements)
            {
                try
                {
                    statement.Visit(this);
                }
                catch (ReturnException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    TrapStatementAst trapStatementAst = FindMatchingTrapStatement(namedBlockAst.Traps, ex);
                    if (trapStatementAst == null)
                    {
                        throw;
                    }

                    SetUnderscoreVariable(ex);
                    AstVisitAction visitAction = VisitTrapBody(trapStatementAst);

                    if (visitAction != AstVisitAction.Continue)
                    {
                        return AstVisitAction.SkipChildren;
                    }
                }
            }

            return AstVisitAction.SkipChildren;
        }
示例#28
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst) { return AutomationNull.Value; }
示例#29
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     // just iterate over children
     return base.VisitNamedBlock(namedBlockAst);
 }
示例#30
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst) { throw PSTraceSource.NewArgumentException("ast"); }
示例#31
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(this.VisitStatementBlock(namedBlockAst.Statements));
 }
 /// <summary>
 /// Visit NamedBlockAst. Skip if name of the block
 /// is in namestobeskipped
 /// </summary>
 /// <param name="namedBlockAst"></param>
 /// <returns></returns>
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return VisitActionHelper(namedBlockAst);
 }
示例#33
0
 /// <summary/>
 public virtual object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(null);
 }
示例#34
0
        private Expression<Action<FunctionContext>> CompileNamedBlock(NamedBlockAst namedBlockAst, string funcName, ScriptBlockAst rootForDefiningTypes)
        {
            IScriptExtent entryExtent = null;
            IScriptExtent exitExtent = null;
            if (namedBlockAst.Unnamed)
            {
                // Get extent from the function or scriptblock expression parent, if any.
                var scriptBlock = (ScriptBlockAst)namedBlockAst.Parent;
                if (scriptBlock.Parent != null && scriptBlock.Extent is InternalScriptExtent)
                {
                    // We must have curlies at the start/end.
                    var scriptExtent = (InternalScriptExtent)scriptBlock.Extent;
                    entryExtent = new InternalScriptExtent(scriptExtent.PositionHelper, scriptExtent.StartOffset, scriptExtent.StartOffset + 1);
                    exitExtent = new InternalScriptExtent(scriptExtent.PositionHelper, scriptExtent.EndOffset - 1, scriptExtent.EndOffset);
                }
            }
            else
            {
                entryExtent = namedBlockAst.OpenCurlyExtent;
                exitExtent = namedBlockAst.CloseCurlyExtent;
            }

            return CompileSingleLambda(namedBlockAst.Statements, namedBlockAst.Traps, funcName, entryExtent, exitExtent, rootForDefiningTypes);
        }
示例#35
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     throw PSTraceSource.NewArgumentException("ast");
 }
示例#36
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     Diagnostics.Assert(false, "NamedBlockAst is handled specially, not via the visitor.");
     return null;
 }
示例#37
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return(AutomationNull.Value);
 }
示例#38
0
 public override AstVisitAction VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return AstVisitAction.Continue;
 }
示例#39
0
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     return this.VisitStatementBlock(namedBlockAst.Statements);
 }
 public object VisitNamedBlock(NamedBlockAst namedBlockAst)
 {
     throw new NotImplementedException();
 }