|
| 1 | +# Copyright (c) 2025 Kodo Robotics |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import ast |
| 16 | + |
| 17 | +from parser.context import ParseContext |
| 18 | +from parser.parser.postprocessing import simplify_launch_configurations |
| 19 | +from parser.parser.registry import register_handler |
| 20 | +from parser.resolution.utils import resolve_call_signature |
| 21 | + |
| 22 | + |
| 23 | +@register_handler("EqualsSubstitution", "launch.substitutions.EqualsSubstitution") |
| 24 | +def handle_equals_substitution(node: ast.Call, context: ParseContext) -> dict: |
| 25 | + args, _ = resolve_call_signature(node, context.engine) |
| 26 | + if len(args) != 2: |
| 27 | + raise ValueError("EqualsSubstitution must receive exactly two arguments.") |
| 28 | + |
| 29 | + left, right = (simplify_launch_configurations(arg) for arg in args) |
| 30 | + return f"${{EqualsSubstitution:{left}, {right}}}" |
| 31 | + |
| 32 | + |
| 33 | +@register_handler("NotEqualsSubstitution", "launch.substitutions.NotEqualsSubstitution") |
| 34 | +def handle_not_equals_substitution(node: ast.Call, context: ParseContext) -> dict: |
| 35 | + args, _ = resolve_call_signature(node, context.engine) |
| 36 | + if len(args) != 2: |
| 37 | + raise ValueError("NotEqualsSubstitution must receive exactly two arguments.") |
| 38 | + |
| 39 | + left, right = (simplify_launch_configurations(arg) for arg in args) |
| 40 | + return f"${{NotEqualsSubstitution:{left}, {right}}}" |
0 commit comments