RagConnect.parser 3.28 KB
Newer Older
René Schöne's avatar
René Schöne committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ConnectSpecificationFile connect_specification_file
  = endpoint_definition.d connect_specification_file.r
    {:
      r.getEndpointDefinitionList().insertChild(d, 0); return r;
    :}
  | dependency_definition.d connect_specification_file.r
    {:
      r.getDependencyDefinitionList().insertChild(d, 0); return r;
    :}
  | mapping_definition.d connect_specification_file.r
    {:
      r.getMappingDefinitionList().insertChild(d, 0); return r;
    :}
  | comment connect_specification_file.r
    {:
      return r;
    :}
  | {: return new ConnectSpecificationFile(); :}
19
20
;

21
22
23
24
%embed {:
  private Iterable<String> makeMappingDefs(ArrayList<?> raw_mapping_defs) {
    return () -> raw_mapping_defs.stream().map(raw -> ((Symbol) raw).value.toString()).iterator();
  }
René Schöne's avatar
René Schöne committed
25
26
27
28
  private TokenEndpointDefinition enableAlwaysApply(TokenEndpointDefinition def) {
    def.setAlwaysApply(true);
    return def;
  }
29
30
:} ;

31
EndpointDefinition endpoint_definition
René Schöne's avatar
René Schöne committed
32
  = endpoint_definition_type.endpointDef SCOL
33
    {:
René Schöne's avatar
René Schöne committed
34
      return endpointDef;
35
    :}
René Schöne's avatar
René Schöne committed
36
  | endpoint_definition_type.endpointDef USING string_list.mapping_defs SCOL
37
    {:
38
      for (String mapping_def : makeMappingDefs(mapping_defs)) {
René Schöne's avatar
René Schöne committed
39
        endpointDef.addMapping(MappingDefinition.createRef(mapping_def));
40
      }
René Schöne's avatar
René Schöne committed
41
      return endpointDef;
42
43
44
    :}
;

René Schöne's avatar
René Schöne committed
45
EndpointDefinition endpoint_definition_type
46
47
  = RECEIVE token_ref           {: return new ReceiveTokenEndpointDefinition().setToken(token_ref); :}
  | SEND token_ref              {: return new SendTokenEndpointDefinition().setToken(token_ref); :}
48
49
  | RECEIVE TREE type_ref       {: return new ReceiveTypeEndpointDefinition().setType(type_ref); :}
  | SEND TREE type_ref          {: return new SendTypeEndpointDefinition().setType(type_ref); :}
René Schöne's avatar
René Schöne committed
50
51
52
53
54
55
;

TokenComponent token_ref
  = ID.type_name DOT ID.token_name  {: return TokenComponent.createRef(type_name + "." + token_name); :}
;

56
57
58
59
TypeComponent type_ref
  = ID.parent_type_name DOT ID.child_type_name  {: return TypeComponent.createRef(parent_type_name + "." + child_type_name); :}
;

60
61
62
63
64
ArrayList string_list
  = ID
  | string_list COMMA ID
;

65
DependencyDefinition dependency_definition
René Schöne's avatar
René Schöne committed
66
  = ID.target_type DOT ID.target_component CAN_DEPEND_ON ID.source_type DOT ID.source_token AS ID.id SCOL
67
68
69
    {:
      DependencyDefinition result = new DependencyDefinition();
      result.setSource(TokenComponent.createRef(source_type + "." + source_token));
René Schöne's avatar
René Schöne committed
70
      result.setTarget(Component.createRef(target_type + "." + target_component));
71
72
73
74
75
76
      result.setID(id);
      return result;
    :}
;

MappingDefinition mapping_definition
77
  = ID.id MAPS mapping_type.from_type ID.from_name TO mapping_type.to_type MAPPING_CONTENT.content
78
79
80
    {:
      MappingDefinition result = new MappingDefinition();
      result.setID(id);
81
82
83
      result.setFromType(from_type);
      result.setFromVariableName(from_name);
      result.setToType(to_type);
84
      result.setContent(content.substring(2, content.length() - 2));
85
86
87
88
      return result;
    :}
;

89
MappingDefinitionType mapping_type
90
  = java_type_use.type
91
    {:
92
      JavaMappingDefinitionType result = new JavaMappingDefinitionType();
93
94
95
      result.setType(type);
      return result;
    :}
96
  | java_type_use.type LBRACKET RBRACKET
97
    {:
98
      JavaArrayMappingDefinitionType result = new JavaArrayMappingDefinitionType();
99
100
101
102
      result.setType(type);
      return result;
    :}
;