-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSessionType.g4
More file actions
76 lines (62 loc) · 4.4 KB
/
SessionType.g4
File metadata and controls
76 lines (62 loc) · 4.4 KB
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
grammar SessionType;
/*------------------------------------------------------------------
* PARSER RULES
*------------------------------------------------------------------*/
start returns [type]
:
s=stype {$type = $s.type if $s.type is not None else ""} EOF;
stype returns [type]
:
//op CLPAR ID SEMIC stype (COMMA ID SEMIC stype)* CRPAR
PLUS CLPAR {$type = "["} i=ID s=SEMIC st=stype {$type += "!" + $i.text + $s.text + ($st.type if not $st.type == None else "") } (c=COMMA i2=ID s2=SEMIC st2=stype {$type += $c.text + "!" + $i2.text + $s2.text + ($st2.type if not $st2.type == None else "")})* {$type += "]"} CRPAR
| AND CLPAR {$type = "["} i=ID s=SEMIC st=stype {$type += "?" + $i.text + $s.text + ($st.type if not $st.type == None else "") } (c=COMMA i2=ID s2=SEMIC st2=stype {$type += $c.text + "?" + $i2.text + $s2.text + ($st2.type if not $st2.type == None else "")})* {$type += "]"} CRPAR
| r=REC i=ID d=DOT g=guarded {$type = $r.text + " V" + $i.text + " " + $d.text + ($g.type if not $g.type == None else "")}
| i=ID {$type = "V" + $i.text}
| e=END {$type = $e.text}
| o=OUT i=ID s=SEMIC st=stype {$type = $o.text + $i.text + $s.text + ($st.type if not $st.type == None else "") }
| sl=SLPAR o=OUT i=ID s=SEMIC st=stype {$type = $sl.text + $o.text + $i.text + $s.text + ($st.type if not $st.type == None else "") }(c=COMMA o2=OUT i2=ID s2=SEMIC st2=stype {$type += $c.text + $o2.text + $i2.text + $s2.text + ($st2.type if not $st2.type == None else "")})* sr=SRPAR {$type += $sr.text}
| n=IN i=ID s=SEMIC st=stype {$type = $n.text + $i.text + $s.text + ($st.type if not $st.type == None else "") }
| sl=SLPAR n=IN i=ID s=SEMIC st=stype {$type = $sl.text + $n.text + $i.text + $s.text + ($st.type if not $st.type == None else "") } (c=COMMA n2=IN i2=ID s2=SEMIC st2=stype {$type += $c.text + $n2.text + $i2.text + $s2.text + ($st2.type if not $st2.type == None else "")})* sr=SRPAR {$type += $sr.text}
;
guarded returns [type]
:
//op CLPAR ID SEMIC stype (COMMA ID SEMIC stype)* CRPAR
PLUS CLPAR {$type = "["} i=ID s=SEMIC st=stype {$type += "!" + $i.text + $s.text + ($st.type if not $st.type == None else "") } (c=COMMA i2=ID s2=SEMIC st2=stype {$type += $c.text + "!" + $i2.text + $s2.text + ($st2.type if not $st2.type == None else "")})* {$type += "]"} CRPAR
| AND CLPAR {$type = "["} i=ID s=SEMIC st=stype {$type += "?" + $i.text + $s.text + ($st.type if not $st.type == None else "") } (c=COMMA i2=ID s2=SEMIC st2=stype {$type += $c.text + "?" + $i2.text + $s2.text + ($st2.type if not $st2.type == None else "")})* {$type += "]"} CRPAR
| r=REC i=ID d=DOT g=guarded {$type = $r.text + " V" + $i.text + " " + $d.text + ($g.type if not $g.type == None else "")}
| e=END {$type = $e.text}
| o=OUT i=ID s=SEMIC st=stype {$type = $o.text + $i.text + $s.text + ($st.type if not $st.type == None else "") }
| sl=SLPAR o=OUT i=ID s=SEMIC st=stype {$type = $sl.text + $o.text + $i.text + $s.text + ($st.type if not $st.type == None else "") }(c=COMMA o2=OUT i2=ID s2=SEMIC st2=stype {$type += $c.text + $o2.text + $i2.text + $s2.text + ($st2.type if not $st2.type == None else "")})* sr=SRPAR {$type += $sr.text}
| n=IN i=ID s=SEMIC st=stype {$type = $n.text + $i.text + $s.text + ($st.type if not $st.type == None else "") }
| sl=SLPAR n=IN i=ID s=SEMIC st=stype {$type = $sl.text + $n.text + $i.text + $s.text + ($st.type if not $st.type == None else "") } (c=COMMA n2=IN i2=ID s2=SEMIC st2=stype {$type += $c.text + $n2.text + $i2.text + $s2.text + ($st2.type if not $st2.type == None else "")})* sr=SRPAR {$type += $sr.text}
;
/*ident returns [type]:
iu=IDU {$type = $iu.text}
|il=IDL {$type = $il.text}
;*/
/*op returnstype [type]
:
PLUS
| AND
;*/
/*------------------------------------------------------------------
* LEXER RULES
*------------------------------------------------------------------*/
PLUS : '+' ;
CLPAR : '{' ;
CRPAR : '}' ;
SLPAR : '[' ;
SRPAR : ']' ;
SEMIC : ';' ;
COMMA : ',' ;
DOT : '.' ;
AND : '&';
REC : 'rec';
END : 'end';
OUT : '!';
IN : '?';
ID : ('a'..'z' | 'A'..'Z')('a'..'z' | 'A'..'Z' | '0'..'9')* ;
//IDU : ('A'..'Z')('a'..'z' | 'A'..'Z' | '0'..'9')* ;
//IDL : ('a'..'z')('a'..'z' | 'A'..'Z' | '0'..'9')* ;
WHITESP : ( '\t' | ' ' | '\r' | '\n' )+ -> channel(HIDDEN) ;
//ERR : . { print("N Error: ")} -> channel(HIDDEN);