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

List type_decls =
Johannes Mey's avatar
Johannes Mey committed
7
8
9
  /* empty */ {: return new List(); :}
  | type_decls.l type_decl.d {: return l.add(d); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
10
11

TypeDecl type_decl =
Johannes Mey's avatar
Johannes Mey committed
12
13
14
15
16
  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); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
17
18

Opt type_decl_super =
Johannes Mey's avatar
Johannes Mey committed
19
20
21
  /* empty */ {: return new Opt(); :}
  | COL s_type_use.u {: return new Opt(u); :}
  ;
22
23

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

TypeUse type_use =
Johannes Mey's avatar
Johannes Mey committed
28
29
30
  s_type_use.u {: return u; :}
  | parameterized_type_use.p {: return p; :}
  ;
31
ParameterizedTypeUse parameterized_type_use =
Johannes Mey's avatar
Johannes Mey committed
32
33
  ID LT type_use_list.l GT {: return new ParameterizedTypeUse(ID, l); :}
  ;
34
List type_use_list =
Johannes Mey's avatar
Johannes Mey committed
35
36
37
  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
38
39

List components_opt =
Johannes Mey's avatar
Johannes Mey committed
40
41
42
  /* empty */ {: return new List(); :}
  | ASSIGN components.l {: return l; :}
  ;
Niklas Fors's avatar
Niklas Fors committed
43
44

List components =
Johannes Mey's avatar
Johannes Mey committed
45
46
47
  {: return new List(); :}
  | components.l component.c {: return l.add(c); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
48
49

Component component =
Johannes Mey's avatar
Johannes Mey committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  ID COL s_type_use.u {: return new NormalComponent(ID, u); :}
  | s_type_use.u {: return new NormalComponent(u.getID(), u); :}
  // List
  | ID COL s_type_use.u STAR {: return new ListComponent(ID, u); :}
  | s_type_use.u STAR {: return new ListComponent(u.getID(), u); :}
  // Opt
  | 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); :}
  // 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); :}
  // 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); :}
  // Token
  | LT ID COL type_use.u GT {: return new TokenComponent(ID, u); :}
  | LT ID GT {: return new TokenComponent(ID, new SimpleTypeUse("String")); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
68
69

List relations =
Johannes Mey's avatar
Johannes Mey committed
70
71
72
  /* empty */ {: return new List(); :}
  | relations.l relation.r {: return l.add(r); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
73
74

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

Niklas Fors's avatar
Niklas Fors committed
79
RelationComponent relation_comp =
Johannes Mey's avatar
Johannes Mey committed
80
81
82
83
84
85
86
87
88
89
  // One
  s_type_use.u DOT ID {: return new OneRelationComponent(ID, u); :}
  | s_type_use.u {: return new OneRelationComponent("", u); :}
  // Optional
  | s_type_use.u DOT ID QUESTION_MARK {: return new OptionalRelationComponent(ID, u); :}
  | s_type_use.u QUESTION_MARK {: return new OptionalRelationComponent("", u); :}
  // Many
  | 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
90
91

Direction direction =
Johannes Mey's avatar
Johannes Mey committed
92
93
94
  RIGHT {: return new RightDirection(); :}
  | BIDIRECTIONAL {: return new Bidirectional(); :}
  ;