RelAstBase.parser 2.19 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
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
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(); :}
	| COL type_use.u {: return new Opt(u); :}
	;

TypeUse type_use =
	ID {: return new TypeUse(ID); :}
	;

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 =
	ID COL type_use.u {: return new NormalComponent(ID, u); :}
	| type_use.u {: return new NormalComponent(u.getID(), u); :}
	// List
	| ID COL type_use.u STAR {: return new ListComponent(ID, u); :}
	| type_use.u STAR {: return new ListComponent(u.getID(), u); :}
	// Opt
	| LBRACKET ID COL type_use.u RBRACKET {: return new OptComponent(ID, u); :}
	| LBRACKET type_use.u RBRACKET {: return new OptComponent(u.getID(), u); :}
	// Token
	| LT ID COL type_use.u GT {: return new TokenComponent(ID, u); :}
	| LT ID GT {: return new TokenComponent(ID, new TypeUse("String")); :}
	;

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

Relation relation =
	RELATION relation_side.l direction relation_side.r SCOL 
	{: return new Relation(l, direction, r); :}
	;

RelationSide relation_side =
	// One
	type_use.u DOT ID {: return new OneRelationSide(u, ID); :}
	| type_use.u {: return new OneRelationSide(u, ""); :}
	// Optional
	| LBRACKET type_use.u DOT ID RBRACKET {: return new OptionalRelationSide(u, ID); :}
	| LBRACKET type_use.u RBRACKET {: return new OptionalRelationSide(u, ""); :}
	// Many
	| type_use.u STAR DOT ID {: return new ManyRelationSide(u, ID); :}
	| type_use.u STAR {: return new ManyRelationSide(u, ""); :}
	;

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