RelAst.parser 2.92 KB
Newer Older
Johannes Mey's avatar
Johannes Mey committed
1
Program goal =
Niklas Fors's avatar
Niklas Fors committed
2
3
4
5
6
7
8
9
10
11
	type_decls.t relations.r {: return new Program(t, r); :}
	| STRING_LITERAL STAR {: return new Program(); :}
	;

List type_decls =
	/* empty */ {: return new List(); :}
	| type_decls.l type_decl.d {: return l.add(d); :}
	;

TypeDecl type_decl =
Johannes Mey's avatar
Johannes Mey committed
12
	ID type_decl_super.s components_opt.c SCOL
Niklas Fors's avatar
Niklas Fors committed
13
	{: return new TypeDecl(ID, false, s, c); :}
Johannes Mey's avatar
Johannes Mey committed
14
	| ABSTRACT ID type_decl_super.s components_opt.c SCOL
Niklas Fors's avatar
Niklas Fors committed
15
16
17
18
19
	{: return new TypeDecl(ID, true, s, c); :}
	;

Opt type_decl_super =
	/* empty */ {: return new Opt(); :}
20
21
22
23
24
	| COL s_type_use.u {: return new Opt(u); :}
	;

SimpleTypeUse s_type_use =
	ID {: return new SimpleTypeUse(ID); :}
Niklas Fors's avatar
Niklas Fors committed
25
26
27
	;

TypeUse type_use =
28
29
30
31
32
33
34
35
36
	s_type_use.u {: return u; :}
	| parameterized_type_use.p {: return p; :}
	;
ParameterizedTypeUse parameterized_type_use =
	ID LT type_use_list.l GT {: return new ParameterizedTypeUse(ID, l); :}
	;
List type_use_list =
	type_use.u {: return new List().add(u); :}
	| type_use_list.l COMMA type_use.u {: return l.add(u); :}
Niklas Fors's avatar
Niklas Fors committed
37
38
39
40
41
42
43
44
45
46
47
48
49
	;

List components_opt =
	/* empty */ {: return new List(); :}
	| ASSIGN components.l {: return l; :}
	;

List components =
	{: return new List(); :}
	| components.l component.c {: return l.add(c); :}
	;

Component component =
50
51
	ID COL s_type_use.u {: return new NormalComponent(ID, u); :}
	| s_type_use.u {: return new NormalComponent(u.getID(), u); :}
Niklas Fors's avatar
Niklas Fors committed
52
	// List
53
54
	| ID COL s_type_use.u STAR {: return new ListComponent(ID, u); :}
	| s_type_use.u STAR {: return new ListComponent(u.getID(), u); :}
Niklas Fors's avatar
Niklas Fors committed
55
	// Opt
56
57
	| LBRACKET ID COL s_type_use.u RBRACKET {: return new OptComponent(ID, u); :}
	| LBRACKET s_type_use.u RBRACKET {: return new OptComponent(u.getID(), u); :}
Johannes Mey's avatar
Johannes Mey committed
58
59
60
	// NTA
	| SLASH ID COL s_type_use.u SLASH {: return new NTAComponent(ID, u); :}
	| SLASH s_type_use.u SLASH {: return new NTAComponent(u.getID(), u); :}
61
62
63
	// NTA Token (same as NTA)
	| SLASH LT ID COL s_type_use.u GT SLASH {: return new NTAComponent(ID, u); :}
	| SLASH LT s_type_use.u GT SLASH {: return new NTAComponent(u.getID(), u); :}
Niklas Fors's avatar
Niklas Fors committed
64
65
	// Token
	| LT ID COL type_use.u GT {: return new TokenComponent(ID, u); :}
66
	| LT ID GT {: return new TokenComponent(ID, new SimpleTypeUse("String")); :}
Niklas Fors's avatar
Niklas Fors committed
67
68
69
70
71
72
73
74
	;

List relations =
	/* empty */ {: return new List(); :}
	| relations.l relation.r {: return l.add(r); :}
	;

Relation relation =
Niklas Fors's avatar
Niklas Fors committed
75
	RELATION relation_comp.l direction relation_comp.r SCOL
Niklas Fors's avatar
Niklas Fors committed
76
77
78
	{: return new Relation(l, direction, r); :}
	;

Niklas Fors's avatar
Niklas Fors committed
79
RelationComponent relation_comp =
Niklas Fors's avatar
Niklas Fors committed
80
	// One
81
82
	s_type_use.u DOT ID {: return new OneRelationComponent(ID, u); :}
	| s_type_use.u {: return new OneRelationComponent("", u); :}
Niklas Fors's avatar
Niklas Fors committed
83
	// Optional
84
85
	| s_type_use.u DOT ID QUESTION_MARK {: return new OptionalRelationComponent(ID, u); :}
	| s_type_use.u QUESTION_MARK {: return new OptionalRelationComponent("", u); :}
Niklas Fors's avatar
Niklas Fors committed
86
	// Many
87
88
	| s_type_use.u DOT ID STAR {: return new ManyRelationComponent(ID, u); :}
	| s_type_use.u STAR {: return new ManyRelationComponent("", u); :}
Niklas Fors's avatar
Niklas Fors committed
89
90
91
92
93
	;

Direction direction =
	RIGHT {: return new RightDirection(); :}
	| BIDIRECTIONAL {: return new Bidirectional(); :}
94
	;