Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create sankey parser and integrate sankey parser into mermaid package #4799

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7ca02da
feat: create `sankey` parser and integrate `sankey` parser into `merm…
Yokozuna59 Sep 2, 2023
a10821f
chore: remove sankey links map
Yokozuna59 Sep 2, 2023
9ad5536
chore: remove sankey links map
Yokozuna59 Sep 2, 2023
9a8963a
Merge branch 'next' into add-sankey-langium-parser
Yokozuna59 Sep 2, 2023
8feef1e
chore: `vi.mock` sankey renderer
Yokozuna59 Sep 2, 2023
efbb1f1
styles: refactor `switch..case` into `Record` for matcher regexes
Yokozuna59 Sep 2, 2023
b6906a6
fix: match until comments in `sankey` diagram
Yokozuna59 Sep 2, 2023
8c40eb3
Merge branch next into add-sankey-langium-parser
Yokozuna59 Sep 20, 2023
63430d2
pref(sankey): combine `source` and `target` rules as `node`
Yokozuna59 Sep 20, 2023
5fe951a
chore: update rule name of why we can't use default import in sankey
Yokozuna59 Sep 20, 2023
6187f4b
change test case with double quotes values
Yokozuna59 Sep 20, 2023
709ece5
Merge branch 'next' into add-sankey-langium-parser
Yokozuna59 Feb 12, 2024
aa9e875
update pnpm-lock.yaml
Yokozuna59 Feb 12, 2024
15c8bf8
update sankey parser tests
Yokozuna59 Feb 12, 2024
c364715
update the parser `index.ts` exports
Yokozuna59 Feb 12, 2024
32d82a6
add the approach from #4910 pr
Yokozuna59 Feb 12, 2024
bb84e17
change ISankeyLink into SankeyLink in sankeyDB
Yokozuna59 Feb 12, 2024
e51b7a4
modify sankye matcher
Yokozuna59 Feb 12, 2024
eb55e39
rename sankey langium parser files
Yokozuna59 Feb 12, 2024
4d035ed
simplify `sankey.langium`
Yokozuna59 Feb 13, 2024
56c643d
use `AbstractMermaidTokenBuilder` in sankey token builder
Yokozuna59 Feb 13, 2024
c0535f4
Merge branch 'develop' into add-sankey-langium-parser
Yokozuna59 Mar 24, 2024
0705aff
Merge branch 'develop' into add-sankey-langium-parser
Yokozuna59 Mar 24, 2024
bf95a30
fix lint:fix
Yokozuna59 Mar 24, 2024
434d154
remove unused imports
Yokozuna59 Mar 24, 2024
6c7b0f2
implement the greedy annotation approach
Yokozuna59 Mar 26, 2024
125ec46
Merge branch 'develop' into add-sankey-langium-parser
Yokozuna59 Mar 26, 2024
c9f6816
apply review suggestions
Yokozuna59 Mar 26, 2024
c155434
remove `utils.ts` and related unused imports
Yokozuna59 Apr 14, 2024
3597ffe
reorder sankey.langium rules
Yokozuna59 Apr 14, 2024
e080e96
Merge branch 'develop' into add-sankey-langium-parser
Yokozuna59 Apr 14, 2024
875c4fe
Merge branch 'develop' into add-sankey-langium-parser
Yokozuna59 Apr 15, 2024
51896f3
create separate test case for `CommonTokenBuilder`
Yokozuna59 Apr 15, 2024
8fa0509
run fix lint
Yokozuna59 Apr 15, 2024
681fbd0
Merge branch 'develop' into add-sankey-langium-parser
Yokozuna59 Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
create separate test case for CommonTokenBuilder
Yokozuna59 committed Apr 15, 2024
commit 51896f30f56cafc6bd1fddf09ae88b1762498c35
64 changes: 64 additions & 0 deletions packages/parser/tests/greedy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { createLangiumGrammarServices, createServicesForGrammar } from 'langium/grammar';
import { describe, expect, it } from 'vitest';
import { CommonTokenBuilder } from '../src/index.js';
import type { TokenType } from 'chevrotain';
import { EmptyFileSystem } from 'langium';

const grammarServices = createLangiumGrammarServices(EmptyFileSystem).grammar;

async function createServicesFromGrammar(grammar: string) {
const services = await createServicesForGrammar({
grammar,
module: {
parser: {
TokenBuilder: () => new CommonTokenBuilder([], grammarServices),
},
},
});

return {
grammar: services.Grammar,
tokenBuilder: services.parser.TokenBuilder,
};
}

describe('CommonTokenBuilder', async () => {
it('should handle grammar with one greedy rule', async () => {
const grammar = `
grammar TestGrammar
entry Rule:
'rule' value=(LessGreedy | Greedy);

hidden terminal WS: /\\s+/;

