RagConnect.parser 3.23 KB
Newer Older
1
RagConnect ragconnect
2
  = endpoint_definition.d ragconnect.r       {: r.getEndpointDefinitionList().insertChild(d, 0); return r; :}
3
4
5
6
  | dependency_definition.d ragconnect.r   {: r.getDependencyDefinitionList().insertChild(d, 0); return r; :}
  | mapping_definition.d ragconnect.r      {: r.getMappingDefinitionList().insertChild(d, 0); return r; :}
  | comment ragconnect.r                   {: return r; :}
  |                                     {: return new RagConnect(); :}
7
8
;

9
10
11
12
13
14
%embed {:
  private Iterable<String> makeMappingDefs(ArrayList<?> raw_mapping_defs) {
    return () -> raw_mapping_defs.stream().map(raw -> ((Symbol) raw).value.toString()).iterator();
  }
:} ;

15
EndpointDefinition endpoint_definition
16
  = RECEIVE ID.type_name DOT ID.token_name SCOL
17
    {:
18
      ReceiveFromMqttDefinition result = new ReceiveFromMqttDefinition();
19
20
21
      result.setToken(TokenComponent.createRef(type_name + "." + token_name));
      return result;
    :}
22
  | RECEIVE ID.type_name DOT ID.token_name USING string_list.mapping_defs SCOL
23
    {:
24
      ReceiveFromMqttDefinition result = new ReceiveFromMqttDefinition();
25
      result.setToken(TokenComponent.createRef(type_name + "." + token_name));
26
27
28
      for (String mapping_def : makeMappingDefs(mapping_defs)) {
        result.addMapping(MappingDefinition.createRef(mapping_def));
      }
29
30
      return result;
    :}
31
  | SEND ID.type_name DOT ID.token_name SCOL
32
    {:
33
      SendToMqttDefinition result = new SendToMqttDefinition();
34
35
36
      result.setToken(TokenComponent.createRef(type_name + "." + token_name));
      return result;
    :}
37
  | SEND ID.type_name DOT ID.token_name USING string_list.mapping_defs SCOL
38
    {:
39
      SendToMqttDefinition result = new SendToMqttDefinition();
40
      result.setToken(TokenComponent.createRef(type_name + "." + token_name));
41
42
43
      for (String mapping_def : makeMappingDefs(mapping_defs)) {
        result.addMapping(MappingDefinition.createRef(mapping_def));
      }
44
45
46
47
      return result;
    :}
;

48
49
50
51
52
ArrayList string_list
  = ID
  | string_list COMMA ID
;

53
54
55
56
57
58
59
60
61
62
63
64
DependencyDefinition dependency_definition
  = ID.target_type DOT ID.target_token CAN_DEPEND_ON ID.source_type DOT ID.source_token AS ID.id SCOL
    {:
      DependencyDefinition result = new DependencyDefinition();
      result.setSource(TokenComponent.createRef(source_type + "." + source_token));
      result.setTarget(TokenComponent.createRef(target_type + "." + target_token));
      result.setID(id);
      return result;
    :}
;

MappingDefinition mapping_definition
65
  = ID.id MAPS mapping_type.from_type ID.from_name TO mapping_type.to_type MAPPING_CONTENT.content
66
67
68
    {:
      MappingDefinition result = new MappingDefinition();
      result.setID(id);
69
70
71
      result.setFromType(from_type);
      result.setFromVariableName(from_name);
      result.setToType(to_type);
72
      result.setContent(content.substring(2, content.length() - 2));
73
74
75
76
      return result;
    :}
;

77
MappingDefinitionType mapping_type
78
  = java_type_use.type
79
    {:
80
      JavaMappingDefinitionType result = new JavaMappingDefinitionType();
81
82
83
      result.setType(type);
      return result;
    :}
84
  | java_type_use.type LBRACKET RBRACKET
85
    {:
86
      JavaArrayMappingDefinitionType result = new JavaArrayMappingDefinitionType();
87
88
89
90
      result.setType(type);
      return result;
    :}
;