mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
pref: remove rearrangeRules
from AbstractMermaidTokenBuilder
This commit is contained in:
parent
c2ea23f01f
commit
54a09ead95
@ -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<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[],
|
||||
@ -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 {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user