Back Home

How To Write a Language Definition

The Purpose of a LangDef

The LangDef is a global definition that handles the structure of an overall program in the outputted language. It is responsible for any code needed to bind the widgets together into a cohesive program, and for assembling the code generated by assorted widget definitions into the program at the appropriate places. Writing a Language Definition is a significantly more intensive process that writing a widget definition, and language definitions are by their nature much more flexible and broadly specified. Language Definitions can either use the included WidgetDef abstract class as a foundation for their library of widget definitions, or may if preferred create a new interface tailored to the needs of the desired output language.

The Structure of a LangDef

There are only three things which must be overridden in a given language definition:

String getLibPath()

Returns a string denoting the path to the library of widget definitions for the associated output language. The getLibPath method defaults to returning the string variable "libPath" which can then be defined in the constructor of the language definition, or can be bypassed entirely and getLibPath can be overridden to return something entirely different.

Class<? extends WidgetDef> getRootWidgetType()

Returns the WidgetDef associated with the root widget in the language's widget hierarchy.

String[][] generateCode(GUIFile guiFile, ErrorHandler errorHandler)

The master method of a language definition, it takes an error handler and the GUIFile associated with an ELVIS program and produces a double array of Strings, where the first entries correspond to the names of desired output files, and the second entry corresponds to their content. The errorHandler is any implementation of the interface ErrorHandler, which is called when an exception is encountered while generating the output code.

The Structure of a GUIFile

The GUIFile is the electronic representation of all the information specified in the ELVIS file. It has 4 basic components:

String fileName

The file name of the file associated with this ELVIS program.

List<Widget> widgets

A list of top-level widgets in the ELVIS program.

Set<Flag> flags

A set of Flag enumerations associated with the various settings of the GUIFile, such as whether modifiers are suppressed or whether the outputted code should be a stand-alone executable or not.

List<EventHandler> handlers

A list of the different types of event handlers that the controller interface will need to contain.

Documentation

The LangDef documentation is available here