public override AstVisitAction VisitPipeline(PipelineAst pipelineAst) { MaxPipelineDepth = Math.Max(MaxPipelineDepth, pipelineAst.PipelineElements.Count); PipelineCount += 1; return(AstVisitAction.Continue); }
private Hashtable GetHashtableFromHashTableAst(HashtableAst hashTableAst) { var output = new Hashtable(); foreach (var kvp in hashTableAst.KeyValuePairs) { var keyAst = kvp.Item1 as StringConstantExpressionAst; if (keyAst == null) { // first item (the key) should be a string ThrowInvalidDataException(kvp.Item1); } var key = keyAst.Value; // parse the item2 as array PipelineAst pipeAst = kvp.Item2 as PipelineAst; List <string> rhsList = new List <string>(); if (pipeAst != null) { ExpressionAst pureExp = pipeAst.GetPureExpression(); var constExprAst = pureExp as ConstantExpressionAst; if (constExprAst != null) { var strConstExprAst = constExprAst as StringConstantExpressionAst; if (strConstExprAst != null) { // it is a string literal output[key] = strConstExprAst.Value; } else { // it is either an integer or a float output[key] = constExprAst.Value; } continue; } else if (pureExp is HashtableAst) { output[key] = GetHashtableFromHashTableAst((HashtableAst)pureExp); continue; } else if (pureExp is VariableExpressionAst) { var varExprAst = (VariableExpressionAst)pureExp; switch (varExprAst.VariablePath.UserPath.ToLower()) { case "true": output[key] = true; break; case "false": output[key] = false; break; default: ThrowInvalidDataException(varExprAst.Extent); break; } continue; } else { rhsList = GetArrayFromAst(pureExp); } } if (rhsList.Count == 0) { ThrowInvalidDataException(kvp.Item2); } output[key] = rhsList.ToArray(); } return(output); }
public virtual StatementAst VisitPipeline(PipelineAst pipelineAst) { return(new PipelineAst( pipelineAst.Extent, pipelineAst.PipelineElements.RewriteAll(this, SyntaxKind.Command))); }
object ICustomAstVisitor.VisitPipeline(PipelineAst pipelineAst) => ProcessRewriter(VisitPipeline, pipelineAst);
public virtual TResult VisitPipeline(PipelineAst pipelineAst) => default(TResult);
object ICustomAstVisitor.VisitPipeline(PipelineAst pipelineAst) => VisitPipeline(pipelineAst);
/// <summary> /// Returns '0' if the <paramref name="parameterValue"/> does not need delimitation, '1' if it does, and a quote character if it needs to be delimited with a quote /// </summary> /// <param name="parameterValue">parameter value to check</param> /// <param name="requireScriptblock">true if the parameter value should be a scriptblock</param> /// <returns>'0' if the parameter does not need delimitation, '1' if it needs, '\'' if it needs to be delimited with single quote and '\"' if it needs to be delimited with double quotes</returns> private static char ParameterNeedsDelimitation(string parameterValue, bool requireScriptblock) { Token[] tokens; ParseError[] errors; ScriptBlockAst values = Parser.ParseInput("commandName -parameterName " + parameterValue, out tokens, out errors); if (values == null || values.EndBlock == null || values.EndBlock.Statements.Count == 0) { return('1'); } PipelineAst pipeline = values.EndBlock.Statements[0] as PipelineAst; if (pipeline == null || pipeline.PipelineElements.Count == 0) { return('1'); } CommandAst commandAst = pipeline.PipelineElements[0] as CommandAst; if (commandAst == null || commandAst.CommandElements.Count == 0) { return('1'); } // 3 is for CommandName, Parameter and its value if (commandAst.CommandElements.Count != 3) { return('1'); } if (requireScriptblock) { ScriptBlockExpressionAst scriptAst = commandAst.CommandElements[2] as ScriptBlockExpressionAst; return(scriptAst == null ? '1' : '0'); } StringConstantExpressionAst stringValue = commandAst.CommandElements[2] as StringConstantExpressionAst; if (stringValue != null) { if (errors.Length == 0) { return('0'); } char stringTerminationChar; if (stringValue.StringConstantType == StringConstantType.BareWord) { stringTerminationChar = parameterValue[0]; } else if (stringValue.StringConstantType == StringConstantType.DoubleQuoted || stringValue.StringConstantType == StringConstantType.DoubleQuotedHereString) { stringTerminationChar = '\"'; } else { Diagnostics.Assert(stringValue.StringConstantType == StringConstantType.SingleQuoted || stringValue.StringConstantType == StringConstantType.SingleQuotedHereString, "those are the 2 enumeration values left"); stringTerminationChar = '\''; } char oppositeTerminationChar = stringTerminationChar == '\"' ? '\'' : '\"'; // If the string is not terminated, it should be delimited by the opposite string termination character return(oppositeTerminationChar); } if (errors.Length != 0) { return('1'); } return('0'); }
public override AstVisitAction VisitPipeline(PipelineAst pipelineAst) { return(Visit(pipelineAst)); }
public override AstVisitAction VisitPipeline(PipelineAst pipelineAst) => VisitAst(pipelineAst);