Validation Rules
OSC2 Studio provides real-time syntax and semantic validation to help you catch errors instantly while writing scenarios.
Syntax Validation
Syntax validation checks whether the code conforms to the OSC2 grammar specification, including:
- Correct indentation — Indentation errors cause parsing failures
- Keyword spelling — Whether keywords such as
scenario,do,serialare correct - Symbol matching — Whether brackets, colons, commas, and other symbols are complete
- Identifier format — Whether variable names and type names follow naming rules
- Import statements — Whether
importpaths are correctly formatted
Example syntax errors:
# Error: missing colon
scenario my_scenario
do serial: # Correct
car.drive()
# Error: inconsistent indentation
scenario my_scenario:
do serial:
car.drive() # Indentation error, should be 8 spaces
Semantic Validation
Semantic validation checks the logical correctness of the code — cases where syntax is correct but the semantics are problematic:
- Type checking — Whether variable types match (e.g., cannot assign a
stringto anint) - Reference resolution — Whether variables, types, and actors have been declared
- Physical quantity checking — Whether units match (e.g., cannot assign
kphto alengthtype) - Scope checking — Whether a variable is referenced within a valid scope
- Duplicate declarations — Whether duplicate names exist in the same scope
Example semantic errors:
# Error: type mismatch
my_speed: speed = 10m # 10m is a length, not a speed
# Error: undefined variable
car.drive() with:
speed(undefined_var) # undefined_var was not declared
# Error: unit mismatch
distance: length = 50kph # kph is a speed unit, cannot be assigned to length
Constraint Validation
keep statements define conditions that must be satisfied during scenario execution:
keep(car.speed < 80kph) # Hard constraint: vehicle speed must be below 80 km/h
keep(default x == 3) # Default constraint: can be overridden
keep(x in [10..20]) # Range constraint: x is between 10 and 20
Constraint validation checks:
- Whether the constraint expression type is correct (e.g., both sides of
speed < 80kphhave consistent units) - Whether the constraint is within a valid range
- Whether default constraints are correctly overridden
Coverage Checking
Use the cover statement to record test coverage:
extend my_scenario:
cover(side, event: end, target: 10)
The validator checks whether the coverage target format is correct.
Validation Results
In the OSC2 Studio editor, validation results are displayed in the problems panel at the bottom:
- Red wavy lines — Syntax errors (must be fixed)
- Yellow wavy lines — Semantic warnings (recommended to fix)
- Green markers — Validation passed
Click an error marker to jump to the corresponding code location.