Enhancing the AST #371
-
Before I can use my AST for code generation I need to perform a number of validation checks and store some additional information against the AST nodes to make it a lot easier to use the model AST in handlebarjs templates. Is there a recommended approach for this? Cheers |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, generally, you should use the For post processing, @spoenemann previously mentioned a method to do this directly after parsing here. If you need validations to run before that, you can override the async validateDocument(document: LangiumDocument, cancelToken = CancellationToken.None): Promise<Diagnostic[]> {
const diagnostics = await super.validateDocument(document, cancelToken);
this.performPostProcessing(document);
return diagnostics;
} |
Beta Was this translation helpful? Give feedback.
Hi,
generally, you should use the
ValidationRegistry
for validation checks. See how we use it for langium's own grammar language:https://github.com/langium/langium/blob/main/packages/langium/src/grammar/langium-grammar-validator.ts
For post processing, @spoenemann previously mentioned a method to do this directly after parsing here. If you need validations to run before that, you can override the
validateDocument
method of theDocumentValidator
in a way like this: