1/** js sequence diagrams
2 *  https://bramp.github.io/js-sequence-diagrams/
3 *  (c) 2012-2017 Andrew Brampton (bramp.net)
4 *  Simplified BSD license.
5 */
6%lex
7
8%options case-insensitive
9
10%{
11	// Pre-lexer code can go here
12%}
13
14%%
15
16[\r\n]+           return 'NL';
17\s+               /* skip whitespace */
18\#[^\r\n]*        /* skip comments */
19"participant"     return 'participant';
20"left of"         return 'left_of';
21"right of"        return 'right_of';
22"over"            return 'over';
23"note"            return 'note';
24"title"           return 'title';
25","               return ',';
26[^\->:,\r\n"]+    return 'ACTOR';
27\"[^"]+\"         return 'ACTOR';
28"--"              return 'DOTLINE';
29"-"               return 'LINE';
30">>"              return 'OPENARROW';
31">"               return 'ARROW';
32:[^\r\n]+         return 'MESSAGE';
33<<EOF>>           return 'EOF';
34.                 return 'INVALID';
35
36/lex
37
38%start start
39
40%% /* language grammar */
41
42start
43	: document 'EOF' { return yy.parser.yy; } /* returning parser.yy is a quirk of jison >0.4.10 */
44	;
45
46document
47	: /* empty */
48	| document line
49	;
50
51line
52	: statement { }
53	| 'NL'
54	;
55
56statement
57	: 'participant' actor_alias { $2; }
58	| signal               { yy.parser.yy.addSignal($1); }
59	| note_statement       { yy.parser.yy.addSignal($1); }
60	| 'title' message      { yy.parser.yy.setTitle($2);  }
61	;
62
63note_statement
64	: 'note' placement actor message   { $$ = new Diagram.Note($3, $2, $4); }
65	| 'note' 'over' actor_pair message { $$ = new Diagram.Note($3, Diagram.PLACEMENT.OVER, $4); }
66	;
67
68actor_pair
69	: actor             { $$ = $1; }
70	| actor ',' actor   { $$ = [$1, $3]; }
71	;
72
73placement
74	: 'left_of'   { $$ = Diagram.PLACEMENT.LEFTOF; }
75	| 'right_of'  { $$ = Diagram.PLACEMENT.RIGHTOF; }
76	;
77
78signal
79	: actor signaltype actor message
80	{ $$ = new Diagram.Signal($1, $2, $3, $4); }
81	;
82
83actor
84	: ACTOR { $$ = yy.parser.yy.getActor(Diagram.unescape($1)); }
85	;
86
87actor_alias
88	: ACTOR { $$ = yy.parser.yy.getActorWithAlias(Diagram.unescape($1)); }
89	;
90
91signaltype
92	: linetype arrowtype  { $$ = $1 | ($2 << 2); }
93	| linetype            { $$ = $1; }
94	;
95
96linetype
97	: LINE      { $$ = Diagram.LINETYPE.SOLID; }
98	| DOTLINE   { $$ = Diagram.LINETYPE.DOTTED; }
99	;
100
101arrowtype
102	: ARROW     { $$ = Diagram.ARROWTYPE.FILLED; }
103	| OPENARROW { $$ = Diagram.ARROWTYPE.OPEN; }
104	;
105
106message
107	: MESSAGE { $$ = Diagram.unescape($1.substring(1)); }
108	;
109
110
111%%
112