public class TextParser extends antlr.LLkParser implements PreprocTokenTypes
The parsing starts when a driving code calls the
method of this class. The processed output is written to an output
stream as the parsing progresses. As soon as the parser reaches
the end of file, the preprocessor is done.
text()
The parser calls the lexer's nextToken
method and works
with the stream of Token
objects. So, all the details
of tokenizations are hidden in the lexer. The lexer, in turn, reads
its input character by character from an input stream. The input
stream is an instance of the
class
that hides from the lexer some essential complexity of the preprocessing
like handling the alternative codings, escape sequences and substitutions
for braces.
ClearStream
The parser recognizes and properly handles the following constructs:
TextLexer
,
BracesParser
,
BracesLexer
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
_tokenNames |
static antlr.collections.impl.BitSet |
_tokenSet_0 |
static antlr.collections.impl.BitSet |
_tokenSet_1 |
static antlr.collections.impl.BitSet |
_tokenSet_10 |
static antlr.collections.impl.BitSet |
_tokenSet_2 |
static antlr.collections.impl.BitSet |
_tokenSet_3 |
static antlr.collections.impl.BitSet |
_tokenSet_4 |
static antlr.collections.impl.BitSet |
_tokenSet_5 |
static antlr.collections.impl.BitSet |
_tokenSet_6 |
static antlr.collections.impl.BitSet |
_tokenSet_7 |
static antlr.collections.impl.BitSet |
_tokenSet_8 |
static antlr.collections.impl.BitSet |
_tokenSet_9 |
private int |
condNesting
Tracks nesting level for conditional preproc directives.
|
private Environment |
env
Keeps a reference to the shared environment.
|
private int |
nested
Nesting level for text block processing.
|
astFactory, inputState, returnAST, tokenNames, tokenTypeToASTClassMap, traceDepth
AELSE, AELSEIF, AENDIF, AGLOBAL, AIF, ALPHA, AMESSAGE, AMPER, APOST, ARESUME, ASCOPED, ASTMT, ASTRING, ASUSPEND, ATHEN, AUNDEFINE, CODE, COMM_CLOSE, COMM_OPEN, COMMENT, DIGIT, DIGITS, EOF, EQUALS, LBRACE, NL, NULL_TREE_LOOKAHEAD, PPNAME, QSTRING, QUOTE, RBRACE, SPECIAL, STAR, STRING, TAB, WS, XAPOST, XQUOTE
Modifier | Constructor and Description |
---|---|
|
TextParser(antlr.ParserSharedInputState state) |
|
TextParser(antlr.TokenBuffer tokenBuf) |
protected |
TextParser(antlr.TokenBuffer tokenBuf,
int k) |
|
TextParser(antlr.TokenStream lexer) |
|
TextParser(antlr.TokenStream lexer,
Environment env)
Constructor.
|
protected |
TextParser(antlr.TokenStream lexer,
int k) |
Modifier and Type | Method and Description |
---|---|
void |
aif()
Matches the
&IF Progress preprocessor statement. |
void |
astmt()
Matches any mistyped or unrecognized Progress preprocessor statement.
|
void |
condtext()
Concludes the conditional input parsing for
&IF &ENDIF
preprocessor statements. |
void |
define(boolean global)
Matches
&GLOBAL-DEFINE and &SCOPED-DEFINE
preprocessor directives and creates newly defined preprocessor variable
in the corresponding scope. |
java.lang.String |
expression(int emit)
Gathers the preprocessor expression into a string
or ignores it.
|
void |
globdef()
Matches the
&GLOBAL-DEFINE Progress preprocessor statement. |
void |
message()
Matches
&MESSAGE preprocessor statement and prints
the message text into the error stream without incrementing the errors
count. |
private static long[] |
mk_tokenSet_0() |
private static long[] |
mk_tokenSet_1() |
private static long[] |
mk_tokenSet_10() |
private static long[] |
mk_tokenSet_2() |
private static long[] |
mk_tokenSet_3() |
private static long[] |
mk_tokenSet_4() |
private static long[] |
mk_tokenSet_5() |
private static long[] |
mk_tokenSet_6() |
private static long[] |
mk_tokenSet_7() |
private static long[] |
mk_tokenSet_8() |
private static long[] |
mk_tokenSet_9() |
void |
noop()
Matches the
&ANALYZE-SUSPEND and &ANALYZE-RESUME
preprocessor statements. |
java.lang.String |
ppname()
Matches sequence of tokens that make a preprocessor variable name.
|
void |
ppstatement()
Matches any Progress preprocessor statement, even mistyped one.
|
void |
reportError(antlr.RecognitionException re)
Writes error data to
System.err , including a full stack
trace. |
void |
scopdef()
Matches the
&SCOPED-DEFINE Progress preprocessor statement. |
void |
skipBlock()
Matches any non-interpretable block of text from the Progress source
file, including those containing nested
&IF &ENDIF
statements. |
void |
skipIf()
Matches non-interpretable block of text from the Progress source
file which is a fully coded
&IF &ENDIF statement, possibly
recursive. |
void |
text()
Matches any interpretable block of text from the Progress source
file.
|
void |
textBlock()
Matches any interpretable block of text from the Progress source
file.
|
void |
undefine()
Matches
&UNDEFINE preprocessor statement and removes
the first found definition of the preprocessor variable in the nearest
scope. |
addMessageListener, addParserListener, addParserMatchListener, addParserTokenListener, addSemanticPredicateListener, addSyntacticPredicateListener, addTraceListener, consumeUntil, consumeUntil, defaultDebuggingSetup, getAST, getASTFactory, getFilename, getInputState, getTokenName, getTokenNames, getTokenTypeToASTClassMap, isDebugMode, mark, match, match, matchNot, panic, recover, removeMessageListener, removeParserListener, removeParserMatchListener, removeParserTokenListener, removeSemanticPredicateListener, removeSyntacticPredicateListener, removeTraceListener, reportError, reportWarning, rewind, setASTFactory, setASTNodeClass, setASTNodeType, setDebugMode, setFilename, setIgnoreInvalidDebugCalls, setInputState, setTokenBuffer, traceIndent
private Environment env
private int nested
private int condNesting
public static final java.lang.String[] _tokenNames
public static final antlr.collections.impl.BitSet _tokenSet_0
public static final antlr.collections.impl.BitSet _tokenSet_1
public static final antlr.collections.impl.BitSet _tokenSet_2
public static final antlr.collections.impl.BitSet _tokenSet_3
public static final antlr.collections.impl.BitSet _tokenSet_4
public static final antlr.collections.impl.BitSet _tokenSet_5
public static final antlr.collections.impl.BitSet _tokenSet_6
public static final antlr.collections.impl.BitSet _tokenSet_7
public static final antlr.collections.impl.BitSet _tokenSet_8
public static final antlr.collections.impl.BitSet _tokenSet_9
public static final antlr.collections.impl.BitSet _tokenSet_10
public TextParser(antlr.TokenStream lexer, Environment env)
lexer
- The lexer for this instance.env
- The shared preprocessor environment.protected TextParser(antlr.TokenBuffer tokenBuf, int k)
public TextParser(antlr.TokenBuffer tokenBuf)
protected TextParser(antlr.TokenStream lexer, int k)
public TextParser(antlr.TokenStream lexer)
public TextParser(antlr.ParserSharedInputState state)
public void reportError(antlr.RecognitionException re)
System.err
, including a full stack
trace.reportError
in class antlr.Parser
re
- The error on which to report.public final void text() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&THEN
or &ELSE
statements when their appropriate preprocessor expressions evaluate
to those clauses.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void textBlock() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&THEN
or &ELSE
statements when their appropriate preprocessor expressions evaluate
to those clauses.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void ppstatement() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void globdef() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&GLOBAL-DEFINE
Progress preprocessor statement.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void scopdef() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&SCOPED-DEFINE
Progress preprocessor statement.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void undefine() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&UNDEFINE
preprocessor statement and removes
the first found definition of the preprocessor variable in the nearest
scope. Contrary to the parsing of define(boolean)
which consumes all
text up to the end of the line, this directive only consumes whitespace
followed by a single preprocessor name.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void message() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&MESSAGE
preprocessor statement and prints
the message text into the error stream without incrementing the errors
count.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void noop() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&ANALYZE-SUSPEND
and &ANALYZE-RESUME
preprocessor statements. Everything is parsed to the end of the line
and is dropped. The newline is preserved in the output.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void aif() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&IF
Progress preprocessor statement.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void astmt() throws antlr.RecognitionException, antlr.TokenStreamException
antlr.RecognitionException
antlr.TokenStreamException
public final void define(boolean global) throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&GLOBAL-DEFINE
and &SCOPED-DEFINE
preprocessor directives and creates newly defined preprocessor variable
in the corresponding scope. This consumes everything up to the end of
the line and uses the text (trimmed of spaces at the front and back) as
the value of the preprocessor variable.global
- true
if this is a &GLOBAL-DEFINE
and
false
for &SCOPED-DEFINE
.antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final java.lang.String ppname() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final void condtext() throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
&IF &ENDIF
preprocessor statements. Due to the nested nature of conditional
statements, this method may be called recursively.
The preprocessor expression evaluation is done in two steps.
Firstly, the entire expression is gathered from multiple lexer tokens
into a string by calling the expression
method.
Secondly, if the expression has to be evaluated, the
method
is called to do the job.Preprocessor.evaluate(Environment,String)
antlr.RecognitionException
antlr.TokenStreamException
java.io.IOException
public final java.lang.String expression(int emit) throws antlr.RecognitionException, antlr.TokenStreamException, java.io.IOException
emit
- if 0, instructs the method to gather expression tokens
into a string, otherwise the expression is ignored.emit
is 0, or "".java.io.IOException
antlr.RecognitionException
antlr.TokenStreamException
public final void skipBlock() throws antlr.RecognitionException, antlr.TokenStreamException
&IF &ENDIF
statements. Non-interpretable blocks are the result of the preprocessor
expressions evaluated so they cause bypassing of corresponding
clauses of &IF...&ENDIF
statements.
It is not possible to take the simple approach of matching everything
until the next &ELSEIF, &ELSE or &ENDIF
because there may be
a nested &IF
inside this block. In such a case, the
&IF
block will definitely have its own &ENDIF
(and may also have its own &ELSEIF or &ELSE
) which should
not cause the termination of this loop since the entire
&IF...&ENDIF
is dead code. The matching loop can only
terminate when it reaches an &ELSEIF, &ELSE or &ENDIF
that
is at the same level (no nesting) as the current block being skipped. The
skipIf()
rule handles matching any nested &IF
constructs and uses recursion to handle any nested blocks that are
nested inside of the nested block and so on.
Note that braces expansion must be disabled before entering this rule
since the lookahead processing may trigger expansion of includes or
argument references before this rule can be executed. Since braces are
not expanded inside skipped conditional blocks in Progress, this is
valid. This behavior also enables include files to include themselves
recursively (so long as the &IF
) blocks are VERY carefully
crafted. This rule will always re-enable braces expansions before it
returns.
antlr.RecognitionException
antlr.TokenStreamException
public final void skipIf() throws antlr.RecognitionException, antlr.TokenStreamException
&IF &ENDIF
statement, possibly
recursive. Non-interpretable blocks are the result of the preprocessor
expressions evaluated so they cause bypassing of corresponding
clauses of &IF...&ENDIF
statements.
This is a simple replacement for the aif()
rule which discards
any content and uses recursion to drop any nested conditional blocks.
See skipBlock()
which is the only user of this rule.
antlr.RecognitionException
antlr.TokenStreamException
private static final long[] mk_tokenSet_0()
private static final long[] mk_tokenSet_1()
private static final long[] mk_tokenSet_2()
private static final long[] mk_tokenSet_3()
private static final long[] mk_tokenSet_4()
private static final long[] mk_tokenSet_5()
private static final long[] mk_tokenSet_6()
private static final long[] mk_tokenSet_7()
private static final long[] mk_tokenSet_8()
private static final long[] mk_tokenSet_9()
private static final long[] mk_tokenSet_10()