The instantiation contexts editor is used to define and organize predefined instantiation contexts for
use by the grammar coverage testset and the interactive debugging tools. The instantiation contexts are saved
in the grammar coverage file (the .grd file that is created alongside an ABNF grammar).
To edit the set of predefined instantiation contexts, select the Contexts tab at the bottom of the grammar editor:
The buttons have the following meaning:
The Details section at the right of the contexts list (not shown in the above image) allows some meta information to be attached to the selected context on the left, like its name and a short description, as well as other informations specific to the type of the selected context (see below).
Professional Edition only. The Query field can be used to simulate a query string like in a
HTTP GET request. This is mainly useful to test grammars using the Nuance SWI_var feature.
A JSON context is an instantiation context whose variables are bound to values specified as JSON objects. (JSON stands for JavaScript Object Notation.)
For JSON contexts, the variables and their associated values are configured directly in the Details section. Clicking on a value opens the JSON Editor for the corresponding variable.
A Program context represents an instantiation context generated as the result of running an external program. The program can accept any number of parameters (as specified in the Command Line text box), and must return (write) a JSON object on the standard output stream.
For program contexts, the Details section contains fields to specify the command-line used to call the external program, as well as the directory in which the program is started. They both can contain variable references that will be expanded when the program is executed. The currently supported variables are:
${project} - this variable will be replaced by
the absolute path of the Eclipse project containing the contexts
file.${grammardir} - this variable will be replaced
by the absolute path of the directory containing the
corresponding grammar file.A Java context is an instantiation context populated by a Java object (hereafter referred to as a Java context initializer). The class of this object is configured in the Details section, as well as the parameters passed to the object.
A Java context initializer must implement the
ContextInitializer
interface and must be in the classpath of the project
containing the grammar and the coverage file. The context
initializer class must have a default (no argument)
constructor that is used to create the context initializer
object when the Java context is used.
For Java contexts, the Details section contains fields
to specify the Java class to instantiate, as well as
parameters passed to the object when calling
its getContext
method. The parameter values can contain variable references
that will be expanded when getMethod is called on
the object. The currently supported variables are:
${project} - this variable will be replaced by
the absolute path of the Eclipse project containing the contexts
file.${grammardir} - this variable will be replaced
by the absolute path of the directory containing the
corresponding grammar file.Java contexts are typically used for grammars intended to be deployed on a servlet-based NuGram Server.
Since instantiation contexts can be costly to create and/or generate, instantiation contexts produced by Program contexts and Java contexts can be cached. To control caching (enabling it or disabling it), select the project in the Navigator view, right-click and select the Properties menu item, then select the Grammar Development properties page: