dpmcore.services.ast_generator
Generate engine-ready validation scripts from DPM-XL expressions. The
resulting enriched_ast is keyed by the resolved module URI and
carries the AST, resolved release, per-validation severity, operands,
tables, preconditions, and dependency information.
The same script generation is exposed through the generate-script
CLI command and the /api/v1/scripts REST endpoint.
ASTGeneratorService
- class dpmcore.services.ast_generator.ASTGeneratorService(session=None)[source]
Bases:
objectGenerate engine-ready validation scripts from DPM-XL expressions.
- __init__(session=None)[source]
Build the service, optionally bound to a SQLAlchemy
session.- Parameters:
session (Session | None)
- Return type:
None
- script(expressions, module_code, module_version, preconditions=None, severity=None, severities=None, release=None)[source]
Generate an engine-ready validations script.
- Parameters:
expressions (
List[Tuple[str,str]]) –[(expression, validation_code), ...].module_code (
str) – Code of the primary module (e.g."COREP_Con").module_version (
str) – Version of the primary module (e.g."2.0.1").preconditions (
Optional[List[Union[Tuple[str,List[str]],Dict[str,Any]]]]) – Optional list of precondition specs. Each entry is either a tuple(precondition_expression, [validation_codes])or a dict with keysexpressionandaffected_operations(optionalcodeandversion_idare also accepted). A precondition can guard many validation codes; a validation may have no precondition.severity (
Optional[str]) – Optional global default severity tag ("error","warning","info"). Defaults to"warning".severities (
Optional[Dict[str,str]]) – Optional per-validation override map{validation_code: severity}. Resolution per validation isseverities.get(code, severity_global). Unknown codes (not present inexpressions) raiseValueError.release (
Optional[str]) – Optional release code. When omitted, resolved to the latest release whose window contains the requestedModuleVersion. The resolved release is surfaced in thedpm_releaseblock and used for every downstream DB filter.
- Return type:
- Returns:
A dict with keys
success(bool),enriched_ast(the namespaced dict, orNoneon failure),error(str orNone), andfailed_operations(a{validation_code: error_message}map of expressions skipped due to semantic errors). The namespaced dict mirrors the shape pydpm’sgenerate_validations_scriptproduces.