public override AstVisitAction VisitErrorStatement(ErrorStatementAst ast) { return CheckParent(ast); }
public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { throw PSTraceSource.NewArgumentException("ast"); }
public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { return(AutomationNull.Value); }
public System.Object VisitErrorStatement(System.Management.Automation.Language.ErrorStatementAst errorStatementAst) { IScriptExtent mappedExtent = MapExtent(errorStatementAst.Extent); return(errorStatementAst); }
/// <summary/> public virtual object VisitErrorStatement(ErrorStatementAst errorStatementAst) { return(null); }
public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { throw PSTraceSource.NewArgumentException("ast"); }
/// <summary> /// Visit error statement /// </summary> /// <param name="errorStatementAst"></param> /// <returns></returns> public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { return null; }
private ExpressionAst ParenthesizedExpressionRule(Token lParen) { //G parenthesized-expression: //G '(' new-lines:opt pipeline new-lines:opt ')' Token rParen; PipelineBaseAst pipelineAst; var oldTokenizerMode = _tokenizer.Mode; var oldDisableCommaOperator = _disableCommaOperator; try { SetTokenizerMode(TokenizerMode.Command); _disableCommaOperator = false; SkipNewlines(); pipelineAst = PipelineRule(); if (pipelineAst == null) { IScriptExtent errorPosition = After(lParen); ReportIncompleteInput(errorPosition, () => ParserStrings.ExpectedExpression); pipelineAst = new ErrorStatementAst(errorPosition); } SkipNewlines(); rParen = NextToken(); if (rParen.Kind != TokenKind.RParen) { // ErrorRecovery: Assume only the closing paren is missing, continue as though it was present. UngetToken(rParen); ReportIncompleteInput(After(pipelineAst), () => ParserStrings.MissingEndParenthesisInExpression); rParen = null; } } finally { _disableCommaOperator = oldDisableCommaOperator; SetTokenizerMode(oldTokenizerMode); } return new ParenExpressionAst(ExtentOf(lParen, ExtentFromFirstOf(rParen, pipelineAst)), pipelineAst); }
private Tuple<ExpressionAst, StatementAst> GetKeyValuePair() { Token token; ExpressionAst expressionAst; StatementAst errorStatementAst; Tuple<ExpressionAst, StatementAst> tuple; TokenizerMode mode = this._tokenizer.Mode; try { this.SetTokenizerMode(TokenizerMode.Expression); expressionAst = this.LabelOrKeyRule(); if (expressionAst != null) { token = this.NextToken(); goto Label0; } else { tuple = null; } } finally { this.SetTokenizerMode(mode); } return tuple; Label0: if (token.Kind == TokenKind.Equals) { try { this.SetTokenizerMode(TokenizerMode.Command); this.SkipNewlines(); errorStatementAst = this.StatementRule(); if (errorStatementAst == null) { IScriptExtent scriptExtent = Parser.After(token); this.ReportIncompleteInput(scriptExtent, ParserStrings.MissingStatementInHashLiteral, new object[0]); errorStatementAst = new ErrorStatementAst(scriptExtent, (IEnumerable<Ast>)null); } } finally { this.SetTokenizerMode(mode); } return new Tuple<ExpressionAst, StatementAst>(expressionAst, errorStatementAst); } else { this.UngetToken(token); IScriptExtent scriptExtent1 = Parser.After(expressionAst); this.ReportError(scriptExtent1, ParserStrings.MissingEqualsInHashLiteral, new object[0]); TokenKind[] tokenKindArray = new TokenKind[3]; tokenKindArray[0] = TokenKind.RCurly; tokenKindArray[1] = TokenKind.Semi; tokenKindArray[2] = TokenKind.NewLine; this.SyncOnError(tokenKindArray); return new Tuple<ExpressionAst, StatementAst>(expressionAst, new ErrorStatementAst(scriptExtent1, (IEnumerable<Ast>)null)); } }
private PipelineBaseAst PipelineRule() { //G pipeline: //G assignment-expression //G expression redirections:opt pipeline-tail:opt //G command pipeline-tail:opt //G //G assignment-expression: //G expression assignment-operator statement //G //G pipeline-tail: //G '|' new-lines:opt command //G '|' new-lines:opt command pipeline-tail var pipelineElements = new List<CommandBaseAst>(); IScriptExtent startExtent = null; Token pipeToken = null; bool scanning = true; while (scanning) { CommandBaseAst commandAst; Token assignToken = null; ExpressionAst expr; var oldTokenizerMode = _tokenizer.Mode; try { SetTokenizerMode(TokenizerMode.Expression); expr = ExpressionRule(); if (expr != null) { // We peek here because we are in expression mode, otherwise =0 will get scanned // as a single token. var token = PeekToken(); if (token.Kind.HasTrait(TokenFlags.AssignmentOperator)) { SkipToken(); assignToken = token; } } } finally { SetTokenizerMode(oldTokenizerMode); } if (expr != null) { if (pipelineElements.Count > 0) { // ErrorRecovery: this is a semantic error, so just keep parsing. ReportError(expr.Extent, () => ParserStrings.ExpressionsMustBeFirstInPipeline); } if (assignToken != null) { SkipNewlines(); StatementAst statement = StatementRule(); if (statement == null) { // ErrorRecovery: we are very likely at EOF because pretty much anything should result in some // pipeline, so just keep parsing. IScriptExtent errorExtent = After(assignToken); ReportIncompleteInput(errorExtent, () => ParserStrings.ExpectedValueExpression, assignToken.Kind.Text()); statement = new ErrorStatementAst(errorExtent); } return new AssignmentStatementAst(ExtentOf(expr, statement), expr, assignToken.Kind, statement, assignToken.Extent); } RedirectionAst[] redirections = null; var redirectionToken = PeekToken() as RedirectionToken; RedirectionAst lastRedirection = null; while (redirectionToken != null) { SkipToken(); if (redirections == null) { redirections = new RedirectionAst[CommandBaseAst.MaxRedirections]; } IScriptExtent unused = null; lastRedirection = RedirectionRule(redirectionToken, redirections, ref unused); redirectionToken = PeekToken() as RedirectionToken; } var exprExtent = lastRedirection != null ? ExtentOf(expr, lastRedirection) : expr.Extent; commandAst = new CommandExpressionAst(exprExtent, expr, redirections != null ? redirections.Where(r => r != null) : null); } else { commandAst = (CommandAst)CommandRule(forDynamicKeyword: false); } if (commandAst != null) { if (startExtent == null) { startExtent = commandAst.Extent; } pipelineElements.Add(commandAst); } else if (pipelineElements.Count > 0 || PeekToken().Kind == TokenKind.Pipe) { // ErrorRecovery: just fall through // If the first pipe element is null, the position points to the pipe (ideally it would // point before, but the pipe could be the first character), otherwise the empty element // is after the pipe character. IScriptExtent errorPosition = pipeToken != null ? After(pipeToken) : PeekToken().Extent; ReportIncompleteInput(errorPosition, () => ParserStrings.EmptyPipeElement); } pipeToken = PeekToken(); switch (pipeToken.Kind) { case TokenKind.Semi: case TokenKind.NewLine: case TokenKind.RParen: case TokenKind.RCurly: case TokenKind.EndOfInput: scanning = false; continue; case TokenKind.Pipe: SkipToken(); SkipNewlines(); if (PeekToken().Kind == TokenKind.EndOfInput) { scanning = false; ReportIncompleteInput(After(pipeToken), () => ParserStrings.EmptyPipeElement); } break; case TokenKind.AndAnd: case TokenKind.OrOr: // Parse in a manner similar to a pipe, but issue an error (for now, but should implement this for V3.) SkipToken(); SkipNewlines(); ReportError(pipeToken.Extent, () => ParserStrings.InvalidEndOfLine, pipeToken.Text); if (PeekToken().Kind == TokenKind.EndOfInput) { scanning = false; } break; default: // ErrorRecovery: don't eat the token, assume it belongs to something else. ReportError(pipeToken.Extent, () => ParserStrings.UnexpectedToken, pipeToken.Text); scanning = false; break; } } if (pipelineElements.Count == 0) { return null; } return new PipelineAst(ExtentOf(startExtent, pipelineElements[pipelineElements.Count - 1]), pipelineElements); }
private KeyValuePair GetKeyValuePair(bool parsingSchemaElement) { //G hash-entry: //G key-expression '=' new-lines:opt statement Token equals; ExpressionAst key; var oldTokenizerMode = _tokenizer.Mode; try { SetTokenizerMode(TokenizerMode.Expression); key = LabelOrKeyRule(); if (key == null) { return null; } equals = NextToken(); } finally { SetTokenizerMode(oldTokenizerMode); } if (equals.Kind != TokenKind.Equals) { // ErrorRecovery: Pretend we saw the '=' and a statement. UngetToken(equals); IScriptExtent errorExtent = After(key); // 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 ? (() => (ParserStrings.MissingEqualsInPropertyAssignmentBlock)) : (Expression<Func<string>>)(() => ParserStrings.MissingEqualsInHashLiteral); ReportError(errorExtent, errorMessageExpression); SyncOnError(true, TokenKind.RCurly, TokenKind.Semi, TokenKind.NewLine); return new KeyValuePair(key, new ErrorStatementAst(errorExtent)); } StatementAst statement; try { SetTokenizerMode(TokenizerMode.Command); SkipNewlines(); statement = StatementRule(); if (statement == null) { // ErrorRecovery: pretend we saw a statement and keep parsing. IScriptExtent errorExtent = After(equals); // 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.MissingEqualsInPropertyAssignmentBlock) : (Expression<Func<string>>)(() => ParserStrings.MissingStatementInHashLiteral); ReportIncompleteInput(errorExtent, errorMessageExpression); statement = new ErrorStatementAst(errorExtent); } } finally { SetTokenizerMode(oldTokenizerMode); } return new KeyValuePair(key, statement); }
private StatementAst WhileStatementRule(LabelToken labelToken, Token whileToken) { //G while-statement: //G 'while ' new-lines:opt '(' new-lines:opt while-condition new-lines:opt ')' statement-block SkipNewlines(); Token lParen = NextToken(); if (lParen.Kind != TokenKind.LParen) { // ErrorRecovery: assume user just typed 'while' and hadn't started typing anything // else yet. Next token is likely a newline, so just put it back and keep parsing. UngetToken(lParen); ReportIncompleteInput(After(whileToken), () => ParserStrings.MissingOpenParenthesisAfterKeyword, whileToken.Text); return new ErrorStatementAst(ExtentOf(labelToken ?? whileToken, whileToken)); } SkipNewlines(); PipelineBaseAst condition = PipelineRule(); PipelineBaseAst errorCondition = null; if (condition == null) { // ErrorRecovery: assume pipeline just hasn't been entered yet, continue hoping // to find a close paren and statement block. IScriptExtent errorPosition = After(lParen); ReportIncompleteInput(errorPosition, () => ParserStrings.MissingExpressionAfterKeyword, whileToken.Kind.Text()); condition = new ErrorStatementAst(errorPosition); } else { errorCondition = condition; } SkipNewlines(); Token rParen = NextToken(); if (rParen.Kind != TokenKind.RParen) { // ErrorRecovery: assume the next token is a newline or part of something else, // so stop parsing the statement and try parsing something else if possible. UngetToken(rParen); if (!(condition is ErrorStatementAst)) { ReportIncompleteInput(After(condition), () => ParserStrings.MissingEndParenthesisAfterStatement, whileToken.Kind.Text()); } return new ErrorStatementAst(ExtentOf(labelToken ?? whileToken, condition), GetNestedErrorAsts(errorCondition)); } SkipNewlines(); StatementBlockAst body = StatementBlockRule(); if (body == null) { // ErrorRecovery: assume the next token is a newline or part of something else. ReportIncompleteInput(After(rParen), () => ParserStrings.MissingLoopStatement, whileToken.Kind.Text()); return new ErrorStatementAst(ExtentOf(labelToken ?? whileToken, rParen), GetNestedErrorAsts(errorCondition)); } return new WhileStatementAst(ExtentOf(labelToken ?? whileToken, body), labelToken != null ? labelToken.LabelText : null, condition, body); }
private StatementAst IfStatementRule(Token ifToken) { //G if-statement: //G 'if' new-lines:opt '(' pipeline-statement ')' statement-block elseif-clauses:opt else-clause:opt //G elseif-clauses: //G elseif-clause //G elseif-clauses elseif-clause //G elseif-clause: //G 'elseif' new-lines:opt '(' pipeline-statement ')' statement-block //G else-clause: //G 'else' statement-block List<IfClause> clauses = new List<IfClause>(); List<Ast> componentAsts = new List<Ast>(); StatementBlockAst elseClause = null; Token keyword = ifToken; while (true) { SkipNewlines(); Token lParen = NextToken(); if (lParen.Kind != TokenKind.LParen) { // ErrorRecovery: assume user just typed 'if' or 'elseif' and hadn't started typing anything // else yet. Next token is likely a newline, so just put it back and keep parsing. UngetToken(lParen); ReportIncompleteInput(After(keyword), () => ParserStrings.MissingOpenParenthesisInIfStatement, keyword.Text); return new ErrorStatementAst(ExtentOf(ifToken, keyword), componentAsts); } SkipNewlines(); PipelineBaseAst condition = PipelineRule(); if (condition == null) { // ErrorRecovery: assume pipeline just hasn't been entered yet, continue hoping // to find a close paren and statement block. IScriptExtent errorPosition = After(lParen); ReportIncompleteInput(errorPosition, () => ParserStrings.IfStatementMissingCondition, keyword.Text); condition = new ErrorStatementAst(errorPosition); } else { componentAsts.Add(condition); } SkipNewlines(); Token rParen = NextToken(); if (rParen.Kind != TokenKind.RParen) { // ErrorRecovery: assume the next token is a newline or part of something else, // so stop parsing the statement and try parsing something else if possible. UngetToken(rParen); // Don't bother reporting this error if we already reported an empty condition error. if (!(condition is ErrorStatementAst)) { ReportIncompleteInput(rParen.Extent, () => ParserStrings.MissingEndParenthesisAfterStatement, keyword.Text); } return new ErrorStatementAst(ExtentOf(ifToken, Before(rParen)), componentAsts); } SkipNewlines(); StatementBlockAst body = StatementBlockRule(); if (body == null) { // ErrorRecovery: assume the next token is a newline or part of something else, // so stop parsing the statement and try parsing something else. ReportIncompleteInput(rParen.Extent, () => ParserStrings.MissingStatementBlock, keyword.Text); return new ErrorStatementAst(ExtentOf(ifToken, rParen), componentAsts); } componentAsts.Add(body); clauses.Add(new IfClause(condition, body)); SkipNewlines(); keyword = PeekToken(); if (keyword.Kind == TokenKind.ElseIf) { SkipToken(); continue; } if (keyword.Kind == TokenKind.Else) { SkipToken(); SkipNewlines(); elseClause = StatementBlockRule(); if (elseClause == null) { // ErrorRecovery: assume the next token is a newline or part of something else, // so stop parsing the statement and try parsing something else. ReportIncompleteInput(After(keyword), () => ParserStrings.MissingStatementBlockAfterElse); return new ErrorStatementAst(ExtentOf(ifToken, keyword), componentAsts); } } break; } IScriptExtent endExtent = (elseClause != null) ? elseClause.Extent : clauses[clauses.Count - 1].Item2.Extent; IScriptExtent extent = ExtentOf(ifToken, endExtent); return new IfStatementAst(extent, clauses, elseClause); }
/// <summary> /// Parse a single statement. /// </summary> /// <returns>A statement ast. Never returns null, always returns PipelineAst.EmptyPipeline if there was no statement.</returns> private StatementAst StatementRule() { //G statement: //G if-statement //G label:opt labeled-statement //G function-statement //G flow-control-statement statement-terminator //G trap-statement //G try-statement //G data-statement //G pipeline statement-terminator //G //G labeled-statement: //G switch-statement //G foreach-statement //G for-statement //G while-statement //G do-statement //G //G flow-control-statement: //G 'break' label-expression:opt //G 'continue' label-expression:opt //G 'throw' pipeline:opt //G 'return' pipeline:opt //G 'exit' pipeline:opt //G //G statement-terminator: //G ';' //G new-line-character RuntimeHelpers.EnsureSufficientExecutionStack(); int restorePoint = 0; StatementAst statement; Token token = NextToken(); List<AttributeBaseAst> attributes = null; if (token.Kind == TokenKind.Generic && token.Text[0] == '[') { restorePoint = token.Extent.StartOffset; Resync(token); attributes = AttributeListRule(false); token = NextToken(); if (attributes != null && attributes.Count > 0) { if ((token.TokenFlags & TokenFlags.StatementDoesntSupportAttributes) != 0) { if (attributes.OfType<TypeConstraintAst>().Any()) { Resync(restorePoint); token = NextToken(); } else { ReportError(attributes[0].Extent, () => ParserStrings.UnexpectedAttribute, attributes[0].TypeName.FullName); } } else if ((token.TokenFlags & TokenFlags.Keyword) != 0) { foreach (var attr in attributes.Where(attr => !(attr is AttributeAst))) { ReportError(attr.Extent, () => ParserStrings.TypeNotAllowedBeforeStatement, attr.TypeName.FullName); break; } } else { Resync(restorePoint); token = NextToken(); } } } switch (token.Kind) { case TokenKind.If: statement = IfStatementRule(token); break; case TokenKind.Switch: statement = SwitchStatementRule(null, token); break; case TokenKind.Foreach: statement = ForeachStatementRule(null, token); break; case TokenKind.For: statement = ForStatementRule(null, token); break; case TokenKind.While: statement = WhileStatementRule(null, token); break; case TokenKind.Do: statement = DoWhileStatementRule(null, token); break; case TokenKind.Function: case TokenKind.Filter: case TokenKind.Workflow: statement = FunctionDeclarationRule(token); break; case TokenKind.Return: statement = ReturnStatementRule(token); break; case TokenKind.Throw: statement = ThrowStatementRule(token); break; case TokenKind.Exit: statement = ExitStatementRule(token); break; case TokenKind.Break: statement = BreakStatementRule(token); break; case TokenKind.Continue: statement = ContinueStatementRule(token); break; case TokenKind.Trap: statement = TrapStatementRule(token); break; case TokenKind.Try: statement = TryStatementRule(token); break; case TokenKind.Data: statement = DataStatementRule(token); break; case TokenKind.Parallel: case TokenKind.Sequence: statement = BlockStatementRule(token); break; case TokenKind.Configuration: statement = ConfigurationStatementRule(attributes != null ? attributes.OfType<AttributeAst>() : null, token); break; case TokenKind.From: case TokenKind.Define: case TokenKind.Var: ReportError(token.Extent, () => ParserStrings.ReservedKeywordNotAllowed, token.Kind.Text()); statement = new ErrorStatementAst(token.Extent); break; case TokenKind.Label: SkipNewlines(); statement = LabeledStatementRule((LabelToken)token); break; case TokenKind.EndOfInput: if (attributes != null) { Resync(restorePoint); statement = PipelineRule(); } else { UngetToken(token); statement = null; } break; case TokenKind.Else: case TokenKind.ElseIf: case TokenKind.Catch: case TokenKind.Until: if (ErrorList.Count > 0) { // If we have already seen an error, just eat these tokens. By eating the token, we won't // generate an odd pipeline with the keyword as a command name, which should provider a better // user experience (e.g., better syntax coloring.) SkipNewlines(); return StatementRule(); } goto default; case TokenKind.DynamicKeyword: DynamicKeyword keywordData = DynamicKeyword.GetKeyword(token.Text); statement = DynamicKeywordStatementRule(token, keywordData); break; case TokenKind.Class: statement = ClassDefinitionRule(attributes, token); break; case TokenKind.Enum: statement = EnumDefinitionRule(attributes, token); break; case TokenKind.Using: statement = UsingStatementRule(token); // Report an error - usings must appear before anything else in the script, but parse it anyway ReportError(statement.Extent, () => ParserStrings.UsingMustBeAtStartOfScript); break; default: if (attributes != null) { Resync(restorePoint); } else { UngetToken(token); } statement = PipelineRule(); break; } return statement; }
public override AstVisitAction VisitErrorStatement(ErrorStatementAst ast) { return this.Check(ast); }
private StatementAst IfStatementRule(Token ifToken) { IScriptExtent extent; List<Tuple<PipelineBaseAst, StatementBlockAst>> tuples = new List<Tuple<PipelineBaseAst, StatementBlockAst>>(); List<Ast> asts = new List<Ast>(); StatementBlockAst statementBlockAst = null; Token token = ifToken; while (true) { this.SkipNewlines(); Token token1 = this.NextToken(); if (token1.Kind != TokenKind.LParen) { this.UngetToken(token1); object[] text = new object[1]; text[0] = token.Text; this.ReportIncompleteInput(Parser.After(token), ParserStrings.MissingOpenParenthesisInIfStatement, text); return new ErrorStatementAst(Parser.ExtentOf(ifToken, token), asts); } this.SkipNewlines(); PipelineBaseAst errorStatementAst = this.PipelineRule(); if (errorStatementAst != null) { asts.Add(errorStatementAst); } else { IScriptExtent scriptExtent = Parser.After(token1); object[] objArray = new object[1]; objArray[0] = token.Text; this.ReportIncompleteInput(scriptExtent, ParserStrings.IfStatementMissingCondition, objArray); errorStatementAst = new ErrorStatementAst(scriptExtent, (IEnumerable<Ast>)null); } this.SkipNewlines(); Token token2 = this.NextToken(); if (token2.Kind != TokenKind.RParen) { this.UngetToken(token2); if (errorStatementAst as ErrorStatementAst == null) { object[] text1 = new object[1]; text1[0] = token.Text; this.ReportIncompleteInput(token2.Extent, ParserStrings.MissingEndParenthesisAfterStatement, text1); } return new ErrorStatementAst(Parser.ExtentOf(ifToken, Parser.Before(token2)), asts); } this.SkipNewlines(); StatementBlockAst statementBlockAst1 = this.StatementBlockRule(); if (statementBlockAst1 == null) { object[] objArray1 = new object[1]; objArray1[0] = token.Text; this.ReportIncompleteInput(token2.Extent, ParserStrings.MissingStatementBlock, objArray1); return new ErrorStatementAst(Parser.ExtentOf(ifToken, token2), asts); } asts.Add(statementBlockAst1); tuples.Add(new Tuple<PipelineBaseAst, StatementBlockAst>(errorStatementAst, statementBlockAst1)); this.SkipNewlines(); token = this.PeekToken(); if (token.Kind != TokenKind.ElseIf) { break; } this.SkipToken(); } if (token.Kind == TokenKind.Else) { this.SkipToken(); this.SkipNewlines(); statementBlockAst = this.StatementBlockRule(); if (statementBlockAst == null) { this.ReportIncompleteInput(Parser.After(token), ParserStrings.MissingStatementBlockAfterElse, new object[0]); return new ErrorStatementAst(Parser.ExtentOf(ifToken, token), asts); } } if (statementBlockAst != null) { extent = statementBlockAst.Extent; } else { extent = tuples[tuples.Count - 1].Item2.Extent; } IScriptExtent scriptExtent1 = extent; IScriptExtent scriptExtent2 = Parser.ExtentOf(ifToken, scriptExtent1); return new IfStatementAst(scriptExtent2, tuples, statementBlockAst); }
public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { return AutomationNull.Value; }
private ExpressionAst ParenthesizedExpressionRule(Token lParen) { Token token; PipelineBaseAst errorStatementAst; TokenizerMode mode = this._tokenizer.Mode; bool flag = this._disableCommaOperator; try { this.SetTokenizerMode(TokenizerMode.Command); this._disableCommaOperator = false; this.SkipNewlines(); errorStatementAst = this.PipelineRule(); if (errorStatementAst == null) { IScriptExtent scriptExtent = Parser.After(lParen); this.ReportIncompleteInput(scriptExtent, ParserStrings.ExpectedExpression, new object[0]); errorStatementAst = new ErrorStatementAst(scriptExtent, (IEnumerable<Ast>)null); } this.SkipNewlines(); token = this.NextToken(); if (token.Kind != TokenKind.RParen) { this.UngetToken(token); this.ReportIncompleteInput(Parser.After(errorStatementAst), ParserStrings.MissingEndParenthesisInExpression, new object[0]); token = null; } } finally { this._disableCommaOperator = flag; this.SetTokenizerMode(mode); } object[] objArray = new object[2]; objArray[0] = token; objArray[1] = errorStatementAst; return new ParenExpressionAst(Parser.ExtentOf(lParen, Parser.ExtentFromFirstOf(objArray)), errorStatementAst); }
public virtual AstVisitAction VisitErrorStatement(ErrorStatementAst errorStatementAst) { return AstVisitAction.Continue; }
private PipelineBaseAst PipelineRule() { List<CommandBaseAst> source = new List<CommandBaseAst>(); IScriptExtent first = null; Token token = null; bool flag = true; while (flag) { CommandBaseAst ast; ExpressionAst ast2; Token token2 = null; TokenizerMode mode = this._tokenizer.Mode; try { this.SetTokenizerMode(TokenizerMode.Expression); ast2 = this.ExpressionRule(); if (ast2 != null) { Token token3 = this.PeekToken(); if (token3.Kind.HasTrait(TokenFlags.AssignmentOperator)) { this.SkipToken(); token2 = token3; } } } finally { this.SetTokenizerMode(mode); } if (ast2 != null) { if (source.Any<CommandBaseAst>()) { this.ReportError(ast2.Extent, ParserStrings.ExpressionsMustBeFirstInPipeline, new object[0]); } if (token2 != null) { this.SkipNewlines(); StatementAst right = this.StatementRule(); if (right == null) { IScriptExtent extent2 = After(token2); this.ReportIncompleteInput(extent2, ParserStrings.ExpectedValueExpression, new object[] { token2.Kind.Text() }); right = new ErrorStatementAst(extent2, (IEnumerable<Ast>)null); } return new AssignmentStatementAst(ExtentOf((Ast)ast2, (Ast)right), ast2, token2.Kind, right, token2.Extent); } RedirectionAst[] redirections = null; RedirectionToken redirectionToken = this.PeekToken() as RedirectionToken; RedirectionAst ast4 = null; while (redirectionToken != null) { this.SkipToken(); if (redirections == null) { redirections = new RedirectionAst[7]; } IScriptExtent extent3 = null; ast4 = this.RedirectionRule(redirectionToken, redirections, ref extent3); redirectionToken = this.PeekToken() as RedirectionToken; } IScriptExtent extent = (ast4 != null) ? ExtentOf((Ast)ast2, (Ast)ast4) : ast2.Extent; ast = new CommandExpressionAst(extent, ast2, (redirections != null) ? (from r in redirections where r != null select r) : null); } else { ast = this.CommandRule(); } if (ast != null) { if (first == null) { first = ast.Extent; } source.Add(ast); } else if (source.Any<CommandBaseAst>() || (this.PeekToken().Kind == TokenKind.Pipe)) { IScriptExtent extent5 = (token != null) ? After(token) : this.PeekToken().Extent; this.ReportIncompleteInput(extent5, ParserStrings.EmptyPipeElement, new object[0]); } token = this.PeekToken(); switch (token.Kind) { case TokenKind.NewLine: case TokenKind.EndOfInput: case TokenKind.RParen: case TokenKind.RCurly: case TokenKind.Semi: { flag = false; continue; } case TokenKind.AndAnd: case TokenKind.OrOr: { this.SkipToken(); this.SkipNewlines(); this.ReportError(token.Extent, ParserStrings.InvalidEndOfLine, new object[] { token.Text }); if (this.PeekToken().Kind == TokenKind.EndOfInput) { flag = false; } continue; } case TokenKind.Pipe: { this.SkipToken(); this.SkipNewlines(); if (this.PeekToken().Kind == TokenKind.EndOfInput) { flag = false; this.ReportIncompleteInput(After(token), ParserStrings.EmptyPipeElement, new object[0]); } continue; } } this.ReportError(token.Extent, ParserStrings.UnexpectedToken, new object[] { token.Text }); flag = false; } if (source.Count == 0) { return null; } return new PipelineAst(ExtentOf(first, source[source.Count - 1]), source); }
/// <summary/> public virtual object VisitErrorStatement(ErrorStatementAst errorStatementAst) { return _decorated.VisitErrorStatement(errorStatementAst); }
private StatementAst StatementRule() { StatementAst errorStatementAst; RuntimeHelpers.EnsureSufficientExecutionStack(); Token token = this.NextToken(); TokenKind kind = token.Kind; if (kind == TokenKind.Label) { this.SkipNewlines(); errorStatementAst = this.LabeledStatementRule((LabelToken)token); } else { if (kind == TokenKind.EndOfInput) { this.UngetToken(token); errorStatementAst = null; } else { switch (kind) { case TokenKind.Break: { errorStatementAst = this.BreakStatementRule(token); break; } case TokenKind.Catch: case TokenKind.Else: case TokenKind.ElseIf: case TokenKind.Until: { if (!this._errorList.Any<ParseError>()) { this.UngetToken(token); errorStatementAst = this.PipelineRule(); break; } this.SkipNewlines(); return this.StatementRule(); } case TokenKind.Class: case TokenKind.Define: case TokenKind.From: case TokenKind.Using: case TokenKind.Var: { object[] objArray = new object[1]; objArray[0] = token.Kind.Text(); this.ReportError(token.Extent, ParserStrings.ReservedKeywordNotAllowed, objArray); errorStatementAst = new ErrorStatementAst(token.Extent, (IEnumerable<Ast>)null); break; } case TokenKind.Continue: { errorStatementAst = this.ContinueStatementRule(token); break; } case TokenKind.Data: { errorStatementAst = this.DataStatementRule(token); break; } case TokenKind.Do: { errorStatementAst = this.DoWhileStatementRule(null, token); break; } case TokenKind.Dynamicparam: case TokenKind.End: case TokenKind.Finally: case TokenKind.In: case TokenKind.Param: case TokenKind.Process: { this.UngetToken(token); errorStatementAst = this.PipelineRule(); break; } case TokenKind.Exit: { errorStatementAst = this.ExitStatementRule(token); break; } case TokenKind.Filter: case TokenKind.Function: case TokenKind.Workflow: { errorStatementAst = this.FunctionDeclarationRule(token); break; } case TokenKind.For: { errorStatementAst = this.ForStatementRule(null, token); break; } case TokenKind.Foreach: { errorStatementAst = this.ForeachStatementRule(null, token); break; } case TokenKind.If: { errorStatementAst = this.IfStatementRule(token); break; } case TokenKind.Return: { errorStatementAst = this.ReturnStatementRule(token); break; } case TokenKind.Switch: { errorStatementAst = this.SwitchStatementRule(null, token); break; } case TokenKind.Throw: { errorStatementAst = this.ThrowStatementRule(token); break; } case TokenKind.Trap: { errorStatementAst = this.TrapStatementRule(token); break; } case TokenKind.Try: { errorStatementAst = this.TryStatementRule(token); break; } case TokenKind.While: { errorStatementAst = this.WhileStatementRule(null, token); break; } case TokenKind.Parallel: case TokenKind.Sequence: { errorStatementAst = this.BlockStatementRule(token); break; } default: { this.UngetToken(token); errorStatementAst = this.PipelineRule(); break; } } } } return errorStatementAst; }
public override AstVisitAction VisitErrorStatement(ErrorStatementAst ast) { return(Check(ast)); }
private StatementAst WhileStatementRule(LabelToken labelToken, Token whileToken) { string labelText; this.SkipNewlines(); Token token = this.NextToken(); if (token.Kind == TokenKind.LParen) { this.SkipNewlines(); PipelineBaseAst errorStatementAst = this.PipelineRule(); PipelineBaseAst pipelineBaseAst = null; if (errorStatementAst != null) { pipelineBaseAst = errorStatementAst; } else { IScriptExtent scriptExtent = Parser.After(token); object[] objArray = new object[1]; objArray[0] = whileToken.Kind.Text(); this.ReportIncompleteInput(scriptExtent, ParserStrings.MissingExpressionAfterKeyword, objArray); errorStatementAst = new ErrorStatementAst(scriptExtent, (IEnumerable<Ast>)null); } this.SkipNewlines(); Token token1 = this.NextToken(); if (token1.Kind == TokenKind.RParen) { this.SkipNewlines(); StatementBlockAst statementBlockAst = this.StatementBlockRule(); if (statementBlockAst != null) { LabelToken labelToken1 = labelToken; Token token2 = labelToken1; if (labelToken1 == null) { token2 = whileToken; } IScriptExtent scriptExtent1 = Parser.ExtentOf(token2, statementBlockAst); if (labelToken != null) { labelText = labelToken.LabelText; } else { labelText = null; } return new WhileStatementAst(scriptExtent1, labelText, errorStatementAst, statementBlockAst); } else { object[] objArray1 = new object[1]; objArray1[0] = whileToken.Kind.Text(); this.ReportIncompleteInput(Parser.After(token1), ParserStrings.MissingLoopStatement, objArray1); LabelToken labelToken2 = labelToken; Token token3 = labelToken2; if (labelToken2 == null) { token3 = whileToken; } object[] objArray2 = new object[1]; objArray2[0] = pipelineBaseAst; return new ErrorStatementAst(Parser.ExtentOf(token3, token1), Parser.GetNestedErrorAsts(objArray2)); } } else { this.UngetToken(token1); if (errorStatementAst as ErrorStatementAst == null) { object[] objArray3 = new object[1]; objArray3[0] = whileToken.Kind.Text(); this.ReportIncompleteInput(Parser.After(errorStatementAst), ParserStrings.MissingEndParenthesisAfterStatement, objArray3); } LabelToken labelToken3 = labelToken; Token token4 = labelToken3; if (labelToken3 == null) { token4 = whileToken; } object[] objArray4 = new object[1]; objArray4[0] = pipelineBaseAst; return new ErrorStatementAst(Parser.ExtentOf(token4, errorStatementAst), Parser.GetNestedErrorAsts(objArray4)); } } else { this.UngetToken(token); object[] text = new object[1]; text[0] = whileToken.Text; this.ReportIncompleteInput(Parser.After(whileToken), ParserStrings.MissingOpenParenthesisAfterKeyword, text); LabelToken labelToken4 = labelToken; Token token5 = labelToken4; if (labelToken4 == null) { token5 = whileToken; } return new ErrorStatementAst(Parser.ExtentOf(token5, whileToken), (IEnumerable<Ast>)null); } }
public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { return false; }
/// <summary/> public virtual AstVisitAction VisitErrorStatement(ErrorStatementAst errorStatementAst) => DefaultVisit(errorStatementAst);
/// <summary/> public virtual AstVisitAction VisitErrorStatement(ErrorStatementAst errorStatementAst) { return(AstVisitAction.Continue); }
public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { throw new UnexpectedElementException(); }
public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { return(false); }
public object VisitErrorStatement(ErrorStatementAst errorStatementAst) { throw new NotImplementedException(); }