Skip to main content

dsl


submodule compiler


submodule types


func build_mission

Call Type: normal

Compile DSL source text into a MissionIR object.

Arguments

arg  dsl_code  (str) string representation of a DSL file

Returns

MissionIR a mission intermediate representation

View Source
def build_mission(dsl_code: str) -> MissionIR:
"""Compile DSL source text into a MissionIR object.

Args:
dsl_code (str): string representation of a DSL file

Returns:
MissionIR: a mission intermediate representation
"""
tree = _parser.parse(dsl_code)
mission = DroneDSLTransformer().transform(tree)
logger.info(
"Compiled DSL: start=%s, actions=%d, events=%d",
mission.start_action_id, len(mission.actions), len(mission.events),
)
return mission


func cli_compile_dsl

Call Type: normal

Command line utility for compiling DSL scripts.

Command line script that takes a DSL file as input and writes the compiled mission file to the specified output path.

Arguments

arg  dsl_file  (str) input DSL file path (positional argument 0, required)

arg  output  (str) output mission JSON path (--output or -o, default: ./mission.json)

View Source
def cli_compile_dsl():
"""Command line utility for compiling DSL scripts.

Command line script that takes a DSL file as input and writes the compiled mission file
to the specified output path.

Args:
dsl_file (str): input DSL file path (positional argument 0, required)
output (str): output mission JSON path (`--output` or `-o`, default: `./mission.json`)
"""
import argparse
from dataclasses import asdict
import json
parser = argparse.ArgumentParser(description="SteelEagle DSL compiler.")
parser.add_argument("dsl_file", help="Path to DSL file")
parser.add_argument("-o", "--output", type=str, default="mission.json", help="Name of the output file (type: JSON)")
args = parser.parse_args()

mission_json_text = ''
with open(args.dsl_file, 'r') as file:
dsl_content = file.read()
mission = build_mission(dsl_content)
mission_json_text = json.dumps(asdict(mission))
print("Mission compiled!")

with open(args.output, 'w') as file:
file.write(mission_json_text)
print(f"Wrote contents to {args.output}.")