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: add pie langium parser #4751

Merged
merged 53 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
49c5f3b
feat(parser): create `pie` parser and export it
Yokozuna59 Aug 20, 2023
1c8e13b
feat: integrate `pir` parser into `mermaid` package
Yokozuna59 Aug 20, 2023
341db13
chore!: rename `D3Sections` type into `D3Section`
Yokozuna59 Aug 20, 2023
d0c36c0
chore!: change `addSection` header into `D3Section`
Yokozuna59 Aug 20, 2023
258dbf3
Merge branch 'next' into pr/Yokozuna59/4751
sidharthv96 Aug 28, 2023
146364a
chore: Fix imports
sidharthv96 Aug 28, 2023
dff404a
Update docs
sidharthv96 Aug 28, 2023
23fc7c2
Update packages/parser/src/language/pie/pieValueConverter.ts
Yokozuna59 Aug 28, 2023
5469a7e
Update packages/mermaid/src/diagrams/pie/pieParser.ts
Yokozuna59 Aug 28, 2023
795baed
chore: run `pnpm lint:fix`
Yokozuna59 Aug 28, 2023
24d4384
chore: apply review suggestions
Yokozuna59 Sep 6, 2023
fedbd48
Merge branch 'next' into pr/Yokozuna59/4751
sidharthv96 Sep 14, 2023
8c31db6
Merge branch 'next' into add-pie-langium-parser
Yokozuna59 Sep 20, 2023
0184403
build(deps): remove `langium-cli` from `packages/parser` to use the o…
Yokozuna59 Nov 3, 2023
6a4ad8a
build(deps): update `langium` and `langium-cli` to `v2.1.0`
Yokozuna59 Nov 3, 2023
55d7e9e
pref: remove `CommonLexer` and use `EOF`
Yokozuna59 Nov 3, 2023
7765afa
chore: allow comments to adjust keywords
Yokozuna59 Nov 3, 2023
fe2e46f
build(dev-deps): add `chevrotain` as a `devDependencies`
Yokozuna59 Nov 3, 2023
1cda376
chore(parser): rearrange rules to make imported rules at the beginning
Yokozuna59 Nov 3, 2023
922bb14
test: update all parser test cases
Yokozuna59 Nov 3, 2023
0a62691
remove unnecessary lines
Yokozuna59 Nov 3, 2023
58c7934
export necessary objects and types from `packages/parser`
Yokozuna59 Nov 3, 2023
53ef5c5
create `CommonTokenBuilder`
Yokozuna59 Nov 3, 2023
5ef0527
export all common `ValueConverter` and `TokenBuilder` and update imports
Yokozuna59 Nov 3, 2023
0c57433
Merge branch 'next' into add-pie-langium-parser
Yokozuna59 Nov 3, 2023
cf18803
fix: make `rearrangeRules` update the array itself
Yokozuna59 Nov 4, 2023
c62be1b
export necessary functions and types from `packages/parser`
Yokozuna59 Nov 4, 2023
f01971b
switch to `NEWLINE+` instead of `EOF` until next release of `langium`
Yokozuna59 Nov 4, 2023
cf22e30
rename abstract rules in common parser files
Yokozuna59 Nov 5, 2023
b836034
build(deps): update `langium` to `v2.1.1`
Yokozuna59 Nov 6, 2023
6102285
full switch to EOF
Yokozuna59 Nov 6, 2023
1d88ac4
enhance `title`, `accTitle`, and `accDescr` regexes
Yokozuna59 Nov 6, 2023
4c43bae
Merge branch next into add-pie-langium-parser
Yokozuna59 Nov 14, 2023
692a747
chore: apply review changes
Yokozuna59 Nov 15, 2023
e86f09a
Apply suggested style from code review
Yokozuna59 Nov 15, 2023
f0d6789
fix: Netlify build
sidharthv96 Nov 16, 2023
c2ea23f
Merge branch next into add-pie-langium-parser
Yokozuna59 Dec 31, 2023
54a09ea
pref: remove `rearrangeRules` from `AbstractMermaidTokenBuilder`
Yokozuna59 Dec 31, 2023
526d2a6
Merge branch 'mermaid-js:develop' into add-pie-langium-parser
Yokozuna59 Jan 2, 2024
c7eaee0
Merge branch next into add-sankey-langium-parser
Yokozuna59 Jan 20, 2024
0dcca35
Update docs
Yokozuna59 Jan 20, 2024
5c46b98
Merge branch 'next' into pr/Yokozuna59/4751
sidharthv96 Jan 23, 2024
16968eb
Fix lint
sidharthv96 Jan 23, 2024
47a6ce4
Update docs
Yokozuna59 Jan 20, 2024
55be75c
Merge branch next into add-pie-langium-parser
Yokozuna59 Jan 25, 2024
a2a9948
Merge branch 'mermaid-js:develop' into add-pie-langium-parser
Yokozuna59 Jan 27, 2024
72a6fad
Merge branch next into add-pie-langium-parser
Yokozuna59 Jan 27, 2024
191ea24
make pie parser async
Yokozuna59 Jan 27, 2024
b30d609
Merge branch 'add-pie-langium-parser' of github.com:Yokozuna59/mermai…
sidharthv96 Feb 11, 2024
48ff3b2
Merge branch 'next' into pr/Yokozuna59/4751
sidharthv96 Feb 11, 2024
00423ed
Fix config
sidharthv96 Feb 11, 2024
062176d
Merge branch 'next' into pr/Yokozuna59/4751
sidharthv96 Feb 11, 2024
25cd86f
Fix docs
sidharthv96 Feb 11, 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
9 changes: 0 additions & 9 deletions .build/langium-cli.d.ts

