From 56c643d3c28d870db055daa380b079484694687f Mon Sep 17 00:00:00 2001 From: Reda Al Sulais Date: Tue, 13 Feb 2024 15:13:58 +0300 Subject: [PATCH] use `AbstractMermaidTokenBuilder` in sankey token builder --- .../src/language/sankey/tokenBuilder.ts | 22 +++++-------------- .../src/language/sankey/valueConverter.ts | 1 + 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/parser/src/language/sankey/tokenBuilder.ts b/packages/parser/src/language/sankey/tokenBuilder.ts index e810e86c43..ff05e43eb7 100644 --- a/packages/parser/src/language/sankey/tokenBuilder.ts +++ b/packages/parser/src/language/sankey/tokenBuilder.ts @@ -1,10 +1,14 @@ import type { GrammarAST, Stream, TokenBuilderOptions } from 'langium'; -import { DefaultTokenBuilder } from 'langium'; import type { TokenType } from 'chevrotain'; +import { AbstractMermaidTokenBuilder } from '../common/index.js'; import { matchSankeyLinkNode } from './matcher.js'; -export class SankeyTokenBuilder extends DefaultTokenBuilder { +export class SankeyTokenBuilder extends AbstractMermaidTokenBuilder { + public constructor() { + super(['sankey-beta']); + } + protected override buildTerminalTokens(rules: Stream): TokenType[] { const tokenTypes: TokenType[] = super.buildTerminalTokens(rules); tokenTypes.forEach((tokenType: TokenType): void => { @@ -18,18 +22,4 @@ export class SankeyTokenBuilder extends DefaultTokenBuilder { }); return tokenTypes; } - - protected override buildKeywordTokens( - rules: Stream, - terminalTokens: TokenType[], - options?: TokenBuilderOptions - ): TokenType[] { - const tokenTypes: TokenType[] = super.buildKeywordTokens(rules, terminalTokens, options); - tokenTypes.forEach((tokenType: TokenType): void => { - if (tokenType.name === 'sankey-beta' && tokenType.PATTERN !== undefined) { - tokenType.PATTERN = new RegExp(tokenType.PATTERN.toString() + '(?!\\S)'); - } - }); - return tokenTypes; - } } diff --git a/packages/parser/src/language/sankey/valueConverter.ts b/packages/parser/src/language/sankey/valueConverter.ts index e6db03f186..c722d3f04f 100644 --- a/packages/parser/src/language/sankey/valueConverter.ts +++ b/packages/parser/src/language/sankey/valueConverter.ts @@ -23,6 +23,7 @@ export class SankeyValueConverter extends AbstractMermaidValueConverter { if (match === null) { return undefined; } + // source and target with double quote and value if (match[1] !== undefined) { if (rule.name === 'SANKEY_LINK_VALUE') {