public static Hashtable GetHashtable(HashtableAst ast) { if (ast != null) { return ast.Visit(new PowerShellHashtableVisitor()) as Hashtable; } return null; }
public override AstVisitAction VisitHashtable(HashtableAst ast) { return CheckParent(ast); }
public virtual AstVisitAction VisitHashtable(HashtableAst hashtableAst) { return AstVisitAction.Continue; }
public override AstVisitAction VisitHashtable(HashtableAst hashtableAst) { Hashtable hashTable = new Hashtable(StringComparer.InvariantCultureIgnoreCase); foreach (var pair in hashtableAst.KeyValuePairs) { // if we don't have a custom psobject, make sure the value var val = EvaluateAst(pair.Item2); var psobjVal = val as PSObject; if (psobjVal != null && psobjVal.ImmediateBaseObject != null && psobjVal.ImmediateBaseObject.GetType() != typeof(PSCustomObject)) { val = psobjVal.ImmediateBaseObject; } hashTable.Add(EvaluateAst(pair.Item1), val); } this._pipelineCommandRuntime.WriteObject(hashTable); return AstVisitAction.SkipChildren; }
/// <summary> /// Visit Hash table /// </summary> /// <param name="hashtableAst"></param> /// <returns></returns> public object VisitHashtable(HashtableAst hashtableAst) { if (hashtableAst == null) return null; foreach (var pair in hashtableAst.KeyValuePairs) { pair.Item1.Visit(this.Decorator); pair.Item2.Visit(this.Decorator); } return null; }
private Tuple<ExpressionAst, StatementAst> GetHashEntryContainsCursor( IScriptPosition cursor, HashtableAst hashTableAst, bool isCursorInString) { Tuple<ExpressionAst, StatementAst> keyValuePairWithCursor = null; foreach (var kvp in hashTableAst.KeyValuePairs) { if (IsCursorWithinOrJustAfterExtent(cursor, kvp.Item2.Extent)) { keyValuePairWithCursor = kvp; break; } if (!isCursorInString) { // // Handle following case, cursor is after '=' but before next key value pair, // next key value pair will be treated as kvp.Item2 of 'Ensure' key // // configuration foo // { // File foo // { // DestinationPath = "\foo.txt" // Ensure = | // DependsOn =@("[User]x") // } // } // if (kvp.Item2.Extent.StartLineNumber > kvp.Item1.Extent.EndLineNumber && IsCursorAfterExtentAndInTheSameLine(cursor, kvp.Item1.Extent)) { keyValuePairWithCursor = kvp; break; } // // If cursor is not within a string, then handle following two cases, // // #1) cursor is after '=', in the same line of previous key value pair // configuration test{File testfile{DestinationPath='c:\test'; Ensure = | // // #2) cursor is after '=', in the separate line of previous key value pair // configuration test{File testfile{DestinationPath='c:\test'; // Ensure = | // if (!IsCursorBeforeExtent(cursor, kvp.Item1.Extent) && IsCursorAfterExtentAndInTheSameLine(cursor, kvp.Item2.Extent)) { keyValuePairWithCursor = kvp; } } } return keyValuePairWithCursor; }
public override AstVisitAction VisitHashtable(HashtableAst hashtableAst) { return AstVisitAction.Continue; }
public object VisitHashtable(HashtableAst hashtableAst) { var temp = NewTemp(typeof(Hashtable), "hashtable"); return Expression.Block(typeof(Hashtable), new[] { temp }, BuildHashtable(hashtableAst.KeyValuePairs, temp, ordered: false)); }
public override AstVisitAction VisitHashtable(HashtableAst hashtableAst) { HashSet<string> keys = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (var entry in hashtableAst.KeyValuePairs) { var keyStrAst = entry.Item1 as ConstantExpressionAst; if (keyStrAst != null) { var keyStr = keyStrAst.Value.ToString(); if (keys.Contains(keyStr)) { // Note - the error handling function inspects the error message body to extra the ParserStrings property name. It uses this value as the errorid. var errorMessageExpression = hashtableAst.IsSchemaElement ? (() => ParserStrings.DuplicatePropertyInInstanceDefinition) : (Expression<Func<string>>)(() => ParserStrings.DuplicateKeyInHashLiteral); _parser.ReportError(entry.Item1.Extent, errorMessageExpression, keyStr); } else { keys.Add(keyStr); } } } return AstVisitAction.Continue; }
public override AstVisitAction VisitHashtable(HashtableAst hashtableAst) { // Hash literals are accepted if the keys and values are accepted. return AstVisitAction.Continue; }
public object VisitHashtable(HashtableAst hashtableAst) { ParameterExpression temp = this.NewTemp(typeof(Hashtable), "hashtable"); return Expression.Block(typeof(Hashtable), new ParameterExpression[] { temp }, this.BuildHashtable(hashtableAst.KeyValuePairs, temp, false)); }
/// <summary> /// Checks if the *ToExport fields are explicitly set to arrays, eg. @(...), and the array entries do not contain any wildcard. /// </summary> /// <param name="key"></param> /// <param name="hast"></param> /// <param name="scriptText"></param> /// <param name="extent"></param> /// <returns>A boolean value indicating if the the ToExport fields are explicitly set to arrays or not.</returns> private bool HasAcceptableExportField(string key, HashtableAst hast, string scriptText, out IScriptExtent extent) { extent = null; foreach (var pair in hast.KeyValuePairs) { if (key.Equals(pair.Item1.Extent.Text.Trim(), StringComparison.OrdinalIgnoreCase)) { // checks if the right hand side of the assignment is an array. var arrayAst = pair.Item2.Find(x => x is ArrayLiteralAst || x is ArrayExpressionAst, true); if (arrayAst == null) { extent = pair.Item2.Extent; return false; } else { //checks if any entry within the array has a wildcard. var elementWithWildcard = arrayAst.Find(x => x is StringConstantExpressionAst && x.Extent.Text.Contains("*"), false); if (elementWithWildcard != null) { extent = elementWithWildcard.Extent; return false; } return true; } } } return true; }
public override AstVisitAction VisitHashtable(HashtableAst hashtableAst) { HashSet<string> set = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (Tuple<ExpressionAst, StatementAst> tuple in hashtableAst.KeyValuePairs) { ConstantExpressionAst ast = tuple.Item1 as ConstantExpressionAst; if (ast != null) { string item = ast.Value.ToString(); if (set.Contains(item)) { this._parser.ReportError(tuple.Item1.Extent, ParserStrings.DuplicateKeyInHashLiteral, new object[] { item }); } else { set.Add(item); } } } return AstVisitAction.Continue; }
private ExpressionAst HashExpressionRule(Token atCurlyToken, bool parsingSchemaElement) { //G hash-literal-expression: //G '@{' new-lines:opt hash-literal-body:opt new-lines:opt '}' //G hash-literal-body: //G hash-entry //G hash-literal-body statement-terminators hash-entry //G statement-terminators: //G statement-terminator //G statement-terminators statement-terminator SkipNewlines(); List<KeyValuePair> keyValuePairs = new List<KeyValuePair>(); while (true) { KeyValuePair pair = GetKeyValuePair(parsingSchemaElement); if (pair == null) { break; } keyValuePairs.Add(pair); Token token = PeekToken(); if (token.Kind != TokenKind.NewLine && token.Kind != TokenKind.Semi) { break; } SkipNewlinesAndSemicolons(); } IScriptExtent endExtent; Token rCurly = NextToken(); if (rCurly.Kind != TokenKind.RCurly) { UngetToken(rCurly); // Note - the error handling function inspects the error message body to extra the ParserStrings property name. It uses this value as the errorid. var errorMessageExpression = parsingSchemaElement ? (Expression<Func<string>>)(() => ParserStrings.IncompletePropertyAssignmentBlock) : (Expression<Func<string>>)(() => ParserStrings.IncompleteHashLiteral); ReportIncompleteInput(keyValuePairs.Any() ? After(keyValuePairs.Last().Item2) : After(atCurlyToken), rCurly.Extent, errorMessageExpression); endExtent = Before(rCurly); } else { endExtent = rCurly.Extent; } var hashAst = new HashtableAst(ExtentOf(atCurlyToken, endExtent), keyValuePairs); hashAst.IsSchemaElement = parsingSchemaElement; return hashAst; }
/// <summary/> public virtual object VisitHashtable(HashtableAst hashtableAst) { return null; }
public object VisitHashtable(HashtableAst hashtableAst) { Hashtable hashtable = new Hashtable(StringComparer.CurrentCultureIgnoreCase); foreach (var pair in hashtableAst.KeyValuePairs) { var key = pair.Item1.Accept(this); var value = pair.Item2.Accept(this); hashtable.Add(key, value); } return hashtable; }
/// <summary> /// Gets the correction extent /// </summary> /// <param name="ast"></param> /// <returns>A List of CorrectionExtent</returns> private List<CorrectionExtent> GetCorrectionExtent(HashtableAst ast) { int startLineNumber; int startColumnNumber; // for empty hashtable insert after after "@{" if (ast.KeyValuePairs.Count == 0) { // check if ast starts with "@{" if (ast.Extent.Text.IndexOf("@{") != 0) { return null; } startLineNumber = ast.Extent.StartLineNumber; startColumnNumber = ast.Extent.StartColumnNumber + 2; // 2 for "@{", } else // for non-empty hashtable insert after the last element { int maxLine = 0; int lastCol = 0; foreach (var keyVal in ast.KeyValuePairs) { if (keyVal.Item2.Extent.EndLineNumber > maxLine) { maxLine = keyVal.Item2.Extent.EndLineNumber; lastCol = keyVal.Item2.Extent.EndColumnNumber; } } startLineNumber = maxLine; startColumnNumber = lastCol; } var correctionExtents = new List<CorrectionExtent>(); string fieldName = "ModuleVersion"; string fieldValue = "1.0.0.0"; string description = string.Format( CultureInfo.CurrentCulture, Strings.MissingModuleManifestFieldCorrectionDescription, fieldName, fieldValue); var correctionTextTemplate = @" # Version number of this module. {0} = '{1}' "; var correctionText = string.Format( correctionTextTemplate, fieldName, fieldValue); var correctionExtent = new CorrectionExtent( startLineNumber, startLineNumber, startColumnNumber, startColumnNumber, correctionText, ast.Extent.File, description); correctionExtents.Add(correctionExtent); return correctionExtents; }
public object VisitHashtable(HashtableAst hashtableAst) { var result = new Hashtable(StringComparer.InvariantCultureIgnoreCase); foreach (var pair in hashtableAst.KeyValuePairs) { result.Add(pair.Item1.Visit(this), pair.Item2.Visit(this)); } return result; }
public object VisitHashtable(HashtableAst hashtableAst) { foreach (var pair in hashtableAst.KeyValuePairs) { pair.Item1.Accept(this); pair.Item2.Accept(this); } return null; }
public override AstVisitAction VisitHashtable(HashtableAst ast) { return this.Check(ast); }
// Helper method to look for an incomplete assignment pair in hash table. private bool CheckForPendingAssigment(HashtableAst hashTableAst) { foreach (var keyValue in hashTableAst.KeyValuePairs) { if (keyValue.Item2 is ErrorStatementAst) { // This indicates the assignment has not completed. return true; } } return false; }
public object VisitHashtable(HashtableAst hashtableAst) { foreach (Tuple<ExpressionAst, StatementAst> tuple in hashtableAst.KeyValuePairs) { if (!((bool) tuple.Item1.Accept(this))) { return false; } if (!((bool) tuple.Item2.Accept(this))) { return false; } } return true; }
public object VisitHashtable(HashtableAst hashtableAst) { foreach (Tuple<ExpressionAst, StatementAst> tuple in hashtableAst.KeyValuePairs) { tuple.Item1.Accept(this); tuple.Item2.Accept(this); } return null; }
public object VisitHashtable(HashtableAst hashtableAst) { return CheckingRequiresArgument && hashtableAst.KeyValuePairs.All(pair => (bool)pair.Item1.Accept(this) && (bool)pair.Item2.Accept(this)); }
/// <summary/> public virtual object VisitHashtable(HashtableAst hashtableAst) { return _decorated.VisitHashtable(hashtableAst); }
public object VisitHashtable(HashtableAst hashtableAst) { CheckIsConstant(hashtableAst, "Caller to verify ast is constant"); var result = new Hashtable(); foreach (var pair in hashtableAst.KeyValuePairs) { result.Add(pair.Item1.Accept(this), pair.Item2.Accept(this)); } return result; }
public override AstVisitAction VisitHashtable(HashtableAst hashtableAst) { Hashtable hashTable = new Hashtable(); foreach (var pair in hashtableAst.KeyValuePairs) { hashTable.Add(EvaluateAst(pair.Item1), EvaluateAst(pair.Item2)); } this._pipelineCommandRuntime.WriteObject(hashTable); return AstVisitAction.SkipChildren; }
public object VisitHashtable(HashtableAst hashtableAst) { if (hashtableAst.KeyValuePairs.Count > MaxHashtableKeyCount) { return false; } return hashtableAst.KeyValuePairs.All(pair => (bool)pair.Item1.Accept(this) && (bool)pair.Item2.Accept(this)); }
public object VisitHashtable(HashtableAst hashtableAst) { return (!this.CheckingRequiresArgument ? ((object) false) : ((object) hashtableAst.KeyValuePairs.All<Tuple<ExpressionAst, StatementAst>>(pair => (((bool) pair.Item1.Accept(this)) && ((bool) pair.Item2.Accept(this)))))); }
public object VisitHashtable(HashtableAst hashtableAst) { Hashtable hashtable = new Hashtable(); foreach (Tuple<ExpressionAst, StatementAst> tuple in hashtableAst.KeyValuePairs) { hashtable.Add(tuple.Item1.Accept(this), tuple.Item2.Accept(this)); } return hashtable; }