This file was deleted.

24 changes: 12 additions & 12 deletions docs/intro/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,18 @@ In this example, the `mermaidAPI` is being called through the `CDN`:
<body>
Here is one mermaid diagram:
<pre class="mermaid">
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server1]
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server1]
B --> D[Server2]
</pre>

And here is another:
<pre class="mermaid">
graph TD
graph TD
A[Client] -->|tcp_123| B
B(Load Balancer)
B -->|tcp_456| C[Server1]
B(Load Balancer)
B -->|tcp_456| C[Server1]
B -->|tcp_456| D[Server2]
</pre>

Expand All @@ -278,15 +278,15 @@ In this example, `mermaid.js` is referenced in `src` as a separate JavaScript fi
</head>
<body>
<pre class="mermaid">
graph LR
A --- B
B-->C[fa:fa-ban forbidden]
graph LR
A --- B
B-->C[fa:fa-ban forbidden]
B-->D(fa:fa-spinner);
</pre>
<pre class="mermaid">
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server1]
graph TD
A[Client] --> B[Load Balancer]
B --> C[Server1]
B --> D[Server2]
</pre>
<script type="module">
Expand Down
4 changes: 2 additions & 2 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
base = ""

# Directory that contains the deploy-ready HTML files and
# assets generated by the build. This is an absolute path relative
# assets generated by the build. This is an absolute path relative
# to the base directory, which is the root by default (/).
# This sample publishes the directory located at the absolute
# This sample publishes the directory located at the absolute
# path "root/project/build-output"

publish = "mermaid-live-editor/docs"
Expand Down
74 changes: 0 additions & 74 deletions packages/mermaid/src/diagrams/pie/parser/pie.jison

This file was deleted.

53 changes: 23 additions & 30 deletions packages/mermaid/src/diagrams/pie/pie.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-ignore: JISON doesn't support types
import { parser } from './parser/pie.jison';
import { parser } from './pieParser.js';
import { DEFAULT_PIE_DB, db } from './pieDb.js';
import { setConfig } from '../../diagram-api/diagramAPI.js';

Expand All @@ -8,26 +7,20 @@ setConfig({
});

