Skip to content

Commit

Permalink
use AbstractMermaidTokenBuilder in sankey token builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Yokozuna59 committed Feb 13, 2024
1 parent 4d035ed commit 56c643d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
22 changes: 6 additions & 16 deletions packages/parser/src/language/sankey/tokenBuilder.ts
Original file line number Diff line number Diff line change
@@ -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<GrammarAST.AbstractRule>): TokenType[] {
const tokenTypes: TokenType[] = super.buildTerminalTokens(rules);
tokenTypes.forEach((tokenType: TokenType): void => {
Expand All @@ -18,18 +22,4 @@ export class SankeyTokenBuilder extends DefaultTokenBuilder {
});
return tokenTypes;
}

protected override buildKeywordTokens(
rules: Stream<GrammarAST.AbstractRule>,
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;
}
}
1 change: 1 addition & 0 deletions packages/parser/src/language/sankey/valueConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit 56c643d

Please sign in to comment.