RelAst.parser 4.54 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
38
39
40
41
ArrayList inner_type_use
    = ID
    | inner_type_use DOT ID
    ;

Niklas Fors's avatar
Niklas Fors committed
42
TypeUse type_use =
43
44
45
46
//    s_type_use.u                {: return u; :}
//  |
  parameterized_type_use.p    {: return p; :}
  | inner_type_use.p            {: return new SimpleTypeUse((String)p.stream().map( x -> ((Symbol)x).value.toString()).collect(java.util.stream.Collectors.joining("."))); :}
Johannes Mey's avatar
Johannes Mey committed
47
  ;
48
ParameterizedTypeUse parameterized_type_use =
49
  ID LT type_use_list.l GT      {: return new ParameterizedTypeUse(ID, l); :}
Johannes Mey's avatar
Johannes Mey committed
50
  ;
51
List type_use_list =
52
53
  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
54
  ;
Niklas Fors's avatar
Niklas Fors committed
55
56

List components_opt =
57
58
  /* empty */               {: return new List(); :}
  | ASSIGN components.l     {: return l; :}
Johannes Mey's avatar
Johannes Mey committed
59
  ;
Niklas Fors's avatar
Niklas Fors committed
60
61

List components =
62
63
  /* empty */                   {: return new List(); :}
  | components.l component.c    {: return l.add(c); :}
Johannes Mey's avatar
Johannes Mey committed
64
  ;
Niklas Fors's avatar
Niklas Fors committed
65
66

Component component =
67
68
    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
69
  // List
70
71
  | 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
72
  // Opt
Johannes Mey's avatar
Johannes Mey committed
73
74
75
76
77
78
79
80
  | 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
81
  // NTA
82
83
  | 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
84
  // NTA Token (same as NTA)
85
86
  | 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
87
  // Token
88
89
  | 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
90
  ;
Niklas Fors's avatar
Niklas Fors committed
91
92

Relation relation =
Johannes Mey's avatar
Johannes Mey committed
93
  RELATION relation_comp.l direction relation_comp.r SCOL
94
95
   {:
      Relation result = new Relation();
96
97
98
99
100
101
102
103
104
      if (direction instanceof LeftDirection) {
        result.setLeft(r);
        result.setDirection(new RightDirection());
        result.setRight(l);
      } else {
        result.setLeft(l);
        result.setDirection(direction);
        result.setRight(r);
      }
105
106
      return result;
   :}
Johannes Mey's avatar
Johannes Mey committed
107
  ;
Niklas Fors's avatar
Niklas Fors committed
108

Niklas Fors's avatar
Niklas Fors committed
109
RelationComponent relation_comp =
Johannes Mey's avatar
Johannes Mey committed
110
  // One
111
112
  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
113
  // Optional
114
115
  | 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
116
  // Many
117
118
  | 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
119
  ;
Niklas Fors's avatar
Niklas Fors committed
120
121

Direction direction =
Johannes Mey's avatar
Johannes Mey committed
122
  RIGHT {: return new RightDirection(); :}
123
  | LEFT {: return new LeftDirection(); :}
Johannes Mey's avatar
Johannes Mey committed
124
125
  | BIDIRECTIONAL {: return new Bidirectional(); :}
  ;