public abstract class TunableParser<D> extends Object
TunedDTDParser
(in fact, it is an
extraction from the original code.) Therefore it is prepared
for "external entity expansion", which is "file inclusion" in a more
general way of talking.
This is maintained by IncludingCharBuf
, to which all
character read, buffer insertion and buffer restore is delegated.
boolean lookahead (...)
yields whether the current
input does match.
void match (...)
consumes specified input.
MUST match, otherwise calls "fatalError()"
boolean matchahead (...)
combination of both:
consumes specified input iff possible.
matchUpTo(..)
and skipUpTo(..)
consumes as long as the specified prefix is NOT reached (or end of input
is reached).
eof(..)
matches iff end of input is reached.
Modifier and Type | Class and Description |
---|---|
static interface |
TunableParser.CharSet
Auxiliary class which realizes a character set by the
characteristic predicate.
|
static class |
TunableParser.ExtensionalCharSet
Auxiliary class which realizes a character set by a
BitSet . |
Modifier and Type | Field and Description |
---|---|
protected @Opt URL |
base
Basis for resolving include directives.
|
protected IncludingCharBuf<D> |
in
The current input.
|
protected SimpleMessage.Generator<D> |
messageGenerator |
protected D |
topleveldocumentid
Id for generating locations in messages.
|
Modifier | Constructor and Description |
---|---|
protected |
TunableParser(Reader in,
D id,
MessageReceiver<? super SimpleMessage<D>> msg)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
consume()
Advance input by one character position.
|
protected void |
eof()
Assume end of input reached.
|
protected void |
error(String msg) |
protected void |
failure(String msg) |
protected abstract void |
fatalError(String s)
Signals parsing errors, must be re-defined by derived class.
|
MessageReceiver<? super SimpleMessage<D>> |
getMessageReceiver() |
protected boolean |
lookahead_eof()
Report whether end of input reached.
|
protected boolean |
lookahead(char c)
Returns whether the next character to read is equal to the parameter.
|
protected boolean |
lookahead(int k,
char c)
Returns whether the next character after (k-1) consumptions would be
equal to the parameter.
|
protected boolean |
lookahead(int k,
TunableParser.CharSet s)
Returns whether the next character after (k-1) consumptions would be
contained in the parameter.
|
protected boolean |
lookahead(String prefix)
Returns whether the current input is prefixed by the string parameter.
|
protected boolean |
lookahead(TunableParser.CharSet s)
Returns whether the next character to read is contained in the parameter.
|
protected char |
match()
Consumes any character and returns it.
|
protected void |
match(char c)
Call to
lookahead(char) ,must succeed, then consume() . |
protected void |
match(String prefix)
Call to
lookahead(String) ,must succeed, then consume() . |
protected char |
match(TunableParser.CharSet s)
Call to
lookahead(CharSet) ,must succeed, then consume() . |
protected boolean |
matchahead(char c)
Like
lookahead(char) , and then consume() if success. |
protected boolean |
matchahead(String prefix)
Like
lookahead(String) , and then consume() if success. |
protected boolean |
matchahead(TunableParser.CharSet s)
Like
lookahead(CharSet) , and then consume() if success. |
protected String |
matchUpto(char end)
Consumes all characters upto (excluding) the given delimiter
and returns them.
|
protected String |
matchUpto(String end)
Consumes all characters upto (excluding) the given delimiter
and returns them.
|
@Opt String |
readExternal(String systemID)
Read a file relative to the current
base and return its contents. |
void |
setBase(@Opt URL base)
set base for resolving include directives.
|
void |
setMessageReceiver(MessageReceiver<? super SimpleMessage<D>> messageReceiver) |
protected void |
skipUpto(String end)
Consumes all characters upto (excluding) the given delimiter
and discard them.
|
protected void |
warning(String msg) |
protected String |
word(TunableParser.CharSet alphabet)
Accept any sequence of characters from the given set, including
the empty word, and return it.
|
protected IncludingCharBuf<D> in
protected D topleveldocumentid
protected final SimpleMessage.Generator<D> messageGenerator
protected TunableParser(Reader in, D id, MessageReceiver<? super SimpleMessage<D>> msg)
in
- source to parseid
- id of toplevel document, for locations in messagesmsg
- message channelpublic void setMessageReceiver(MessageReceiver<? super SimpleMessage<D>> messageReceiver)
public MessageReceiver<? super SimpleMessage<D>> getMessageReceiver()
protected void error(String msg)
protected void failure(String msg)
protected void warning(String msg)
protected abstract void fatalError(String s)
@Opt public @Opt String readExternal(String systemID)
base
and return its contents.
Is based on URLs to allow include of RELATIVELY given files for files in the file
system as well as files given as resource/via class loader.systemID
- a "system identifier", which is an URI according to [xml1.0]protected final boolean lookahead(char c)
protected final boolean lookahead(int k, char c)
protected final boolean lookahead(String prefix)
protected final boolean lookahead(TunableParser.CharSet s)
protected final boolean lookahead(int k, TunableParser.CharSet s)
protected final boolean matchahead(char c)
lookahead(char)
, and then consume()
if success.protected final boolean matchahead(String prefix)
lookahead(String)
, and then consume()
if success.protected final boolean matchahead(TunableParser.CharSet s)
lookahead(CharSet)
, and then consume()
if success.protected final void match(char c)
protected final void match(String prefix)
protected final char match(TunableParser.CharSet s)
protected final char match()
protected String matchUpto(char end)
fatalError(String)
if reading beyond end of input.protected String matchUpto(String end)
fatalError(String)
if reading beyond end of input.protected void skipUpto(String end)
fatalError(String)
if reading beyond end of input.protected void consume()
protected void eof()
fatalError(String)
if not.protected boolean lookahead_eof()
protected String word(TunableParser.CharSet alphabet)
see also the complete user documentation .