mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 23:09:49 +02:00
25 lines
914 B
TypeScript
25 lines
914 B
TypeScript
import type { GrammarAST, Stream, TokenBuilderOptions } from 'langium';
|
|
import { DefaultTokenBuilder } from 'langium';
|
|
|
|
import type { TokenType } from '../chevrotainWrapper.js';
|
|
|
|
export class InfoTokenBuilder extends DefaultTokenBuilder {
|
|
protected override buildKeywordTokens(
|
|
rules: Stream<GrammarAST.AbstractRule>,
|
|
terminalTokens: TokenType[],
|
|
options?: TokenBuilderOptions
|
|
): TokenType[] {
|
|
const tokenTypes: TokenType[] = super.buildKeywordTokens(rules, terminalTokens, options);
|
|
// to restrict users, they mustn't have any non-whitespace characters after the keyword.
|
|
tokenTypes.forEach((tokenType: TokenType): void => {
|
|
if (
|
|
(tokenType.name === 'info' || tokenType.name === 'showInfo') &&
|
|
tokenType.PATTERN !== undefined
|
|
) {
|
|
tokenType.PATTERN = new RegExp(tokenType.PATTERN.toString() + '(?!\\S)');
|
|
}
|
|
});
|
|
return tokenTypes;
|
|
}
|
|
}
|