RelAst.parser 4.29 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
  ID type_decl_super.s components_opt.c SCOL
9
10
11
12
13
14
15
16
    {:
      TypeDecl result = new TypeDecl();
      result.setID(ID);
      result.setAbstract(false);
      result.setSuperOpt(s);
      result.setComponentList(c);
      return result;
    :}
Johannes Mey's avatar
Johannes Mey committed
17
  | ABSTRACT ID type_decl_super.s components_opt.c SCOL
18
19
20
21
22
23
24
25
      {:
        TypeDecl result = new TypeDecl();
        result.setID(ID);
        result.setAbstract(true);
        result.setSuperOpt(s);
        result.setComponentList(c);
        return result;
      :}
Johannes Mey's avatar
Johannes Mey committed
26
  ;
Niklas Fors's avatar
Niklas Fors committed
27
28

Opt type_decl_super =
Johannes Mey's avatar
Johannes Mey committed
29
30
31
  /* empty */ {: return new Opt(); :}
  | COL s_type_use.u {: return new Opt(u); :}
  ;
32
33

SimpleTypeUse s_type_use =
Johannes Mey's avatar
Johannes Mey committed
34
35
  ID {: return new SimpleTypeUse(ID); :}
  ;
Niklas Fors's avatar
Niklas Fors committed
36
37

TypeUse type_use =
38
39
    s_type_use.u                {: return u; :}
  | parameterized_type_use.p    {: return p; :}
Johannes Mey's avatar
Johannes Mey committed
40
  ;
41
ParameterizedTypeUse parameterized_type_use =
42
  ID LT type_use_list.l GT      {: return new ParameterizedTypeUse(ID, l); :}
Johannes Mey's avatar
Johannes Mey committed
43
  ;
44
List type_use_list =
45
46
  type_use.u                              {: return new List().add(u); :}
  | type_use_list.l COMMA type_use.u      {: return l.add(u); :}
Johannes Mey's avatar
Johannes Mey committed
47
  ;
Niklas Fors's avatar
Niklas Fors committed
48
49

List components_opt =
50
51
  /* empty */               {: return new List(); :}
  | ASSIGN components.l     {: return l; :}
Johannes Mey's avatar
Johannes Mey committed
52
  ;
Niklas Fors's avatar
Niklas Fors committed
53
54

List components =
55
56
  /* empty */                   {: return new List(); :}
  | components.l component.c    {: return l.add(c); :}
Johannes Mey's avatar
Johannes Mey committed
57
  ;
Niklas Fors's avatar
Niklas Fors committed
58
59

Component component =
60
61
    ID COL s_type_use.u                       {: return new NormalComponent(ID, u); :}
  | s_type_use.u                              {: return new NormalComponent(u.getID(), u); :}
Johannes Mey's avatar
Johannes Mey committed
62
  // List
63
64
  | ID COL s_type_use.u STAR                  {: return new ListComponent(ID, u); :}
  | s_type_use.u STAR                         {: return new ListComponent(u.getID(), u); :}
Johannes Mey's avatar
Johannes Mey committed
65
  // Opt
Johannes Mey's avatar
Johannes Mey committed
66
67
68
69
70
71
72
73
  | 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 list
  | SLASH ID COL s_type_use.u STAR SLASH {: return new NTAListComponent(ID, u); :}
  | SLASH s_type_use.u STAR SLASH {: return new NTAListComponent(u.getID(), u); :}
  // NTA opt
  | SLASH LBRACKET ID COL s_type_use.u RBRACKET SLASH {: return new NTAOptComponent(ID, u); :}
  | SLASH LBRACKET s_type_use.u RBRACKET SLASH {: return new NTAOptComponent(u.getID(), u); :}
Johannes Mey's avatar
Johannes Mey committed
74
  // NTA
75
76
  | 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); :}
Johannes Mey's avatar
Johannes Mey committed
77
  // NTA Token (same as NTA)
78
79
  | SLASH LT ID COL s_type_use.u GT SLASH     {: return new NTATokenComponent(ID, u); :}
  | SLASH LT s_type_use.u GT SLASH            {: return new NTATokenComponent(u.getID(), u); :}
Johannes Mey's avatar
Johannes Mey committed
80
  // Token
81
82
  | LT ID COL type_use.u GT                   {: return new TokenComponent(ID, u); :}
  | LT ID GT                                  {: return new TokenComponent(ID, new SimpleTypeUse("String")); :}
Johannes Mey's avatar
Johannes Mey committed
83
  ;
Niklas Fors's avatar
Niklas Fors committed
84
85

Relation relation =
Johannes Mey's avatar
Johannes Mey committed
86
  RELATION relation_comp.l direction relation_comp.r SCOL
87
88
   {:
      Relation result = new Relation();
89
90
91
92
93
94
95
96
97
      if (direction instanceof LeftDirection) {
        result.setLeft(r);
        result.setDirection(new RightDirection());
        result.setRight(l);
      } else {
        result.setLeft(l);
        result.setDirection(direction);
        result.setRight(r);
      }
98
99
      return result;
   :}
Johannes Mey's avatar
Johannes Mey committed
100
  ;
Niklas Fors's avatar
Niklas Fors committed
101

Niklas Fors's avatar
Niklas Fors committed
102
RelationComponent relation_comp =
Johannes Mey's avatar
Johannes Mey committed
103
  // One
104
105
  s_type_use.u DOT ID                       {: return new OneRelationComponent(ID, u); :}
  | s_type_use.u                            {: return new OneRelationComponent("", u); :}
Johannes Mey's avatar
Johannes Mey committed
106
  // Optional
107
108
  | s_type_use.u DOT ID QUESTION_MARK       {: return new OptionalRelationComponent(ID, u); :}
  | s_type_use.u QUESTION_MARK              {: return new OptionalRelationComponent("", u); :}
Johannes Mey's avatar
Johannes Mey committed
109
  // Many
110
111
  | s_type_use.u DOT ID STAR                {: return new ManyRelationComponent(ID, u); :}
  | s_type_use.u STAR                       {: return new ManyRelationComponent("", u); :}
Johannes Mey's avatar
Johannes Mey committed
112
  ;
Niklas Fors's avatar
Niklas Fors committed
113
114

Direction direction =
Johannes Mey's avatar
Johannes Mey committed
115
  RIGHT {: return new RightDirection(); :}
116
  | LEFT {: return new LeftDirection(); :}
Johannes Mey's avatar
Johannes Mey committed
117
118
  | BIDIRECTIONAL {: return new Bidirectional(); :}
  ;