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