mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 15:59:51 +02:00
Implementing new syntax
This commit is contained in:
@@ -100,9 +100,9 @@ a -> {
|
||||
30
|
||||
40
|
||||
} -> b -> {
|
||||
20 -> d
|
||||
50 -> e
|
||||
}
|
||||
20 -> d -> 11
|
||||
50 -> e -> 11
|
||||
} -> f -> 30
|
||||
```
|
||||
|
||||
**Probably ambiguous!**
|
||||
|
@@ -2,13 +2,21 @@
|
||||
%lex
|
||||
|
||||
%options case-insensitive
|
||||
%s group
|
||||
// %x attributes
|
||||
|
||||
%%
|
||||
"{" { this.pushState('group'); return 'OPEN_GROUP'; }
|
||||
<group>"}" { this.popState('group'); return 'CLOSE_GROUP'; }
|
||||
"sankey" return 'SANKEY'
|
||||
\d+ return 'VALUE'
|
||||
"->" return 'ARROW'
|
||||
\w+ return 'NODE'
|
||||
[\n]+ return 'NEWLINE';
|
||||
\s+ /* skip all whitespace */
|
||||
"[" {/*this.pushState('attributes');*/ return 'OPEN_ATTRIBUTES'; }
|
||||
"]" { /* this.popState(); */ return 'CLOSE_ATTRIBUTES'; }
|
||||
(<<EOF>>|[\n;])+ return 'EOS' // end of statement
|
||||
\s+ // skip all whitespace
|
||||
// [\n]+ return 'NEWLINE';
|
||||
|
||||
// TODO: check if jison will return 2 separate tokens (for nodes) while ignoring whitespace
|
||||
|
||||
@@ -16,15 +24,50 @@
|
||||
|
||||
%start start
|
||||
|
||||
%% /* language grammar */
|
||||
%% // language grammar
|
||||
|
||||
start
|
||||
: SPACE start
|
||||
: EOS SANKEY document
|
||||
| SANKEY document
|
||||
;
|
||||
|
||||
document
|
||||
: node document
|
||||
| /* empty */
|
||||
: line document
|
||||
| // empty
|
||||
;
|
||||
|
||||
line
|
||||
// : node_with_attributes // one node with attributes
|
||||
: flow EOS
|
||||
| node_with_attributes EOS
|
||||
| EOS
|
||||
;
|
||||
|
||||
|
||||
node_with_attributes
|
||||
: NODE
|
||||
| NODE attributes_group
|
||||
;
|
||||
|
||||
attributes_group
|
||||
: OPEN_ATTRIBUTES attributes CLOSE_ATTRIBUTES
|
||||
;
|
||||
|
||||
attributes:
|
||||
| // TODO
|
||||
;
|
||||
|
||||
flow
|
||||
: NODE ARROW value_or_values_group ARROW flow
|
||||
| NODE
|
||||
;
|
||||
|
||||
value_or_values_group
|
||||
: OPEN_GROUP values CLOSE_GROUP
|
||||
| VALUE
|
||||
;
|
||||
|
||||
values
|
||||
: values VALUE
|
||||
| /* empty */
|
||||
;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import diagram from './sankey.jison';
|
||||
import { parser } from './sankey.jison';
|
||||
import db from '../sankeyDB.js';
|
||||
// import { fail } from 'assert';
|
||||
|
||||
describe('Sankey diagram', function () {
|
||||
// TODO - these examples should be put into ./parser/stateDiagram.spec.js
|
||||
@@ -11,37 +12,102 @@ describe('Sankey diagram', function () {
|
||||
diagram.parser.yy.clear();
|
||||
});
|
||||
|
||||
it('recognized its type', function() {
|
||||
it('recognizes its type', () => {
|
||||
const str=`sankey`;
|
||||
|
||||
parser.parse(str);
|
||||
});
|
||||
|
||||
// it('one simple flow', function () {
|
||||
it('recognizes one flow', () => {
|
||||
const str = `
|
||||
sankey
|
||||
a -> 30 -> b -> 20 -> c
|
||||
`;
|
||||
|
||||
parser.parse(str);
|
||||
});
|
||||
|
||||
it('recognizes multiple flows', () => {
|
||||
const str = `
|
||||
sankey
|
||||
a -> 30 -> b -> 12 -> e
|
||||
c -> 30 -> d -> 12 -> e
|
||||
c -> 40 -> e -> 12 -> e
|
||||
`;
|
||||
|
||||
parser.parse(str);
|
||||
});
|
||||
|
||||
it('recognizes grouped values', () => {
|
||||
const str = `
|
||||
sankey
|
||||
a -> {30} -> b
|
||||
`;
|
||||
|
||||
parser.parse(str);
|
||||
});
|
||||
|
||||
it('recognizes a separate node with its attributes', () => {
|
||||
const str = `
|
||||
sankey
|
||||
c[]
|
||||
`;
|
||||
|
||||
parser.parse(str);
|
||||
});
|
||||
|
||||
// it('recognizes intake group', () => {
|
||||
// const str = `
|
||||
// sankey
|
||||
// a -> 30 -> b
|
||||
// a -> {
|
||||
// 30 -> b
|
||||
// 40 -> c
|
||||
// }
|
||||
// `;
|
||||
|
||||
// parser.parse(str);
|
||||
// });
|
||||
|
||||
// it('multiple flows', function () {
|
||||
// it('recognizes exhaust group', () => {
|
||||
// const str = `
|
||||
// sankey
|
||||
// a -> 30 -> b
|
||||
// c -> 30 -> d
|
||||
// c -> 40 -> e
|
||||
// {
|
||||
// b -> 30
|
||||
// c -> 40
|
||||
// } -> a
|
||||
// `;
|
||||
|
||||
// parser.parse(str);
|
||||
// });
|
||||
|
||||
// it('multiple flows', function () {
|
||||
// it('what to do?', () => {
|
||||
// const str = `
|
||||
// sankey
|
||||
// a -> 30 -> b
|
||||
// c -> 30 -> d
|
||||
// {
|
||||
// b -> 30
|
||||
// c -> 40
|
||||
// } -> {
|
||||
// e
|
||||
// d
|
||||
// }
|
||||
// `;
|
||||
|
||||
// parser.parse(str);
|
||||
// });
|
||||
|
||||
// it('complex', () => {
|
||||
// const str = `
|
||||
// sankey
|
||||
// {
|
||||
// a -> 30
|
||||
// b -> 40
|
||||
// } -> c -> {
|
||||
// 20 -> e -> 49
|
||||
// 20 -> d -> 23
|
||||
// } -> k -> 20 -> i -> {
|
||||
// 10 -> f
|
||||
// 11 -> j
|
||||
// }
|
||||
// `;
|
||||
|
||||
// parser.parse(str);
|
||||
|
10
run
10
run
@@ -14,15 +14,19 @@ $RUN mermaid sh $args
|
||||
;;
|
||||
|
||||
i | install)
|
||||
$RUN mermaid sh -c "npx pnpm install"
|
||||
$RUN mermaid sh -c "npx pnpm install $args"
|
||||
;;
|
||||
|
||||
test)
|
||||
$RUN mermaid sh -c "npx pnpm test"
|
||||
$RUN mermaid sh -c "npx pnpm test $args"
|
||||
;;
|
||||
|
||||
vitest)
|
||||
$RUN mermaid sh -c "npx pnpm vitest $args"
|
||||
;;
|
||||
|
||||
e2e)
|
||||
$RUN mermaid sh -c "npx pnpm e2e"
|
||||
$RUN mermaid sh -c "npx pnpm e2e $args"
|
||||
;;
|
||||
|
||||
lint)
|
||||
|
Reference in New Issue
Block a user