Enhancing the AST #371
Answered
by
msujew
paulfrench
asked this question in
Q&A
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 |
Answered by
msujew
Jan 17, 2022
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;
} |
0 replies
Answer selected by
paulfrench
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
generally, you should use the
ValidationRegistryfor 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
validateDocumentmethod of theDocumentValidatorin a way like this: