Ros2Rag.parser 3.63 KB
Newer Older
1
2
3
4
Ros2Rag ros2rag
  = update_definition.d ros2rag.r       {: r.getUpdateDefinitionList().insertChild(d, 0); return r; :}
  | dependency_definition.d ros2rag.r   {: r.getDependencyDefinitionList().insertChild(d, 0); return r; :}
  | mapping_definition.d ros2rag.r      {: r.getMappingDefinitionList().insertChild(d, 0); return r; :}
5
  | comment ros2rag.r                   {: return r; :}
6
7
8
  |                                     {: return new Ros2Rag(); :}
;

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
16
17
18
19
20
21
22
23
// read Joint.CurrentPosition using LinkStateToIntPosition ;
// write RobotArm._AppropriateSpeed using CreateSpeedMessage ;
UpdateDefinition update_definition
  = READ ID.type_name DOT ID.token_name SCOL
    {:
      ReadFromMqttDefinition result = new ReadFromMqttDefinition();
      result.setToken(TokenComponent.createRef(type_name + "." + token_name));
      return result;
    :}
24
  | READ ID.type_name DOT ID.token_name USING string_list.mapping_defs SCOL
25
26
27
    {:
      ReadFromMqttDefinition result = new ReadFromMqttDefinition();
      result.setToken(TokenComponent.createRef(type_name + "." + token_name));
28
29
30
      for (String mapping_def : makeMappingDefs(mapping_defs)) {
        result.addMapping(MappingDefinition.createRef(mapping_def));
      }
31
32
33
34
35
36
37
38
      return result;
    :}
  | WRITE ID.type_name DOT ID.token_name SCOL
    {:
      WriteToMqttDefinition result = new WriteToMqttDefinition();
      result.setToken(TokenComponent.createRef(type_name + "." + token_name));
      return result;
    :}
39
  | WRITE ID.type_name DOT ID.token_name USING string_list.mapping_defs SCOL
40
41
42
    {:
      WriteToMqttDefinition result = new WriteToMqttDefinition();
      result.setToken(TokenComponent.createRef(type_name + "." + token_name));
43
44
45
      for (String mapping_def : makeMappingDefs(mapping_defs)) {
        result.addMapping(MappingDefinition.createRef(mapping_def));
      }
46
47
48
49
      return result;
    :}
;

50
51
52
53
54
ArrayList string_list
  = ID
  | string_list COMMA ID
;

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// RobotArm._AppropriateSpeed canDependOn Joint.CurrentPosition as dependency1 ;
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;
    :}
;

//LinkStateToIntPosition maps protobuf panda.Linkstate.PandaLinkState x to IntPosition y {
//  panda.Linkstate.PandaLinkState.Position p = x.getPos();
//  y = IntPosition.of((int) p.getPositionX(), (int) p.getPositionY(), (int) p.getPositionZ());
//}
MappingDefinition mapping_definition
72
  = ID.id MAPS mapping_type.from_type ID.from_name TO mapping_type.to_type MAPPING_CONTENT.content
73
74
75
    {:
      MappingDefinition result = new MappingDefinition();
      result.setID(id);
76
77
78
      result.setFromType(from_type);
      result.setFromVariableName(from_name);
      result.setToType(to_type);
79
      result.setContent(content.substring(2, content.length() - 2));
80
81
82
83
      return result;
    :}
;

84
MappingDefinitionType mapping_type
85
  = java_type_use.type
86
    {:
87
      JavaMappingDefinitionType result = new JavaMappingDefinitionType();
88
89
90
      result.setType(type);
      return result;
    :}
91
  | java_type_use.type LBRACKET RBRACKET
92
    {:
93
      JavaArrayMappingDefinitionType result = new JavaArrayMappingDefinitionType();
94
95
96
97
      result.setType(type);
      return result;
    :}
;