From 54a09ead95c9c7e2ecd4c364861f6fd0c2defcae Mon Sep 17 00:00:00 2001 From: Reda Al Sulais Date: Sun, 31 Dec 2023 15:31:15 +0300 Subject: [PATCH] pref: remove `rearrangeRules` from `AbstractMermaidTokenBuilder` --- .../src/language/common/tokenBuilder.ts | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/packages/parser/src/language/common/tokenBuilder.ts b/packages/parser/src/language/common/tokenBuilder.ts index d59249e197..f997634545 100644 --- a/packages/parser/src/language/common/tokenBuilder.ts +++ b/packages/parser/src/language/common/tokenBuilder.ts @@ -1,5 +1,5 @@ import type { GrammarAST, Stream, TokenBuilderOptions } from 'langium'; -import type { TokenType, TokenVocabulary } from 'chevrotain'; +import type { TokenType } from 'chevrotain'; import { DefaultTokenBuilder } from 'langium'; @@ -11,14 +11,6 @@ export abstract class AbstractMermaidTokenBuilder extends DefaultTokenBuilder { this.keywords = new Set(keywords); } - public override buildTokens( - grammar: GrammarAST.Grammar, - options?: TokenBuilderOptions | undefined - ): TokenVocabulary { - this.rearrangeRules(grammar.rules); - return super.buildTokens(grammar, options); - } - protected override buildKeywordTokens( rules: Stream, terminalTokens: TokenType[], @@ -33,28 +25,6 @@ export abstract class AbstractMermaidTokenBuilder extends DefaultTokenBuilder { }); return tokenTypes; } - - /** - * Reorders rules using a pivot rule. - * - * We use this function to reorder rules because imported rules are - * inserted at the end of the array. - * - * @param rules - the grammar rules. - */ - private rearrangeRules(rules: GrammarAST.AbstractRule[]): void { - const index = rules.findIndex((rule) => rule.name === 'TitleAndAccessibilities'); - if (index === -1) { - return; - } - - const [item] = rules.splice(index, 1); - - rules.unshift(item); - - const itemsToMove = rules.splice(1, index); - rules.push(...itemsToMove); - } } export class CommonTokenBuilder extends AbstractMermaidTokenBuilder {}