-
Notifications
You must be signed in to change notification settings - Fork 0
8 Pragmas
Pragmas allow you to set system properties like i.e. if you are allowed to define further types etc. Pragmas can easily be extended. Technically a Pragma is getting executed during parse time at the point in the DL file. You can parameterize pragmas. The default parser just executes pragmas if it is allowed to execute pragmas in the core.
PRAGMA name ( (parameter (, parameter )* ) )?;
Here is excerpt of the parser definition in ANTLR4 grammar:
pragma :
KEYWORD_PRAGMA
pragmaName
staticParameters?
SEMI_COLON ;
pragmaName : identifier ;
pragma definePragma(de.s42.dl.pragmas.DisableDefineAnnotationsPragma);
pragma disableDefineTypes;
You wan write your own pragmas and map them into the core. See Package Source
Either derive directly from DLPragma or use the AbstractDLPragma abstract base class for convenience.
public interface DLPragma extends DLEntity
{
public void doPragma(DLCore core, Object... parameters) throws InvalidPragma;
}
Provides helper methods for implementing pragmas.
public class MyPragma extends AbstractDLPragma
{
public MyPragma()
{
super("myPragma");
}
@Override
public void doPragma(DLCore core, Object... parameters) throws InvalidPragma
{
parameters = validateParameters(parameters, new Class[]{Path.class});
// do stuff
}
}
The following implementations are part of the core library.
Allows to set the current base path of the core relative to the working directory.
pragma basePath(relativePath);
pragma basePath("../data");
Allows to map another pragma into the core.
pragma definePragma(pragmaImplementationClass);
pragma definePragma(my.app.MyPragma);
Disables possibility to define new annotations in the core.
pragma disableDefineAnnotations;
Disables possibility to define new pragmas in the core.
pragma disableDefinePragmas;
Disables possibility to define new types in the core.
pragma disableDefineTypes;
Disables possibility to require other modules in the core.
pragma disableRequire;
Copyright Studio 42 GmbH 2022.