What to do to make use of the syntax module in a new command-line tool.


§1. Status. The syntax module provided as one of the "services" suite of modules, which means that it was built with a view to potential incorporation in multiple tools. It can be found, for example, in inform7, inbuild and syntax-test, among others. syntax-test may be useful as a minimal example of a tool using syntax.

By convention, the modules considered as "services" have no dependencies on other modules except for foundation and other "services" modules.

A tool can import syntax only if it also imports foundation and words.

§2. Importing the module. We'll use the term "parent" to mean the tool which is importing syntax, that is, which will include its code and be able to use it. As with any imported module,

Import: somepath/syntax

But in addition, the parent of syntax must define some Preform grammar:

Though compulsory, these don't need to do much: see Unit Tests (in syntax-test).

§3. Using callbacks. Shared modules like this one are tweaked in behaviour by defining "callback functions". This means that the parent might provide a function of its own which would answer a question put to it by the module, or take some action on behalf of the module: it's a callback in the sense that the parent is normally calling the module, but then the module calls the parent back to ask for data or action.

The parent must indicate which function to use by defining a constant with a specific name as being equal to that function's name. A fictional example would be

    @d EXPRESS_SURPRISE_SYNTAX_CALLBACK Emotions::gosh

    =
    void Emotions::gosh(text_stream *OUT) {
        WRITE("Good gracious!\n");
    }

The syntax module has many callbacks, but they are all optional. The following alphabetical list has references to fuller explanations: