EFX grammar
The efx-grammar folder of the SDK contains the grammar of the eForms Expression Language (EFX): the formal
definition of how EFX is written. You use it to build a program that reads EFX.
Contents of the folder
Efx.g4-
The parser grammar: the rules for how EFX expressions, template files and rules files are put together.
EfxLexer.g4-
The lexer grammar: the rules that divide EFX text into its smallest parts, called tokens, such as keywords, identifiers, literals and operators.
README.md-
A short description of the folder.
The grammar is written for ANTLR 4, a tool that generates parsers. From the two files, ANTLR generates a lexer, which divides the text into tokens, and a parser, which groups the tokens into expressions, template lines and rules. It can generate them in several programming languages, including Java, C#, Python, JavaScript and Go.
One grammar for the three flavours
The grammar defines the three flavours of EFX. Each flavour has its own entry rule, the rule where reading starts:
| Entry rule | Reads |
|---|---|
|
a single expression (EFX Expressions) |
|
a template file (EFX Templates) |
|
a rules file (EFX Rules) |
Syntax only
The grammar describes only the syntax of EFX: how you write the parts of an expression, a template file or a rules
file, and how they are grouped. It says nothing about their types. A single rule, expression, reads every
expression, whatever its type. The order of its alternatives gives the precedence of the operators, that is, which
operators apply first. A program that
reads EFX must find the types itself, from the SDK metadata and from the declarations, and check them (see
Type checking).
The grammar contains no code in any programming language. So you can generate a parser from it in every language that ANTLR supports.
Versions
The grammar in SDK 2 defines EFX-2. The SDK 1 versions contain the grammar of EFX-1.
Changes to the grammar that would make existing expressions invalid come only with a new major version of the SDK. Within a major version, the grammar can grow, but every expression that was valid stays valid.
Using the grammar
EFX does not run on its own. Applications translate it into a language that they can run, such as XPath, XSLT or Schematron. A program that translates or checks EFX starts from a parser generated from this grammar.
The EFX Toolkit for Java contains such a parser. It also contains translators of expressions into XPath and of rules files into Schematron. Its template translator needs a generator for the target markup, which the application supplies; the Notice Viewer sample application supplies one for XSLT. You can extend the toolkit for other target languages.
See also: