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