public static bool TryParseNode(Genero4glParser parser, out CatchBlock node, IModuleResult containingModule, List <Func <PrepareStatement, bool> > prepStatementBinders, Func <ReturnStatement, ParserResult> returnStatementBinder = null, Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null, List <TokenKind> validExitKeywords = null, IEnumerable <ContextStatementFactory> contextStatementFactories = null, HashSet <TokenKind> endKeywords = null) { node = new CatchBlock(); node.StartIndex = parser.Token.Span.Start; prepStatementBinders.Insert(0, node.BindPrepareCursorFromIdentifier); while (!parser.PeekToken(TokenKind.EndOfFile) && !(parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.TryKeyword, 2))) { FglStatement statement; if (parser.StatementFactory.TryParseNode(parser, out statement, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, false, validExitKeywords, contextStatementFactories, null, endKeywords) && statement != null) { AstNode4gl stmtNode = statement as AstNode4gl; node.Children.Add(stmtNode.StartIndex, stmtNode); } else if (parser.PeekToken(TokenKind.EndKeyword) && endKeywords != null && endKeywords.Contains(parser.PeekToken(2).Kind)) { break; } else { parser.NextToken(); } } prepStatementBinders.RemoveAt(0); node.EndIndex = parser.Token.Span.End; return(true); }
public static bool TryParseNode(Genero4glParser parser, out TryCatchStatement defNode, IModuleResult containingModule, List <Func <PrepareStatement, bool> > prepStatementBinders, Func <ReturnStatement, ParserResult> returnStatementBinder = null, Action <IAnalysisResult, int, int> limitedScopeVariableAdder = null, List <TokenKind> validExitKeywords = null, IEnumerable <ContextStatementFactory> contextStatementFactories = null, HashSet <TokenKind> endKeywords = null) { defNode = null; bool result = false; if (parser.PeekToken(TokenKind.TryKeyword)) { result = true; defNode = new TryCatchStatement(); parser.NextToken(); defNode.StartIndex = parser.Token.Span.Start; defNode.DecoratorEnd = parser.Token.Span.End; HashSet <TokenKind> newEndKeywords = new HashSet <TokenKind>(); if (endKeywords != null) { newEndKeywords.AddRange(endKeywords); } newEndKeywords.Add(TokenKind.TryKeyword); prepStatementBinders.Insert(0, defNode.BindPrepareCursorFromIdentifier); TryBlock tryBlock; if (TryBlock.TryParseNode(parser, out tryBlock, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, newEndKeywords) && tryBlock != null) { defNode.Children.Add(tryBlock.StartIndex, tryBlock); } if (parser.PeekToken(TokenKind.CatchKeyword)) { parser.NextToken(); CatchBlock catchBlock; if (CatchBlock.TryParseNode(parser, out catchBlock, containingModule, prepStatementBinders, returnStatementBinder, limitedScopeVariableAdder, validExitKeywords, contextStatementFactories, newEndKeywords) && catchBlock != null) { defNode.Children.Add(catchBlock.StartIndex, catchBlock); // add the catch block to the additional decorators defNode.AdditionalDecoratorRanges.Add(catchBlock.StartIndex, catchBlock.StartIndex + 5); } } prepStatementBinders.RemoveAt(0); if (parser.PeekToken(TokenKind.EndKeyword) && parser.PeekToken(TokenKind.TryKeyword, 2)) { parser.NextToken(); parser.NextToken(); } else { parser.ReportSyntaxError("Invalid end of try-catch block found."); } defNode.EndIndex = parser.Token.Span.End; } return(result); }