describe('pie', () => {
beforeAll(() => {
parser.yy = db;
});

beforeEach(() => {
parser.yy.clear();
});
beforeEach(() => db.clear());

describe('parse', () => {
it('should handle very simple pie', () => {
parser.parse(`pie
it('should handle very simple pie', async () => {
await parser.parse(`pie
"ash": 100
`);

const sections = db.getSections();
expect(sections['ash']).toBe(100);
});

it('should handle simple pie', () => {
parser.parse(`pie
it('should handle simple pie', async () => {
await parser.parse(`pie
"ash" : 60
"bat" : 40
`);
Expand All @@ -37,8 +30,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with showData', () => {
parser.parse(`pie showData
it('should handle simple pie with showData', async () => {
await parser.parse(`pie showData
"ash" : 60
"bat" : 40
`);
Expand All @@ -50,8 +43,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with comments', () => {
parser.parse(`pie
it('should handle simple pie with comments', async () => {
await parser.parse(`pie
%% comments
"ash" : 60
"bat" : 40
Expand All @@ -62,8 +55,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with a title', () => {
parser.parse(`pie title a 60/40 pie
it('should handle simple pie with a title', async () => {
await parser.parse(`pie title a 60/40 pie
"ash" : 60
"bat" : 40
`);
Expand All @@ -75,8 +68,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with an acc title (accTitle)', () => {
parser.parse(`pie title a neat chart
it('should handle simple pie with an acc title (accTitle)', async () => {
await parser.parse(`pie title a neat chart
accTitle: a neat acc title
"ash" : 60
"bat" : 40
Expand All @@ -91,8 +84,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with an acc description (accDescr)', () => {
parser.parse(`pie title a neat chart
it('should handle simple pie with an acc description (accDescr)', async () => {
await parser.parse(`pie title a neat chart
accDescr: a neat description
"ash" : 60
"bat" : 40
Expand All @@ -107,8 +100,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with a multiline acc description (accDescr)', () => {
parser.parse(`pie title a neat chart
it('should handle simple pie with a multiline acc description (accDescr)', async () => {
await parser.parse(`pie title a neat chart
accDescr {
a neat description
on multiple lines
Expand All @@ -126,8 +119,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with positive decimal', () => {
parser.parse(`pie
it('should handle simple pie with positive decimal', async () => {
await parser.parse(`pie
"ash" : 60.67
"bat" : 40
`);
Expand All @@ -138,12 +131,12 @@ describe('pie', () => {
});

it('should handle simple pie with negative decimal', () => {
expect(() => {
parser.parse(`pie
expect(async () => {
await parser.parse(`pie
"ash" : -60.67
"bat" : 40.12
`);
}).toThrowError();
}).rejects.toThrowError();
});
});

Expand Down
15 changes: 2 additions & 13 deletions packages/mermaid/src/diagrams/pie/pieDb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { log } from '../../logger.js';
import { getConfig as commonGetConfig } from '../../diagram-api/diagramAPI.js';
import { sanitizeText } from '../common/common.js';
import {
setAccTitle,
getAccTitle,
Expand All @@ -10,7 +8,7 @@ import {
setAccDescription,
clear as commonClear,
} from '../common/commonDb.js';
import type { PieFields, PieDB, Sections } from './pieTypes.js';
import type { PieFields, PieDB, Sections, D3Section } from './pieTypes.js';
import type { RequiredDeep } from 'type-fest';
import type { PieDiagramConfig } from '../../config.type.js';
import DEFAULT_CONFIG from '../../defaultConfig.js';
Expand All @@ -35,8 +33,7 @@ const clear = (): void => {
commonClear();
};

const addSection = (label: string, value: number): void => {
label = sanitizeText(label, commonGetConfig());
const addSection = ({ label, value }: D3Section): void => {
if (sections[label] === undefined) {
sections[label] = value;
log.debug(`added new section: ${label}, with value: ${value}`);
Expand All @@ -45,13 +42,6 @@ const addSection = (label: string, value: number): void => {

const getSections = (): Sections => sections;

const cleanupValue = (value: string): number => {
if (value.substring(0, 1) === ':') {
value = value.substring(1).trim();
}
return Number(value.trim());
};

const setShowData = (toggle: boolean): void => {
showData = toggle;
};
Expand All @@ -71,7 +61,6 @@ export const db: PieDB = {

addSection,
getSections,
cleanupValue,
setShowData,
getShowData,
};
3 changes: 1 addition & 2 deletions packages/mermaid/src/diagrams/pie/pieDiagram.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/pie.jison';
import { parser } from './pieParser.js';
import { db } from './pieDb.js';
import styles from './pieStyles.js';
import { renderer } from './pieRenderer.js';
Expand Down
21 changes: 21 additions & 0 deletions packages/mermaid/src/diagrams/pie/pieParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Pie } from '@mermaid-js/parser';
import { parse } from '@mermaid-js/parser';
import { log } from '../../logger.js';
import type { ParserDefinition } from '../../diagram-api/types.js';
import { populateCommonDb } from '../common/populateCommonDb.js';
import type { PieDB } from './pieTypes.js';
import { db } from './pieDb.js';

const populateDb = (ast: Pie, db: PieDB) => {
populateCommonDb(ast, db);
db.setShowData(ast.showData);
ast.sections.map(db.addSection);
};

export const parser: ParserDefinition = {
parse: async (input: string): Promise<void> => {
const ast: Pie = await parse('pie', input);
log.debug(ast);
populateDb(ast, db);
},
};
Loading
Loading