public class BracesParser extends antlr.LLkParser implements PreprocTokenTypes
This grammar is not a top level grammar for parsing the Progress
source files. The text.g is such a grammar. This grammar
is supposed to be used from the class
internally.
ClearStream
The parsing starts when the driving code calls the braces() method
of this class.
No output is written to the output stream during parsing of braces. Everything inside and the braces themselves are dropped from the source and a substitution string is pushed back into the input stream so that the contents of the substitution will be read and interpreted (rescanned) next.
As soon as this parser reaches the closing brace token, the parser is done and the calling code resumes execution.
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 ClearStream class
that hides from the lexer some essential complexity of the preprocessing
like handling the alternative codings, escape sequences and substitutions
for braces. That automatically means that the nested braces are
processed recursively in the ClearStream, so any single
instance of the BracesParser has to deal with the non-nested
braces exclusively.
This parser recognizes and properly handles the following constructs:
{0}, {n}, {*}, {&*}, {&name}, {};
{&name};
{&name};
{file}, {file pos}, {file &name=value}
etc;
FileScope
instance is created and chained to the new dictionary scope by calling
Preprocessor.includeFile(com.goldencode.p2j.preproc.Environment, java.lang.String, java.util.Map, java.lang.String) method.ClearStream,
BracesLexer,
FileScope,
TextParser| 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_11 |
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 Environment |
env
Shared state for multiple lexers, parsers and the input stream.
|
private BracesLexer |
lexer
Token source.
|
private static ConversionStatus |
LOG
Logger.
|
private java.lang.String |
parserLookahead
Deferred parser lookahead that must be pushed back.
|
astFactory, inputState, returnAST, tokenNames, tokenTypeToASTClassMap, traceDepthAELSE, AELSEIF, AENDIF, AGLOBAL, AIF, ALPHA, AMESSAGE, AMPER, APOST, ARESUME, ASCOPED, ASTMT, ASTRING, ASUSPEND, ATHEN, AUNDEFINE, BREAK_CODE_CHUNKS, CODE, COMM_CLOSE, COMM_OPEN, COMMENT, DIGIT, DIGITS, EOF, EQUALS, LBRACE, NL, NULL_TREE_LOOKAHEAD, PPNAME, QSTRING, QUOTE, RBRACE, SLASH_SLASH, SPECIAL, STAR, STAR_COMMENT, STRING, TAB, WS, XAPOST, XQUOTE| Modifier | Constructor and Description |
|---|---|
|
BracesParser(Environment env,
BracesLexer lexer)
Constructor.
|
|
BracesParser(antlr.ParserSharedInputState state) |
|
BracesParser(antlr.TokenBuffer tokenBuf) |
protected |
BracesParser(antlr.TokenBuffer tokenBuf,
int k) |
|
BracesParser(antlr.TokenStream lexer) |
protected |
BracesParser(antlr.TokenStream lexer,
int k) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
anyfile()
Matches a sequence of characters that is distinguishable from an argument
reference and returns the sequence.
|
void |
anything()
Matches any sequence of characters except the closing brace
so they don't break the parsing process and discards them.
|
java.lang.String |
anythingButEquals(boolean drop)
Matches a sequence of characters until encountering a closing brace or
'=' and returns the sequence.
|
java.lang.String |
anythingButQuote()
Matches a sequence of characters until encountering a closing brace or
quote and returns the sequence.
|
java.lang.String |
anythingButSpace(boolean dropQuotes)
Matches a sequence of characters until encountering a closing brace or
space and returns the sequence.
|
java.lang.String |
anythingButSpaceOrAmpersand()
Matches a sequence of characters until encountering a closing brace,
ampersand, space or quote and returns the sequence.
|
java.lang.String |
anythingButSpaceOrQuote()
Matches a sequence of characters until encountering a closing brace,
space or double quote character and returns the sequence.
|
java.lang.String |
anythingButUnescapedQuote()
Matches a sequence of characters (including two sequential double quote
characters which is an escaping mechanism) until encountering a closing brace
or unescaped double quote and returns the sequence.
|
java.lang.String |
argref()
Matches all the argument references, even misformed ones and returns
their evaluations.
|
void |
arguments(java.util.Map args)
Matches arguments portion of the include file references and puts the
parsed arguments into a container.
|
java.lang.String |
argvalue(boolean discard)
Matches the argument value portion of either positional or named argument
and returns the value.
|
void |
braces()
Matches all the preprocessor constructs in braces and substitutes
them with their evaluations or activates new input files for the
include file references.
|
java.lang.String |
filename()
Matches include file name portion of the include file references
and returns the file name.
|
void |
incref()
Matches all the include file references and arranges their inclusion
into the input stream.
|
java.lang.String |
keyallref()
Matches the all named argument reference
{&*} and returns
its evaluation. |
java.lang.String |
keyarg(java.util.Map args,
int npos)
Matches a named argument and puts the parsed argument name and value
into a container.
|
void |
misformed()
Matches misformed named argument references so they don't break
the parsing process and discards them.
|
private static long[] |
mk_tokenSet_0() |
private static long[] |
mk_tokenSet_1() |
private static long[] |
mk_tokenSet_10() |
private static long[] |
mk_tokenSet_11() |
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() |
java.lang.String |
nameref()
Matches a named argument or variable reference and returns their
evaluation.
|
java.lang.String |
posallref()
Matches the all positional argument reference
{*}
and returns its evaluation. |
void |
posarg(java.util.Map args,
int npos,
boolean ignore)
Matches a positional argument and puts the parsed argument name and
value into a container.
|
java.lang.String |
posargref()
Matches positional argument references and returns their evaluations.
|
void |
reportError(antlr.RecognitionException re)
Writes error data to logger, including a full stack trace.
|
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, traceIndentprivate static final ConversionStatus LOG
private Environment env
private BracesLexer lexer
private java.lang.String parserLookahead
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 static final antlr.collections.impl.BitSet _tokenSet_11
public BracesParser(Environment env, BracesLexer lexer)
env - instance of the preprocessor environmentlexer - instance of the lexer to be the source of tokens
for this parserprotected BracesParser(antlr.TokenBuffer tokenBuf,
int k)
public BracesParser(antlr.TokenBuffer tokenBuf)
protected BracesParser(antlr.TokenStream lexer,
int k)
public BracesParser(antlr.TokenStream lexer)
public BracesParser(antlr.ParserSharedInputState state)
public void reportError(antlr.RecognitionException re)
reportError in class antlr.Parserre - The error on which to report.public final void braces()
throws antlr.RecognitionException,
antlr.TokenStreamException,
java.io.IOException
Valid alternatives include empty braces, braces with only whitespace
inside, braces containing an argument reference (named or positional) and
braces with an include file reference. The core processing is handled
by argref() and incref().
The expansion of braces can be disabled or enabled by using the
Environment.setExpandBraces(boolean). Note that no matter the state of the
expand flag, the braces and contained text will still be matched.
This is the top level recognizer for all braces.
antlr.RecognitionExceptionantlr.TokenStreamExceptionjava.io.IOExceptionpublic final java.lang.String argref()
throws antlr.RecognitionException,
antlr.TokenStreamException,
java.io.IOException
This is the top level recognizer for all references that produce a substitution (not include files).
antlr.RecognitionExceptionantlr.TokenStreamExceptionjava.io.IOExceptionpublic final void incref()
throws antlr.RecognitionException,
antlr.TokenStreamException
filename() and arguments(java.util.Map)
are used to handle the core parsing.
This is the top level recognizer for all references that resolve into include files versus substitutions.
antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String posargref()
throws antlr.RecognitionException,
antlr.TokenStreamException,
java.io.IOException
antlr.RecognitionExceptionantlr.TokenStreamExceptionjava.io.IOExceptionpublic final java.lang.String posallref()
throws antlr.RecognitionException,
antlr.TokenStreamException
{*}
and returns its evaluation.{*} as a string.antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String keyallref()
throws antlr.RecognitionException,
antlr.TokenStreamException
{&*} and returns
its evaluation.{&*} as a string.antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String nameref()
throws antlr.RecognitionException,
antlr.TokenStreamException,
java.io.IOException
antlr.RecognitionExceptionantlr.TokenStreamExceptionjava.io.IOExceptionpublic final void misformed()
throws antlr.RecognitionException,
antlr.TokenStreamException
antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final void anything()
throws antlr.RecognitionException,
antlr.TokenStreamException
antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String anythingButSpace(boolean dropQuotes)
throws antlr.RecognitionException,
antlr.TokenStreamException
dropQuotes - true if quote characters should be dropped from the text output.antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String filename()
throws antlr.RecognitionException,
antlr.TokenStreamException
antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final void arguments(java.util.Map args)
throws antlr.RecognitionException,
antlr.TokenStreamException
The first argument determines the parsing strategy. If positional, then
all subsequent arguments (even if they have the &name=value form)
will be parsed as positional (so the &name= text will be part of the
argument). If the first argument is named (prefixed with &name=),
then any stray text in between properly formatted named arguments will
be parsed as positional arguments and discarded as trash. See the rule
argvalue(boolean) for details on how the discard mode works.
Core parsing subroutines are keyarg(java.util.Map, int) and posarg(java.util.Map, int, boolean).
args - Container for arguments.antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String anythingButQuote()
throws antlr.RecognitionException,
antlr.TokenStreamException
antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String anyfile()
throws antlr.RecognitionException,
antlr.TokenStreamException
antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String anythingButUnescapedQuote()
throws antlr.RecognitionException,
antlr.TokenStreamException
antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String keyarg(java.util.Map args,
int npos)
throws antlr.RecognitionException,
antlr.TokenStreamException
AMPER. The argument name must follow this and the
anythingButEquals(boolean) rule parses that name. The resulting text has
all spaces removed before the name is stored.
For a valid value to be found, following the name must be an
EQUALS token. Finally, the value is parsed by the rule
argvalue(boolean). The resulting name and value pair is stored in the
given container.
If no EQUALS token is found after the name, then this named
argument and all other text until the closing RBRACE is
dropped. In such a case, even if there are properly formed named
arguments following the malformed one, these are all discarded.
If a named argument is matched that is a duplicate of a previously matched named argument, then the previously matched value will be honored and all subsequent instances of same name are discarded.
args - The container where the argument is put.npos - The position of this argument in the argument list.antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final void posarg(java.util.Map args,
int npos,
boolean ignore)
throws antlr.RecognitionException,
antlr.TokenStreamException
argvalue(boolean).
Names for the positional arguments are special combinations made of the opening brace character and the position number. This rule creates a separate namespace for the positional arguments.
args - The container where the argument is put.npos - The position of this argument in the argument list.ignore - true to force any matched argument to be discarded
instead of added to the container. This is needed to support
"trash" (that look like positional args) intermixed with named
argument processing.antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String anythingButEquals(boolean drop)
throws antlr.RecognitionException,
antlr.TokenStreamException
drop - true to drop whitespace from the returned text.antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String argvalue(boolean discard)
throws antlr.RecognitionException,
antlr.TokenStreamException
When parsing an argument's value any preceding whitespace is dropped though it is not required to have preceding whitespace. At that point, normal parsing of the value occurs. In this parsing, a double quote character will cause a special sub-parsing mode to occur where ampersands, equal signs and white space (characters that normally can't be part of an argument value) can be inserted into the argument value. This mode continues until a closing double quote is encountered OR until the right brace is encountered. This does mean that the closing double quote is optional, but in such a case it will consume everything up to the end of the include specification.
If not in the special quoted mode, the normal value parsing will continue until encountering whitespace or a double quote. Whitespace ends the parsing of a value and the captured text is returned. A double quote character will drop into the special quoted sub-parsing mode described above. Sequences of quoted "strings" and random characters can be freely intermixed to create the value for an argument. The only issue is that any whitespace that exists outside of the double quoted section will mark the end of the value.
It is valid to match nothing in this rule (no whitespace and no value) or
to only match whitespace. In such a case, the parsing will end if an
RBRACE is encountered. This is like having a value that is
an empty string.
In named parsing mode (if the first argument matched was a named
argument in the form &name=value), this method is also used to match
and discard any text in between valid named arguments. To mark this case,
the discard will be true. This changes the
parsing to process the so called "discard region". This region occurs
after the first unquoted whitespace which marks the end of the last valid
named argument. Anything after this point that is not an ampersand or
right brace will be discarded. There is no discard region if positional
parsing mode is active (the first argument matched was a positional
argument). This means that this discard mode will never be enabled for
positional parsing mode. This means that discard should
only be true if this is named parsing mode AND ALSO the
parser has entered the discard region.
In the discard region (between valid named arguments), double quotes lose their special behavior. Specifically, in the discard region the double quote character is treated as any other and cannot be used to "hide" ampersands or whitespace as it normally would. There is no concept of paired sets of double quotes in this part of the parsing.
Once encountering the discard region, whitespace is not required in the character immediately preceding the next ampersand, but rather as soon as the ampersand is encountered, the discard region is exited and the ampersand is treated as the beginning of the next valid named argument.
discard - If true, enter the special discard processing
mode. This should only be true if the parser is
in both named arguments mode AND a valid named argument value
has just been parsed.antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String anythingButSpaceOrAmpersand()
throws antlr.RecognitionException,
antlr.TokenStreamException
antlr.RecognitionExceptionantlr.TokenStreamExceptionpublic final java.lang.String anythingButSpaceOrQuote()
throws antlr.RecognitionException,
antlr.TokenStreamException
antlr.RecognitionExceptionantlr.TokenStreamExceptionprivate 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()
private static final long[] mk_tokenSet_11()