Skip to content

8 Pragmas

Studio 42 GmbH edited this page Dec 27, 2022 · 1 revision

Overview

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 ;

Examples

pragma definePragma(de.s42.dl.pragmas.DisableDefineAnnotationsPragma);

pragma disableDefineTypes;

Extend Pragmas

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.

Interface DLPragma

Source Code

public interface DLPragma extends DLEntity
{
  public void doPragma(DLCore core, Object... parameters) throws InvalidPragma;
}

Abstract Base Class DLPragma

Provides helper methods for implementing pragmas.

Source Code

Example Implementation

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
  }
}

Default Implementations

The following implementations are part of the core library.

basePath

Allows to set the current base path of the core relative to the working directory.

Source Code

pragma basePath(relativePath);

Example

pragma basePath("../data");

definePragma

Allows to map another pragma into the core.

Source Code

pragma definePragma(pragmaImplementationClass);

Example

pragma definePragma(my.app.MyPragma);

disableDefineAnnotations

Disables possibility to define new annotations in the core.

Source Code

pragma disableDefineAnnotations;

disableDefinePragmas

Disables possibility to define new pragmas in the core.

Source Code

pragma disableDefinePragmas;

disableDefineTypes

Disables possibility to define new types in the core.

Source Code

pragma disableDefineTypes;

disableRequire

Disables possibility to require other modules in the core.

Source Code

pragma disableRequire;