Skip to content

Commit

Permalink
pref: remove rearrangeRules from AbstractMermaidTokenBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Yokozuna59 committed Dec 31, 2023
1 parent c2ea23f commit 54a09ea
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions packages/parser/src/language/common/tokenBuilder.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -11,14 +11,6 @@ export abstract class AbstractMermaidTokenBuilder extends DefaultTokenBuilder {
this.keywords = new Set<string>(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<GrammarAST.AbstractRule>,
terminalTokens: TokenType[],
Expand All @@ -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 {}

0 comments on commit 54a09ea

Please sign in to comment.