mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
#945 Handling of note statements
This commit is contained in:
@@ -20,6 +20,9 @@
|
|||||||
%x STATE_ID
|
%x STATE_ID
|
||||||
%x ALIAS
|
%x ALIAS
|
||||||
%x SCALE
|
%x SCALE
|
||||||
|
%x NOTE
|
||||||
|
%x NOTE_ID
|
||||||
|
%x NOTE_TEXT
|
||||||
%x struct
|
%x struct
|
||||||
|
|
||||||
// A special state for grabbing text up to the first comment/newline
|
// A special state for grabbing text up to the first comment/newline
|
||||||
@@ -49,11 +52,15 @@
|
|||||||
<STATE>\{ {this.popState();this.pushState('struct'); console.log('begin struct', yytext);return 'STRUCT_START';}
|
<STATE>\{ {this.popState();this.pushState('struct'); console.log('begin struct', yytext);return 'STRUCT_START';}
|
||||||
<struct>\} { console.log('Ending struct'); this.popState(); return 'STRUCT_STOP';}}
|
<struct>\} { console.log('Ending struct'); this.popState(); return 'STRUCT_STOP';}}
|
||||||
<struct>[\n] /* nothing */
|
<struct>[\n] /* nothing */
|
||||||
// <struct>[^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
|
|
||||||
|
|
||||||
|
<INITIAL,struct>"note"\s+ { this.begin('NOTE'); return 'note'; }
|
||||||
|
<NOTE>"left of" { this.popState();this.pushState('NOTE_ID');console.log('Got dir');return 'left_of';}
|
||||||
|
<NOTE>"right of" { this.popState();this.pushState('NOTE_ID');return 'right_of';}
|
||||||
|
<NOTE_ID>\s*[^:\n\s\-]+ { this.popState();this.pushState('NOTE_TEXT');console.log('Got ID for note', yytext);return 'ID';}
|
||||||
|
<NOTE_TEXT>\s*":"[^\+\-:\n,;]+ { this.popState();console.log('Got NOTE_TEXT for note',yytext);return 'NOTE_TEXT';}
|
||||||
|
<NOTE_TEXT>\s*[^\+\-:,;]+"end note" { this.popState();console.log('Got NOTE_TEXT for note',yytext);return 'NOTE_TEXT';}
|
||||||
|
|
||||||
<INITIAL,struct>"note"\s+ { this.begin('LINE'); return 'note'; }
|
"stateDiagram"\s+ { console.log('Got state diagram', yytext,'#');return 'SD'; }
|
||||||
"stateDiagram"\s+ { console.log('Got state diagram', yytext,'#');return 'SD'; }
|
|
||||||
"hide empty description" { console.log('HIDE_EMPTY', yytext,'#');return 'HIDE_EMPTY'; }
|
"hide empty description" { console.log('HIDE_EMPTY', yytext,'#');return 'HIDE_EMPTY'; }
|
||||||
// "participant" { this.begin('ID'); return 'participant'; }
|
// "participant" { this.begin('ID'); return 'participant'; }
|
||||||
// <ID>[^\->:\n,;]+?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
|
// <ID>[^\->:\n,;]+?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
|
||||||
@@ -67,8 +74,6 @@
|
|||||||
<INITIAL,struct>"[*]" { console.log('EDGE_STATE=',yytext); return 'EDGE_STATE';}
|
<INITIAL,struct>"[*]" { console.log('EDGE_STATE=',yytext); return 'EDGE_STATE';}
|
||||||
<INITIAL,struct>[^:\n\s\-]+ { console.log('ID=',yytext); return 'ID';}
|
<INITIAL,struct>[^:\n\s\-]+ { console.log('ID=',yytext); return 'ID';}
|
||||||
<INITIAL,struct>\s*":"[^\+\->:\n,;]+ { yytext = yytext.trim(); console.log('Descr = ', yytext); return 'DESCR'; }
|
<INITIAL,struct>\s*":"[^\+\->:\n,;]+ { yytext = yytext.trim(); console.log('Descr = ', yytext); return 'DESCR'; }
|
||||||
<INITIAL,struct>"left of" return 'left_of';
|
|
||||||
<INITIAL,struct>"right of" return 'right_of';
|
|
||||||
// "over" return 'over';
|
// "over" return 'over';
|
||||||
// "note" return 'note';
|
// "note" return 'note';
|
||||||
// "activate" { this.begin('ID'); return 'activate'; }
|
// "activate" { this.begin('ID'); return 'activate'; }
|
||||||
@@ -79,6 +84,7 @@
|
|||||||
// ";" return 'NL';
|
// ";" return 'NL';
|
||||||
// [^\+\->:\n,;]+ { yytext = yytext.trim(); return 'ACTOR'; }
|
// [^\+\->:\n,;]+ { yytext = yytext.trim(); return 'ACTOR'; }
|
||||||
<INITIAL,struct>"-->" return '-->';
|
<INITIAL,struct>"-->" return '-->';
|
||||||
|
<struct>"--" return 'CONCURRENT';
|
||||||
// "--" return '--';
|
// "--" return '--';
|
||||||
// ":"[^#\n;]+ return 'TXT';
|
// ":"[^#\n;]+ return 'TXT';
|
||||||
<<EOF>> return 'NL';
|
<<EOF>> return 'NL';
|
||||||
@@ -119,12 +125,19 @@ statement
|
|||||||
| STATE_DESCR AS ID
|
| STATE_DESCR AS ID
|
||||||
| FORK
|
| FORK
|
||||||
| JOIN
|
| JOIN
|
||||||
|
| CONCURRENT
|
||||||
|
| note notePosition ID NOTE_TEXT
|
||||||
;
|
;
|
||||||
|
|
||||||
idStatement
|
idStatement
|
||||||
: ID
|
: ID
|
||||||
| EDGE_STATE
|
| EDGE_STATE
|
||||||
;
|
;
|
||||||
|
|
||||||
|
notePosition
|
||||||
|
: left_of
|
||||||
|
| right_of
|
||||||
|
;
|
||||||
// statement
|
// statement
|
||||||
// : 'participant' actor 'AS' restOfLine 'NL' {$2.description=$4; $$=$2;}
|
// : 'participant' actor 'AS' restOfLine 'NL' {$2.description=$4; $$=$2;}
|
||||||
// | 'participant' actor 'NL' {$$=$2;}
|
// | 'participant' actor 'NL' {$$=$2;}
|
||||||
|
@@ -167,27 +167,43 @@ describe('state diagram, ', function() {
|
|||||||
|
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
// it('should handle concurrent state', function() {
|
it('should handle concurrent state', function() {
|
||||||
// const str = `stateDiagram\n
|
const str = `stateDiagram\n
|
||||||
// [*] --> Active
|
[*] --> Active
|
||||||
|
|
||||||
// state Active {
|
state Active {
|
||||||
// [*] -> NumLockOff
|
[*] --> NumLockOff
|
||||||
// NumLockOff --> NumLockOn : EvNumLockPressed
|
NumLockOff --> NumLockOn : EvNumLockPressed
|
||||||
// NumLockOn --> NumLockOff : EvNumLockPressed
|
NumLockOn --> NumLockOff : EvNumLockPressed
|
||||||
// --
|
--
|
||||||
// [*] -> CapsLockOff
|
[*] --> CapsLockOff
|
||||||
// CapsLockOff --> CapsLockOn : EvCapsLockPressed
|
CapsLockOff --> CapsLockOn : EvCapsLockPressed
|
||||||
// CapsLockOn --> CapsLockOff : EvCapsLockPressed
|
CapsLockOn --> CapsLockOff : EvCapsLockPressed
|
||||||
// --
|
--
|
||||||
// [*] -> ScrollLockOff
|
[*] --> ScrollLockOff
|
||||||
// ScrollLockOff --> ScrollLockOn : EvCapsLockPressed
|
ScrollLockOff --> ScrollLockOn : EvCapsLockPressed
|
||||||
// ScrollLockOn --> ScrollLockOff : EvCapsLockPressed
|
ScrollLockOn --> ScrollLockOff : EvCapsLockPressed
|
||||||
// `;
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
// parser.parse(str);
|
parser.parse(str);
|
||||||
// });
|
});
|
||||||
// it('should handle relation definitions', function() {
|
it('should handle concurrent state', function() {
|
||||||
|
const str = `stateDiagram\n
|
||||||
|
[*] --> Active
|
||||||
|
|
||||||
|
state Active {
|
||||||
|
[*] --> NumLockOff
|
||||||
|
--
|
||||||
|
[*] --> CapsLockOff
|
||||||
|
--
|
||||||
|
[*] --> ScrollLockOff
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
parser.parse(str);
|
||||||
|
});
|
||||||
|
// it('should handle arrow directions definitions', function() {
|
||||||
// const str = `stateDiagram\n
|
// const str = `stateDiagram\n
|
||||||
// [*] -up-> First
|
// [*] -up-> First
|
||||||
// First -right-> Second
|
// First -right-> Second
|
||||||
@@ -197,22 +213,22 @@ describe('state diagram, ', function() {
|
|||||||
|
|
||||||
// parser.parse(str);
|
// parser.parse(str);
|
||||||
// });
|
// });
|
||||||
// it('should handle relation definitions', function() {
|
it('should handle note statements', function() {
|
||||||
// const str = `stateDiagram\n
|
const str = `stateDiagram\n
|
||||||
// [*] --> Active
|
[*] --> Active
|
||||||
// Active --> Inactive
|
Active --> Inactive
|
||||||
|
|
||||||
// note left of Active : this is a short\nnote
|
note left of Active : this is a short<br/>note
|
||||||
|
|
||||||
// note right of Inactive
|
note right of Inactive
|
||||||
// A note can also
|
A note can also
|
||||||
// be defined on
|
be defined on
|
||||||
// several lines
|
several lines
|
||||||
// end note
|
end note
|
||||||
// `;
|
`;
|
||||||
|
|
||||||
// parser.parse(str);
|
parser.parse(str);
|
||||||
// });
|
});
|
||||||
// it('should handle relation definitions', function() {
|
// it('should handle relation definitions', function() {
|
||||||
// const str = `stateDiagram\n
|
// const str = `stateDiagram\n
|
||||||
// state foo
|
// state foo
|
||||||
|
Reference in New Issue
Block a user