Modifying the parser for vector feature label and filter expressions (extSymbology)

From gvSIG CE Wiki

Jump to: navigation, search

The extSymbology extension contains a parser that allows the user to define label and filter expressions for vector features. The exact syntax of this parser has never been published. However, it is possible to learn the syntax by inspecting the source code.

The parser is written in the JavaCC preprocessor language. The files in question have the extension ".jj":

 extSymbology/src/org/gvsig/symbology/fmap/labeling/parse/LabelExpressionParser.jj
 extSymbology/src/org/gvsig/symbology/fmap/rendering/filer/parser/ExpressionParser.jj

When extSymbology" is compiled using the build.xml Ant file, javacc is first called to preprocess the two files above and dynamically generate the following Java source code files from them:

 extSymbology/src/org/gvsig/symbology/fmap/labeling/parse/LabelExpressionParser.java
 extSymbology/src/org/gvsig/symbology/fmap/labeling/parse/LabelExpressionParserTokenManager.java
 extSymbology/src/org/gvsig/symbology/fmap/rendering/filer/parser/ExpressionParser.java
 extSymbology/src/org/gvsig/symbology/fmap/rendering/filer/parser/ExpressionParserTokenManager.java

These four files are then compiled to Java byte code and finally included in the JAR file of the extension.

In order to understand the label and filter expression syntax, it is therefore first necessary to understand the code in the two ".jj" files. The JavaCC syntax is nicely explained in these online tutorials:

In addition, a full description of JavaCC can be downloaded from http://www.engr.mun.ca/~theo/JavaCC-Tutorial/.