-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgroup_handler.py
More file actions
64 lines (53 loc) · 2.08 KB
/
group_handler.py
File metadata and controls
64 lines (53 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright (c) 2025 Kodo Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import ast
from parser.context import ParseContext
from parser.parser.registry import register_handler
from parser.parser.utils import flatten_once, group_entities_by_type
from parser.resolution.utils import resolve_call_signature
@register_handler("GroupAction", "launch.actions.GroupAction")
def handle_group_action(node: ast.Call, context: ParseContext) -> dict:
"""
Handle GroupAction(actions=[...])
- Resolves all actions recursively
- Pushes/pops namespace scope if PushRosNamespace is found
"""
args, kwargs = resolve_call_signature(node, context.engine)
# Resolve 'actions' argument (can be list, var, starred)
raw_expr = kwargs.get("actions") or (args[0] if args else [])
resolved_flat = flatten_once(raw_expr)
namespace = None
parameters = []
actions = []
for item in resolved_flat:
if isinstance(item, dict) and item.get("type") == "PushROSNamespace":
namespace = item.get("namespace")
context.push_namespace(namespace)
elif isinstance(item, dict) and item.get("type") == "SetParameter":
parameters.append({item.get("name"): item.get("value")})
else:
actions.append(item)
grouped = group_entities_by_type(actions)
if namespace:
context.pop_namespace()
result = {
"type": "GroupAction",
**kwargs,
"actions": grouped,
}
if namespace:
result["namespace"] = namespace
if parameters:
result["parameters"] = parameters
return result