mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Updated sequence diagram parsing with the new syntax
This commit is contained in:
parent
a642ae356c
commit
34ffe2790b
@ -18,7 +18,9 @@
|
||||
|
||||
// Directive states
|
||||
%x open_directive type_directive arg_directive
|
||||
|
||||
%x acc_title
|
||||
%x acc_descr
|
||||
%x acc_descr_multiline
|
||||
%%
|
||||
|
||||
\%\%\{ { this.begin('open_directive'); return 'open_directive'; }
|
||||
@ -59,7 +61,13 @@
|
||||
"deactivate" { this.begin('ID'); return 'deactivate'; }
|
||||
"title"\s[^#\n;]+ return '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';
|
||||
"autonumber" return 'autonumber';
|
||||
"off" return 'off';
|
||||
@ -130,7 +138,9 @@ statement
|
||||
| details_statement 'NEWLINE'
|
||||
| title {yy.setTitle($1.substring(6));$$=$1.substring(6);}
|
||||
| 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
|
||||
{
|
||||
$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 { log } from '../../logger';
|
||||
import { sanitizeText } from '../common/common';
|
||||
import {
|
||||
setTitle,
|
||||
getTitle,
|
||||
getAccDescription,
|
||||
setAccDescription,
|
||||
clear as commonClear,
|
||||
} from '../../commonDb';
|
||||
|
||||
let prevActor = undefined;
|
||||
let actors = {};
|
||||
@ -119,9 +126,6 @@ export const getActor = function (id) {
|
||||
export const getActorKeys = function () {
|
||||
return Object.keys(actors);
|
||||
};
|
||||
export const getTitle = function () {
|
||||
return title;
|
||||
};
|
||||
export const enableSequenceNumbers = function () {
|
||||
sequenceNumbersEnabled = true;
|
||||
};
|
||||
@ -140,6 +144,7 @@ export const clear = function () {
|
||||
actors = {};
|
||||
messages = [];
|
||||
sequenceNumbersEnabled = false;
|
||||
commonClear();
|
||||
};
|
||||
|
||||
export const parseMessage = function (str) {
|
||||
@ -325,11 +330,6 @@ export const getActorProperty = function (actor, key) {
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const setTitle = function (txt) {
|
||||
let sanitizedText = sanitizeText(txt, configApi.getConfig());
|
||||
title = sanitizedText;
|
||||
};
|
||||
|
||||
export const apply = function (param) {
|
||||
if (param instanceof Array) {
|
||||
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 {
|
||||
addActor,
|
||||
addMessage,
|
||||
|
@ -108,26 +108,34 @@ Bob-->Alice: I am good thanks!`;
|
||||
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 = `
|
||||
sequenceDiagram
|
||||
accDescription Accessibility Description
|
||||
accTitle: This is the title
|
||||
accDescr: Accessibility Description
|
||||
Alice->Bob:Hello Bob, how are you?
|
||||
Note right of Bob: Bob thinks
|
||||
Bob-->Alice: I am good thanks!`;
|
||||
`;
|
||||
|
||||
mermaidAPI.parse(str);
|
||||
const actors = parser.yy.getActors();
|
||||
expect(actors.Alice.description).toBe('Alice');
|
||||
actors.Bob.description = 'Bob';
|
||||
|
||||
expect(parser.yy.getTitle()).toBe('This is the title');
|
||||
expect(parser.yy.getAccDescription()).toBe('Accessibility Description');
|
||||
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);
|
||||
expect(messages[0].from).toBe('Alice');
|
||||
expect(messages[2].from).toBe('Bob');
|
||||
mermaidAPI.parse(str);
|
||||
expect(parser.yy.getTitle()).toBe('This is the title');
|
||||
expect(parser.yy.getAccDescription()).toBe('Accessibility\nDescription');
|
||||
const messages = parser.yy.getMessages();
|
||||
});
|
||||
|
||||
it('it should space in actor names', function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user