RelAst.parser 2.88 KB
Newer Older
Johannes Mey's avatar
Johannes Mey committed
1
Program goal =
2
3
4
  /* empty */              {: return new Program(); :}
  | type_decl.t goal.p     {: p.getTypeDeclList().insertChild(t, 0); return p; :}
  | relation.r goal.p      {: p.getRelationList().insertChild(r, 0); return p; :}
Johannes Mey's avatar
Johannes Mey committed
5
  ;
Niklas Fors's avatar
Niklas Fors committed
6
7

TypeDecl type_decl =
Johannes Mey's avatar
Johannes Mey committed
8
9
10
11
12
  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
13
14

Opt type_decl_super =
Johannes Mey's avatar
Johannes Mey committed
15
16
17
  /* empty */ {: return new Opt(); :}
  | COL s_type_use.u {: return new Opt(u); :}
  ;
18
19

SimpleTypeUse s_type_use =
Johannes Mey's avatar
Johannes Mey committed
20
21
  ID {: return new SimpleTypeUse(ID); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
22
23

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

List components_opt =
Johannes Mey's avatar
Johannes Mey committed
36
37
38
  /* empty */ {: return new List(); :}
  | ASSIGN components.l {: return l; :}
  ;
Niklas Fors's avatar
Niklas Fors committed
39
40

List components =
Johannes Mey's avatar
Johannes Mey committed
41
42
43
  {: return new List(); :}
  | components.l component.c {: return l.add(c); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
44
45

Component component =
Johannes Mey's avatar
Johannes Mey committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  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
64
65

Relation relation =
Johannes Mey's avatar
Johannes Mey committed
66
67
68
  RELATION relation_comp.l direction relation_comp.r SCOL
  {: return new Relation(l, direction, r); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
69

Niklas Fors's avatar
Niklas Fors committed
70
RelationComponent relation_comp =
Johannes Mey's avatar
Johannes Mey committed
71
72
73
74
75
76
77
78
79
80
  // 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
81
82

Direction direction =
Johannes Mey's avatar
Johannes Mey committed
83
84
85
  RIGHT {: return new RightDirection(); :}
  | BIDIRECTIONAL {: return new Bidirectional(); :}
  ;