mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-20 06:29:43 +02:00
Updated sequence diagram parsing with the new syntax
This commit is contained in:
@@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
// Directive states
|
// Directive states
|
||||||
%x open_directive type_directive arg_directive
|
%x open_directive type_directive arg_directive
|
||||||
|
%x acc_title
|
||||||
|
%x acc_descr
|
||||||
|
%x acc_descr_multiline
|
||||||
%%
|
%%
|
||||||
|
|
||||||
\%\%\{ { this.begin('open_directive'); return 'open_directive'; }
|
\%\%\{ { this.begin('open_directive'); return 'open_directive'; }
|
||||||
@@ -59,7 +61,13 @@
|
|||||||
"deactivate" { this.begin('ID'); return 'deactivate'; }
|
"deactivate" { this.begin('ID'); return 'deactivate'; }
|
||||||
"title"\s[^#\n;]+ return 'title';
|
"title"\s[^#\n;]+ return 'title';
|
||||||
"title:"\s[^#\n;]+ return 'legacy_title';
|
"title:"\s[^#\n;]+ return 'legacy_title';
|
||||||
"accDescription"\s[^#\n;]+ return 'accDescription';
|
accTitle\s*":"\s* { this.begin("acc_title");return 'acc_title'; }
|
||||||
|
<acc_title>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_title_value"; }
|
||||||
|
accDescr\s*":"\s* { this.begin("acc_descr");return 'acc_descr'; }
|
||||||
|
<acc_descr>(?!\n|;|#)*[^\n]* { this.popState(); return "acc_descr_value"; }
|
||||||
|
accDescr\s*"{"\s* { this.begin("acc_descr_multiline");}
|
||||||
|
<acc_descr_multiline>[\}] { this.popState(); }
|
||||||
|
<acc_descr_multiline>[^\}]* return "acc_descr_multiline_value";
|
||||||
"sequenceDiagram" return 'SD';
|
"sequenceDiagram" return 'SD';
|
||||||
"autonumber" return 'autonumber';
|
"autonumber" return 'autonumber';
|
||||||
"off" return 'off';
|
"off" return 'off';
|
||||||
@@ -130,7 +138,9 @@ statement
|
|||||||
| details_statement 'NEWLINE'
|
| details_statement 'NEWLINE'
|
||||||
| title {yy.setTitle($1.substring(6));$$=$1.substring(6);}
|
| title {yy.setTitle($1.substring(6));$$=$1.substring(6);}
|
||||||
| legacy_title {yy.setTitle($1.substring(7));$$=$1.substring(7);}
|
| legacy_title {yy.setTitle($1.substring(7));$$=$1.substring(7);}
|
||||||
| accDescription {yy.setAccDescription($1.substring(15));$$=$1.substring(15);}
|
| acc_title acc_title_value { console.log('acc_title');$$=$2.trim();yy.setTitle($$); }
|
||||||
|
| acc_descr acc_descr_value { console.log('acc_descr');$$=$2.trim();yy.setAccDescription($$); }
|
||||||
|
| acc_descr_multiline_value { console.log('acc_descr_multiline_value');$$=$1.trim();yy.setAccDescription($$); }
|
||||||
| 'loop' restOfLine document end
|
| 'loop' restOfLine document end
|
||||||
{
|
{
|
||||||
$3.unshift({type: 'loopStart', loopText:yy.parseMessage($2), signalType: yy.LINETYPE.LOOP_START});
|
$3.unshift({type: 'loopStart', loopText:yy.parseMessage($2), signalType: yy.LINETYPE.LOOP_START});
|
||||||
|
@@ -2,6 +2,13 @@ import mermaidAPI from '../../mermaidAPI';
|
|||||||
import * as configApi from '../../config';
|
import * as configApi from '../../config';
|
||||||
import { log } from '../../logger';
|
import { log } from '../../logger';
|
||||||
import { sanitizeText } from '../common/common';
|
import { sanitizeText } from '../common/common';
|
||||||
|
import {
|
||||||
|
setTitle,
|
||||||
|
getTitle,
|
||||||
|
getAccDescription,
|
||||||
|
setAccDescription,
|
||||||
|
clear as commonClear,
|
||||||
|
} from '../../commonDb';
|
||||||
|
|
||||||
let prevActor = undefined;
|
let prevActor = undefined;
|
||||||
let actors = {};
|
let actors = {};
|
||||||
@@ -119,9 +126,6 @@ export const getActor = function (id) {
|
|||||||
export const getActorKeys = function () {
|
export const getActorKeys = function () {
|
||||||
return Object.keys(actors);
|
return Object.keys(actors);
|
||||||
};
|
};
|
||||||
export const getTitle = function () {
|
|
||||||
return title;
|
|
||||||
};
|
|
||||||
export const enableSequenceNumbers = function () {
|
export const enableSequenceNumbers = function () {
|
||||||
sequenceNumbersEnabled = true;
|
sequenceNumbersEnabled = true;
|
||||||
};
|
};
|
||||||
@@ -140,6 +144,7 @@ export const clear = function () {
|
|||||||
actors = {};
|
actors = {};
|
||||||
messages = [];
|
messages = [];
|
||||||
sequenceNumbersEnabled = false;
|
sequenceNumbersEnabled = false;
|
||||||
|
commonClear();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parseMessage = function (str) {
|
export const parseMessage = function (str) {
|
||||||
@@ -325,11 +330,6 @@ export const getActorProperty = function (actor, key) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setTitle = function (txt) {
|
|
||||||
let sanitizedText = sanitizeText(txt, configApi.getConfig());
|
|
||||||
title = sanitizedText;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const apply = function (param) {
|
export const apply = function (param) {
|
||||||
if (param instanceof Array) {
|
if (param instanceof Array) {
|
||||||
param.forEach(function (item) {
|
param.forEach(function (item) {
|
||||||
@@ -423,15 +423,6 @@ export const apply = function (param) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const setAccDescription = function (description_lex) {
|
|
||||||
let sanitizedText = sanitizeText(description_lex, configApi.getConfig());
|
|
||||||
description = sanitizedText;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getAccDescription = function () {
|
|
||||||
return description;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
addActor,
|
addActor,
|
||||||
addMessage,
|
addMessage,
|
||||||
|
@@ -108,26 +108,34 @@ Bob-->Alice: I am good thanks!`;
|
|||||||
expect(title).toBe('Diagram Title');
|
expect(title).toBe('Diagram Title');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('it should handle a sequenceDiagram definition with a accDescription', function () {
|
it('it should handle a sequenceDiagram definition with a accessibility title and description (accDescr)', function () {
|
||||||
const str = `
|
const str = `
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
accDescription Accessibility Description
|
accTitle: This is the title
|
||||||
|
accDescr: Accessibility Description
|
||||||
Alice->Bob:Hello Bob, how are you?
|
Alice->Bob:Hello Bob, how are you?
|
||||||
Note right of Bob: Bob thinks
|
`;
|
||||||
Bob-->Alice: I am good thanks!`;
|
|
||||||
|
|
||||||
mermaidAPI.parse(str);
|
mermaidAPI.parse(str);
|
||||||
const actors = parser.yy.getActors();
|
expect(parser.yy.getTitle()).toBe('This is the title');
|
||||||
expect(actors.Alice.description).toBe('Alice');
|
|
||||||
actors.Bob.description = 'Bob';
|
|
||||||
|
|
||||||
expect(parser.yy.getAccDescription()).toBe('Accessibility Description');
|
expect(parser.yy.getAccDescription()).toBe('Accessibility Description');
|
||||||
const messages = parser.yy.getMessages();
|
const messages = parser.yy.getMessages();
|
||||||
const title = parser.yy.getTitle();
|
});
|
||||||
|
it('it should handle a sequenceDiagram definition with a accessibility title and multiline description (accDescr)', function () {
|
||||||
|
const str = `
|
||||||
|
sequenceDiagram
|
||||||
|
accTitle: This is the title
|
||||||
|
accDescr {
|
||||||
|
Accessibility
|
||||||
|
Description
|
||||||
|
}
|
||||||
|
Alice->Bob:Hello Bob, how are you?
|
||||||
|
`;
|
||||||
|
|
||||||
expect(messages.length).toBe(3);
|
mermaidAPI.parse(str);
|
||||||
expect(messages[0].from).toBe('Alice');
|
expect(parser.yy.getTitle()).toBe('This is the title');
|
||||||
expect(messages[2].from).toBe('Bob');
|
expect(parser.yy.getAccDescription()).toBe('Accessibility\nDescription');
|
||||||
|
const messages = parser.yy.getMessages();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('it should space in actor names', function () {
|
it('it should space in actor names', function () {
|
||||||
|
Reference in New Issue
Block a user