@@ -22,48 +22,57 @@ Decisions (start)-><d1>
22
22
Decisions w/Label (start)-><d1>logged in->(Show Dashboard), <d1>not logged in->(Show Login Page)
23
23
Parallel (Action1)->|a|,(Action 2)->|a|
24
24
Note (Action1)-(note: A note message here)
25
+ Object Node [Object]
25
26
Comment // Comments
26
27
*/
27
28
28
- function parseYumlExpr ( specLine ) {
29
- const exprs = [ ] ;
30
- const parts = splitYumlExpr ( specLine , "(<|" ) ;
29
+ function * parseYumlExpr ( specLine ) {
30
+ const parts = splitYumlExpr ( specLine , "[(<|" ) ;
31
+
32
+ // yUML syntax allows any character in decision labels.
33
+ // The following variable serves as flag to avoid parsing
34
+ // brackets characters inside labels.
35
+ let isDecisionLabel = false ;
36
+ let decisionLabelBuffer = "" ;
31
37
32
38
for ( const part of parts ) {
33
- if ( / ^ \( .* \) $ / . test ( part ) ) {
39
+ if ( / - > $ / . test ( part ) ) {
40
+ // arrow
41
+ const fullLabel = decisionLabelBuffer + part . substr ( 0 , part . length - 2 ) . trim ( ) ;
42
+ isDecisionLabel = false ;
43
+ decisionLabelBuffer = "" ;
44
+ yield [ "edge" , "none" , "vee" , fullLabel , "solid" ] ;
45
+ } else if ( isDecisionLabel ) {
46
+ // decision label parts
47
+ decisionLabelBuffer += part ;
48
+ } else if ( / ^ \( .* \) $ / . test ( part ) ) {
34
49
// activity
35
50
const ret = extractBgAndNote (
36
51
part . substr ( 1 , part . length - 2 ) . trim ( ) ,
37
52
true
38
53
) ;
39
- exprs . push ( [
54
+ yield [
40
55
ret . isNote ? "note" : "record" ,
41
56
ret . part ,
57
+ "rounded" ,
42
58
ret . bg ,
43
59
ret . fontcolor ,
44
- ] ) ;
60
+ ] ;
45
61
} else if ( / ^ < .* > $ / . test ( part ) ) {
46
62
// decision
47
- exprs . push ( [ "diamond" , part . substr ( 1 , part . length - 2 ) . trim ( ) ] ) ;
63
+ isDecisionLabel = true ;
64
+ yield [ "diamond" , part . substr ( 1 , part . length - 2 ) . trim ( ) ] ;
65
+ } else if ( / ^ \[ .* \] $ / . test ( part ) ) {
66
+ // object node
67
+ yield [ "record" , part . substr ( 1 , part . length - 2 ) . trim ( ) ] ;
48
68
} else if ( / ^ \| .* \| $ / . test ( part ) ) {
49
69
// bar
50
- exprs . push ( [ "mrecord" , part . substr ( 1 , part . length - 2 ) . trim ( ) ] ) ;
51
- } else if ( / - > $ / . test ( part ) ) {
52
- // arrow
53
- exprs . push ( [
54
- "edge" ,
55
- "none" ,
56
- "vee" ,
57
- part . substr ( 0 , part . length - 2 ) . trim ( ) ,
58
- "solid" ,
59
- ] ) ;
70
+ yield [ "mrecord" , part . substr ( 1 , part . length - 2 ) . trim ( ) ] ;
60
71
} else if ( part === "-" ) {
61
72
// connector for notes
62
- exprs . push ( [ "edge" , "none" , "none" , "" , "solid" ] ) ;
63
- } else throw new Error ( " Invalid expression" ) ;
73
+ yield [ "edge" , "none" , "none" , "" , "solid" ] ;
74
+ } else throw new Error ( ` Invalid expression: " ${ part } "` ) ;
64
75
}
65
-
66
- return exprs ;
67
76
}
68
77
69
78
function composeDotExpr ( specLines , options ) {
@@ -72,11 +81,10 @@ function composeDotExpr(specLines, options) {
72
81
const elements = [ ] ;
73
82
74
83
for ( const line of specLines ) {
75
- const parsedYumlExpr = parseYumlExpr ( line ) ;
76
- const parsedYumlExprLastIndex = parsedYumlExpr . length - 1 ;
84
+ const parsedYumlExpr = Array . from ( parseYumlExpr ( line ) ) ;
77
85
78
86
for ( const elem of parsedYumlExpr ) {
79
- const [ shape , label ] = elem ;
87
+ const [ shape , label , style ] = elem ;
80
88
81
89
if ( shape === "note" || shape === "record" ) {
82
90
const uid = uidHandler . createUid ( label ) ;
@@ -97,18 +105,18 @@ function composeDotExpr(specLines, options) {
97
105
fontsize : 10 ,
98
106
margin : "0.20,0.05" ,
99
107
label : escape_label ( label ) ,
100
- style : "rounded" ,
108
+ style,
101
109
} ;
102
110
103
- if ( elem [ 2 ] ) {
104
- const color = Color ( elem [ 2 ] ) ;
111
+ if ( elem [ 3 ] ) {
112
+ const color = Color ( elem [ 3 ] ) ;
105
113
106
114
node . style += ",filled" ;
107
115
node . fillcolor = color . hex ( ) ;
108
116
node . fontcolor = color . isDark ( ) ? "white" : "black" ;
109
117
}
110
118
111
- if ( elem [ 3 ] ) node . fontcolor = elem [ 3 ] ;
119
+ if ( elem [ 4 ] ) node . fontcolor = elem [ 4 ] ;
112
120
}
113
121
114
122
elements . push ( [ uid , node ] ) ;
@@ -144,6 +152,7 @@ function composeDotExpr(specLines, options) {
144
152
}
145
153
}
146
154
155
+ const parsedYumlExprLastIndex = parsedYumlExpr . length - 1 ;
147
156
for ( let k = 1 ; k < parsedYumlExprLastIndex ; k ++ ) {
148
157
if (
149
158
parsedYumlExpr [ k ] [ 0 ] === "edge" &&
0 commit comments