Aims specifically at transforming the HSQLDB codebase to one of a small number of specific build targets, while keeping complexity and external dependencies to a minimum, yet providing an environment that is sufficiently powerful to solve most easily imaginable preprocessing scenarios. Supports the following (case-sensitive) directives:
( IDENT
| IDENT ( EQ | LT | LTE | GT | GTE ) VALUE
| BOOLEXPR { OR | XOR | AND } BOOLEXPR
| NOT BOOLEXPR
| LPAREN BOOLEXPR RPAREN )
and VALUE is :
( STRING | NUMBER | IDENT )and lexicographic elements are :
ASSIGN : '=' EQ : '==' LT :The lexicographic definitions above use the BNF conventions :'<'LTE :'<='GT :'>'GTE :'>='OR : ('|' | '||') XOR : '^' AND :('&' | '&&')NOT : '!' DQUOTE : '"' LPAREN : '(' RPAREN : ')' DOT : '.' DIGIT : ['0'..'9'] EOL : ('\n' | '\r' | '\n\r') SPACE : (' ' | '\t') NON_DQUOTE : { ANY_UNICODE_CHARACTER_EXCEPT_DQUOTE_OR_EOL } -- see the unicode spec NON_SPACE : { ANY_UNICODE_CHARACTER_EXCEPT_SPACE_OR_EOL } -- see the unicode spec WS : { JAVA_WS } -- see java.lang.Character NON_WS : { ANY_UNICODE_CHARACTER_EXCEPT_WS_OR_EOL } STRING : DQUOTE NON_DQUOTE* DQUOTE NUMBER : DIGIT+ (DOT DIGIT*)? IDENT : JAVA_IDENT_START JAVA_IDENT_PART* -- see java.lang.Character FILEPATH : NON_SPACE (ANY_UNICODE_CHARACTER* NON_WS)? -- i.e. trailing SPACE elements are ignored
'?' : zero or one '*' : zero or more '+' : one or moreDirectives may be arbitrarily indented; there is an option (INDENT) to set or unset directive indentation on output. There is also an option (FILTER) to remove directive lines from output. See
Option for other
preprocessor options.
'//#ifxxx' directives may be nested to arbitrary depth, may be chained with an arbitrary number of '//#elifxxx' directives, may be optionally followed by a single '//#else' directive, and must be terminated by a single '//#endif' directive.
Each '//#include' directive must be terminated by an '//#endinclude' directive; lines between '//#include' and '//#endinclude' are replaced by the content retrieved from the specified FILEPATH.
Included files are preprocessed in a nested scope that inherits the defined symbols of the including scope. Directive lines in included files are always excluded from output.
Design Notes
There are many better/more sophisticated preprocessors/templating engines out there. FreeMaker and Velocity come to mind immediately. Another--the NetBeans MIDP preprocessor--was the direct inspiration for this class.
Other options were rejected because the work of creating this class appeared to be less than dealing with the complexity and dependency issues of hooking up to external libraries. The NetBeans preprocessor, in particular, was rejected because it was not immediately evident how to invoke it independently from the IDE, how to make it available to non-MIDP projects from within the IDE or how to isolate the correct OpenIDE jars to allow stand-alone operation.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| pack-priv static final int | |
| private final Defines | |
| private final Document | |
| private final String | |
| private final String | |
| private final int | |
| private final IResolver | |
| private final Stack | |
| private int | |
| pack-priv static final Integer[] |
| Access | Constructor and Description |
|---|---|
| private | Preprocessor(String documentPath, String encoding, int options, IResolver resolver, String predefined)
|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| private void | |
| private Document | |
| private static void | |
| private boolean | |
| public static void | preprocessBatch(File
under which input files are located sourceDir, File under which output files are to be written targetDir, String[] to be preprocessed fileNames, String to use for output file names altExt, String with which to write output files encoding, int used to control preprocessing options, String CSV list of symbol definition expressions defines, IResolver with which to perform property and path expansions resolver)Preprocesses the specified list of files. |
| public static void | preprocessFile(File
under which the input file is located sourceDir, File under which the output file is to be written targetDir, String to be preprocessed fileName, String to use for output file name altExt, String with which to write output file encoding, int used to control preprocessing options, String CSV list of symbol definition expressions defines, IResolver with which to perform property and path expansions resolver)Preprocesses a single file. |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private int | |
| private Line | |
| private String | |
| private void | |
| private void | |
| private void | |
| private File | |
| private String | |
| private static String | |
| private static String |
| CONDITION_ARMED | back to summary |
|---|---|
| pack-priv static final int CONDITION_ARMED | |
| CONDITION_IN_TRUE | back to summary |
|---|---|
| pack-priv static final int CONDITION_IN_TRUE | |
| CONDITION_NONE | back to summary |
|---|---|
| pack-priv static final int CONDITION_NONE | |
| CONDITION_TRIGGERED | back to summary |
|---|---|
| pack-priv static final int CONDITION_TRIGGERED | |
| defines | back to summary |
|---|---|
| private final Defines defines | |
| document | back to summary |
|---|---|
| private final Document document | |
| documentPath | back to summary |
|---|---|
| private final String documentPath | |
| encoding | back to summary |
|---|---|
| private final String encoding | |
| options | back to summary |
|---|---|
| private final int options | |
| resolver | back to summary |
|---|---|
| private final IResolver resolver | |
| stack | back to summary |
|---|---|
| private final Stack<E> stack | |
| state | back to summary |
|---|---|
| private int state | |
| STATES | back to summary |
|---|---|
pack-priv static final Integer[] STATES
| |
| Preprocessor | back to summary |
|---|---|
| private Preprocessor(String documentPath, String encoding, int options, IResolver resolver, String predefined) throws PreprocessorException | |
| Preprocessor | back to summary |
|---|---|
| private Preprocessor(Preprocessor other, Document include) | |
| isHidingLines | back to summary |
|---|---|
| private boolean isHidingLines() | |
| loadDocument | back to summary |
|---|---|
| private void loadDocument() throws PreprocessorException | |
| loadInclude | back to summary |
|---|---|
| private Document loadInclude(String path) throws PreprocessorException | |
| log | back to summary |
|---|---|
| private static void log(Object toLog) | |
| preprocess | back to summary |
|---|---|
| private boolean preprocess() throws PreprocessorException | |
| preprocessBatch | back to summary |
|---|---|
| public static void preprocessBatch(File sourceDir, File targetDir, String[] fileNames, String altExt, String encoding, int options, String defines, IResolver resolver) throws PreprocessorException Preprocesses the specified list of files.
| |
| preprocessFile | back to summary |
|---|---|
| public static void preprocessFile(File sourceDir, File targetDir, String fileName, String altExt, String encoding, int options, String defines, IResolver resolver) throws PreprocessorException Preprocesses a single file.
| |
| preprocessImpl | back to summary |
|---|---|
| private void preprocessImpl() throws PreprocessorException | |
| processDirective | back to summary |
|---|---|
| private void processDirective(Line line) throws PreprocessorException | |
| processElse | back to summary |
|---|---|
| private void processElse() throws PreprocessorException | |
| processElseIf | back to summary |
|---|---|
| private void processElseIf(boolean condition) throws PreprocessorException | |
| processEndIf | back to summary |
|---|---|
| private void processEndIf() throws PreprocessorException | |
| processIf | back to summary |
|---|---|
| private void processIf(boolean condition) | |
| processInclude | back to summary |
|---|---|
| private int processInclude(int lineCount, Line line) throws PreprocessorException | |
| resolveLine | back to summary |
|---|---|
| private Line resolveLine(String line) throws PreprocessorException | |
| resolvePath | back to summary |
|---|---|
| private String resolvePath(String path) | |
| saveDocument | back to summary |
|---|---|
| private void saveDocument(Object target) throws PreprocessorException | |
| statePop | back to summary |
|---|---|
private void statePop()
| |
| statePush | back to summary |
|---|---|
private void statePush()
| |
| toCanonicalOrAbsoluteFile | back to summary |
|---|---|
| private File toCanonicalOrAbsoluteFile(String path) | |
| toSourceLine | back to summary |
|---|---|
| private String toSourceLine(final Line line) | |
| translateFileExtension | back to summary |
|---|---|
| private static String translateFileExtension(String fileName, String ext) | |
| translatePath | back to summary |
|---|---|
| private static String translatePath(File dir, String fileName, String ext) | |