static void ShiftReturn(CleanupAstNodeStates cleanStates, int advancePosition) { var rightColon = cleanStates.MappedNodes.GeNextTokenKind(TokenKind.SemiColon, advancePosition); cleanStates.ReduceRangeOfTokensAsParent(advancePosition, rightColon, RuleKind.Return); }
static void ReduceImportRange(int pos, int endImport, string libraryToImport, CleanupAstNodeStates cleanStates) { var importSection = cleanStates.ReduceRangeOfTokensAsParent(pos, endImport, RuleKind.ImportLibraryDeclaration); importSection.Content = libraryToImport; var parentImportNode = cleanStates.MappedNodes[pos]; var importCleanStates = parentImportNode.States; var startFunctions = new List<int>(); var endFunctions = new List<int>(); FindImportFunctionRanges(importCleanStates, startFunctions, endFunctions); startFunctions.ReverseEachWithIndex((startPos, index) => { var endFunction = endFunctions[index]; importCleanStates.ReduceRangeOfTokensAsParent(startPos, endFunction, RuleKind.ImportFunction); }); }
static void ShiftStaticDefinition(CleanupAstNodeStates cleanStates, int advancePosition) { cleanStates.ShiftVariableDeclaration(advancePosition + 1); cleanStates.ReduceRangeOfTokensAsParent(advancePosition, advancePosition + 1, RuleKind.Static); }
static void ShiftCase(CleanupAstNodeStates cleanStates, int advancePosition) { var colon = cleanStates.GeNextTokenKind(TokenKind.Colon, advancePosition); var tokenAfterColon = cleanStates[colon + 1].Token; switch (tokenAfterColon) { case TokenKind.Continue: case TokenKind.Return: case TokenKind.Break: case TokenKind.Case: cleanStates.ShiftByNodeType(colon + 1); cleanStates.ReduceRangeOfTokensAsParent(colon + 1, colon + 1, RuleKind.CaseBlock); cleanStates.ReduceRangeOfTokensAsParent(advancePosition, colon + 1, RuleKind.Case); return; } var breakPos = cleanStates.GeNextTokenOfAny(new[] { TokenKind.Break, TokenKind.Return, TokenKind.Continue, TokenKind.Case, }, colon); if (breakPos == 0) { cleanStates.ReduceRangeOfTokensAsParent(colon + 1, cleanStates.Count - 2, RuleKind.CaseBlock); cleanStates.ReduceRangeOfTokensAsParent(advancePosition, colon + 1, RuleKind.Case); return; } var breakToken = cleanStates[breakPos].Token; switch (breakToken) { case TokenKind.Case: cleanStates.ReduceRangeOfTokensAsParent(colon + 1, breakPos - 1, RuleKind.CaseBlock); cleanStates.ReduceRangeOfTokensAsParent(advancePosition, colon + 1, RuleKind.Case); return; case TokenKind.Return: cleanStates.ShiftByNodeType(breakPos); cleanStates.ReduceRangeOfTokensAsParent(colon + 1, breakPos, RuleKind.CaseBlock); cleanStates.ReduceRangeOfTokensAsParent(advancePosition, colon + 1, RuleKind.Case); return; } cleanStates.ReduceRangeOfTokensAsParent(colon + 1, breakPos + 1, RuleKind.CaseBlock); cleanStates.ReduceRangeOfTokensAsParent(advancePosition, colon + 1, RuleKind.Case); }