RagConnect.parser 2.84 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
%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
13
14
15
16
  private TokenEndpointDefinition enableAlwaysApply(TokenEndpointDefinition def) {
    def.setAlwaysApply(true);
    return def;
  }
17
18
:} ;

19
EndpointDefinition endpoint_definition
René Schöne's avatar
René Schöne committed
20
  = endpoint_definition_type.endpointDef SCOL
21
    {:
René Schöne's avatar
René Schöne committed
22
      return endpointDef;
23
    :}
René Schöne's avatar
René Schöne committed
24
  | endpoint_definition_type.endpointDef USING string_list.mapping_defs SCOL
25
    {:
26
      for (String mapping_def : makeMappingDefs(mapping_defs)) {
René Schöne's avatar
René Schöne committed
27
        endpointDef.addMapping(MappingDefinition.createRef(mapping_def));
28
      }
René Schöne's avatar
René Schöne committed
29
      return endpointDef;
30
31
32
    :}
;

René Schöne's avatar
René Schöne committed
33
EndpointDefinition endpoint_definition_type
34
35
  = RECEIVE token_ref           {: return new ReceiveTokenEndpointDefinition().setToken(token_ref); :}
  | SEND token_ref              {: return new SendTokenEndpointDefinition().setToken(token_ref); :}
René Schöne's avatar
René Schöne committed
36
37
38
39
40
41
;

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

42
43
44
45
46
ArrayList string_list
  = ID
  | string_list COMMA ID
;

47
48
49
50
51
52
53
54
55
56
57
58
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
59
  = ID.id MAPS mapping_type.from_type ID.from_name TO mapping_type.to_type MAPPING_CONTENT.content
60
61
62
    {:
      MappingDefinition result = new MappingDefinition();
      result.setID(id);
63
64
65
      result.setFromType(from_type);
      result.setFromVariableName(from_name);
      result.setToType(to_type);
66
      result.setContent(content.substring(2, content.length() - 2));
67
68
69
70
      return result;
    :}
;

71
MappingDefinitionType mapping_type
72
  = java_type_use.type
73
    {:
74
      JavaMappingDefinitionType result = new JavaMappingDefinitionType();
75
76
77
      result.setType(type);
      return result;
    :}
78
  | java_type_use.type LBRACKET RBRACKET
79
    {:
80
      JavaArrayMappingDefinitionType result = new JavaArrayMappingDefinitionType();
81
82
83
84
      result.setType(type);
      return result;
    :}
;