On this page ...

Customization of the Validator

The validator can be adjusted by adding a single Typescript class. This class should implement the generated checker interface of the validator, adding checks per node of the AST that is visited.

The Checker Interface

For each language a checker interface is generated. This interface is an extension of the worker part of the visitor pattern, adding an error list.

// CustomizationsProject/src/freon/validator/gen/EntityModelValidator.ts#L38-L40

The worker defines two methods for each concept in the language, as shown in the next example.

// CustomizationsProject/src/freon/utils/gen/EntityModelWorker.ts#L48-L57

The Validation Class

As a convenience, Freon generates a file ~/freon/validator/CustomYourLanguageNameValidator.ts, which will not be overwritten upon regeneration. This validator should implement the checker interface.

You can give a custom implementation for any of the methods of the default worker. This method will override the (empty) default implementation. Any validation errors should be pushed onto the errorList attribute. Note that each error must implement the FreError interface.

The result of the above could look something like the following. In this example only nodes of type EntityFunction are checked. If the name of the node equals determine than an error is pushed on the errorList. If you want the walker to stop when an erroneous node is found you should return true, else return false.

// CustomizationsProject/src/custom/validator/CustomEntityModelValidator.ts

// Generated by the Freon Language Generator.
import { FreError, FreErrorSeverity } from "@freon4dsl/core";
import { EntityModelDefaultWorker } from "../utils/gen/EntityModelDefaultWorker.js";
import { EntityModelCheckerInterface } from "./gen/EntityModelValidator.js";
import {EntityFunction} from "../language/gen/index.js";

export class CustomEntityModelValidator extends EntityModelDefaultWorker implements EntityModelCheckerInterface {
    errorList: FreError[] = [];

    /**
     * Example of a custom validation. Every EntityFunction with name 'determine' is considered incorrect.
     * @param modelelement
     */
    public execBeforeEntityFunction(modelelement: EntityFunction): boolean {
        if (modelelement.name == "determine") {
            this.errorList.push(
                new FreError(
                    `"determine" is a terrible name for a Function`,
                    modelelement,
                    modelelement.name,
                    FreErrorSeverity.Error
                )
            );
            return true;
        }
        return false;
    }
}
© 2018 - 2025 Freon contributors - Freon is open source under the MIT License.