/** @greedy */
terminal Greedy: /[\\w\\d]+/;
terminal LessGreedy: /[\\w]+/;
`;
const services = await createServicesFromGrammar(grammar);
const tokens = services.tokenBuilder.buildTokens(services.grammar) as TokenType[];

expect(tokens[2].name).toBe('LessGreedy');
expect(tokens[3].name).toBe('Greedy');
});

it('should handle grammar with more than one greedy rule', async () => {
const grammar = `
grammar TestGrammar
entry Rule:
'rule' value=(LessGreedy | Greedy);

hidden terminal WS: /\\s+/;

/** @greedy */
terminal LessGreedy: /[\\w]+/;
/** @greedy */
terminal Greedy: /[\\w\\d]+/;
`;
const services = await createServicesFromGrammar(grammar);
const tokens = services.tokenBuilder.buildTokens(services.grammar) as TokenType[];

expect(tokens[2].name).toBe('LessGreedy');
expect(tokens[3].name).toBe('Greedy');
});
});
50 changes: 0 additions & 50 deletions packages/parser/tests/sankey-tokenBuilder.test.ts

This file was deleted.


Unchanged files with check annotations Beta

declare global {
interface Window {
mermaid: any; // 👈️ turn off type checking

Check warning on line 5 in packages/mermaid-example-diagram/src/types/index.d.ts

GitHub Actions / lint

Unexpected any. Specify a different type
}
}
let vertexText = vertex.text !== undefined ? vertex.text : vertex.id;
// We create a SVG label, either by delegating to addHtmlLabel or manually
let vertexNode;

Check warning on line 67 in packages/mermaid-flowchart-elk/src/flowRenderer-elk.js

GitHub Actions / lint

'vertexNode' is defined but never used
const labelData = { width: 0, height: 0 };
const ports = [
nodeEl = await insertNode(nodes, node, vertex.dir);
boundingBox = nodeEl.node().getBBox();
} else {
const svgLabel = doc.createElementNS('http://www.w3.org/2000/svg', 'text');

Check warning on line 191 in packages/mermaid-flowchart-elk/src/flowRenderer-elk.js

GitHub Actions / lint

'svgLabel' is assigned a value but never used
// svgLabel.setAttribute('style', styles.labelStyle.replace('color:', 'fill:'));
// const rows = vertexText.split(common.lineBreakRegex);
// for (const row of rows) {
* Add edges to graph based on parsed graph definition
*
* @param {object} edges The edges to add to the graph
* @param {object} g The graph object

Check warning on line 397 in packages/mermaid-flowchart-elk/src/flowRenderer-elk.js

GitHub Actions / lint

Expected @param names to be "edges, diagObj, graph, svg". Got "edges, g, cy, diagObj, graph, svg"
* @param cy
* @param diagObj
* @param graph
/**
* Recursive function that iterates over an array of nodes and inserts the children of each node.
* It also recursively populates the inserts the children of the children and so on.
* @param {*} graph

Check warning on line 680 in packages/mermaid-flowchart-elk/src/flowRenderer-elk.js

GitHub Actions / lint

Expected @param names to be "nodeArray, parentLookupDb". Got "graph, nodeArray, parentLookupDb"
* @param nodeArray
* @param parentLookupDb
*/
export let sanitizeText: (str: string) => string;
// eslint-disable @typescript-eslint/no-explicit-any
export let setupGraphViewbox: (
graph: any,

Check warning on line 34 in packages/mermaid-zenuml/src/mermaidUtils.ts

GitHub Actions / lint

Unexpected any. Specify a different type
svgElem: any,

Check warning on line 35 in packages/mermaid-zenuml/src/mermaidUtils.ts

GitHub Actions / lint

Unexpected any. Specify a different type
padding: any,

Check warning on line 36 in packages/mermaid-zenuml/src/mermaidUtils.ts

GitHub Actions / lint

Unexpected any. Specify a different type
useMaxWidth: boolean
) => void;
export const injectUtils = (
_log: Record<keyof typeof LEVELS, typeof console.log>,
_setLogLevel: any,

Check warning on line 42 in packages/mermaid-zenuml/src/mermaidUtils.ts

GitHub Actions / lint

Unexpected any. Specify a different type
_getConfig: any,

Check warning on line 43 in packages/mermaid-zenuml/src/mermaidUtils.ts

GitHub Actions / lint

Unexpected any. Specify a different type
_sanitizeText: any,
_setupGraphViewbox: any
) => {
/**
* Declaration of `Sankey` services.
*/
export type SankeyAddedServices = {

Check failure on line 24 in packages/parser/src/language/sankey/module.ts

GitHub Actions / lint

Use an `interface` instead of a `type`
parser: {
LangiumParser: LangiumParser;
TokenBuilder: SankeyTokenBuilder;