WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

Endpoint
Name:ANTLR Runtime
Description:Parse text into an AST using a grammar definition
Id:AntlrRuntime
Category:accessor
Identifier Syntax

ANTLR Runtime is an accessor using Active URI syntax with the following base identifiers:

Base
active:antlr

and the following arguments: (for more details on argument passing details see here)

ArgumentRulesTypingDescription
operator
Mandatory
Representation (org.netkernel.lang.antlr.AntlrGrammarRepresentation)Antlr Grammar Definition
operand
Mandatory
Representation (Determinate String)text to parse
startrule
Mandatory
Representation (Determinate String)The rule to use as the starting root of the grammar parser
filter
Optional
Representation (Determinate String)Comma separated string list of nodes to filter out
Request Verbs

The following verb is supported:

Verb
SOURCE
Response

The following response representations can be returned for SOURCE requests:

SOURCE Representations
HDS

This accessor throws no documented exceptions.

Import Requirements

To use ANTLR Runtime accessor you must import the module urn:org:netkernel:lang:antlr:

<import>
  <uri>urn:org:netkernel:lang:antlruri>
import>

The ANTLR runtime returns back a HDS representation of the abstract syntax tree of the input using the rule names at node names. Where anonymous literals are used in the grammar the node name of "LITERAL" is used. Any text capture is placed as the node values.

operator

The operator must a grammar using the Antlr variant of Extended Backus Naur Form (EBNF). Please refer to Antlr's reference documentation for the Antlr EBNF syntax.

This accessor requires that the code generation target must be Java (which is the default) and that the definition is a combined lexer parser.

Embedded code stubs are ignored.

operand

The operand is any text/string that conforms to the supplied operator grammar. A syntax error exception will be thrown if the input fails to match.

startrule

The startrule argument must specify the name of the rule in the operator grammar that will be used as the root to start parsing the input.

filter

An optional comma separated string with the names of nodes to be omitted from the final HDS response. Allows grammar chaff to be cleaned such as removing insignificant newlines, whitespace and delimiters.

JDK Requirements

This runtime must be run on a Java JDK not a JRE since it requires the java compiler to internally compile the ANTLR generated classes.

This runtime generates a temporary directory to in which to place files such as the grammar and Java source files because ANTLR can only work this way. This directory will be deleted when the compiled grammar representation is garbage collected.

Example

Using this operator grammar:

grammar Names;
file : line+;         
line : NAME NEWLINE;
NAME : ('a'..'z'|'A'..'Z')+ ;
NEWLINE : '\r'? '\n' ;
we can parse this operand input:
NSW
QLD
SA
TAS
NT
WA

with the rule argument of "file" we obtain the representation...

<file>
  <line>
    <NAME>NSWNAME>
    <NEWLINE />
  line>
  <line>
    <NAME>QLDNAME>
    <NEWLINE />
  line>
  <line>
    <NAME>SANAME>
    <NEWLINE />
  line>
  <line>
    <NAME>TASNAME>
    <NEWLINE />
  line>
  <line>
    <NAME>NTNAME>
    <NEWLINE />
  line>
  <line>
    <NAME>WANAME>
    <NEWLINE />
  line>
file>

if the filter argument is supplied and has a value of "NEWLINE" the following response is returned

<file>
  <line>
    <NAME>NSWNAME>
  line>
  <line>
    <NAME>QLDNAME>
  line>
  <line>
    <NAME>SANAME>
  line>
  <line>
    <NAME>TASNAME>
  line>
  <line>
    <NAME>NTNAME>
  line>
  <line>
    <NAME>WANAME>
  line>
file>