RelAstBase.parser 2.59 KB
Newer Older
Niklas Fors's avatar
Niklas Fors committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Program goal = 
	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 =
	ID type_decl_super.s components_opt.c SCOL 
	{: return new TypeDecl(ID, false, s, c); :}
	| ABSTRACT ID type_decl_super.s components_opt.c SCOL 
	{: 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); :}
Niklas Fors's avatar
Niklas Fors committed
58
59
	// Token
	| LT ID COL type_use.u GT {: return new TokenComponent(ID, u); :}
60
	| LT ID GT {: return new TokenComponent(ID, new SimpleTypeUse("String")); :}
Niklas Fors's avatar
Niklas Fors committed
61
62
63
64
65
66
67
68
	;

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

Relation relation =
Niklas Fors's avatar
Niklas Fors committed
69
	RELATION relation_comp.l direction relation_comp.r SCOL
Niklas Fors's avatar
Niklas Fors committed
70
71
72
	{: return new Relation(l, direction, r); :}
	;

Niklas Fors's avatar
Niklas Fors committed
73
RelationComponent relation_comp =
Niklas Fors's avatar
Niklas Fors committed
74
	// One
75
76
	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
77
	// Optional
78
79
	| 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
80
	// Many
81
82
	| 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
83
84
85
86
87
88
	;

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