Package eu.bandm.tools.rdparser
Class TunableParser<D>
java.lang.Object
eu.bandm.tools.rdparser.TunableParser<D>
- Direct Known Subclasses:
TunableParserForXml
Parser skeleton for explicit lexical decoding and recursive descent
("hand-coded") parsing of idiosyncratic grammars.
This base class has been abstracted from a XML DTD parser. Therefore
it is prepared
for "external entity expansion", which is "file inclusion" in a more
general way of talking.
This is maintained by
The interface methods fall in different categories:
IncludingCharBuf, to which all
character read, buffer insertion and buffer restore is delegated.
The interface methods fall in different categories:
-
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(..)andskipUpTo(..)consumes as long as the specified prefix is NOT reached (or end of input is reached).eof(..)matches iff end of input is reached.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAuxiliary class which realizes a character set by the characteristic predicate.static classAuxiliary class which realizes a character set by aBitSet. -
Field Summary
FieldsModifier and TypeFieldDescriptionBasis for resolving include directives.protected IncludingCharBuf<D> The current input.protected MessageReceiver<? super SimpleMessage<D>> protected intprotected intprotected DId for generating locations in messages. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTunableParser(Reader in, D id, MessageReceiver<? super SimpleMessage<D>> msg) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconsume()Advance input by one character position.protected voideof()Assume end of input reached.protected voidprotected voidprotected abstract voidfatalError(String s) Signals parsing errors, must be re-defined by derived class.MessageReceiver<? super SimpleMessage<D>> protected final booleanlookahead(char c) Returns whether the next character to read is equal to the parameter.protected final booleanlookahead(int k, char c) Returns whether the next character after (k-1) consumptions would be equal to the parameter.protected final booleanlookahead(int k, TunableParser.CharSet s) Returns whether the next character after (k-1) consumptions would be contained in the parameter.protected final booleanReturns whether the next character to read is contained in the parameter.protected final booleanReturns whether the current input is prefixed by the string parameter.protected booleanReport whether end of input reached.protected final charmatch()Consumes any character and returns it.protected final voidmatch(char c) Call tolookahead(char),must succeed, thenconsume().protected final charCall tolookahead(CharSet),must succeed, thenconsume().protected final voidCall tolookahead(String),must succeed, thenconsume().protected final booleanmatchahead(char c) Likelookahead(char), and thenconsume()if success.protected final booleanLikelookahead(CharSet), and thenconsume()if success.protected final booleanmatchahead(String prefix) Likelookahead(String), and thenconsume()if success.protected StringmatchUpto(char end) Consumes all characters upto (excluding) the given delimiter and returns them.protected StringConsumes all characters upto (excluding) the given delimiter and returns them.readExternal(String systemID) Read a file relative to the currentbaseand return its contents.voidset base for resolving include directives.voidsetMessageReceiver(MessageReceiver<? super SimpleMessage<D>> rec) protected voidConsumes all characters upto (excluding) the given delimiter and discard them.protected voidprotected Stringword(TunableParser.CharSet alphabet) Accept any sequence of characters from the given set, including the empty word, and return it.
-
Field Details
-
in
The current input. -
topleveldocumentid
Id for generating locations in messages. -
base
Basis for resolving include directives. -
startColumnNumber
protected int startColumnNumber -
startLineNumber
protected int startLineNumber -
messageReceiver
-
-
Constructor Details
-
TunableParser
Constructor.- Parameters:
in- source to parseid- id of toplevel document, for locations in messagesmsg- message channel
-
-
Method Details
-
setBase
set base for resolving include directives. -
setMessageReceiver
-
getMessageReceiver
-
error
-
failure
-
warning
-
fatalError
Signals parsing errors, must be re-defined by derived class. -
readExternal
Read a file relative to the currentbaseand 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.ATTENTION assume the file is UTF-8 encoded!
- Parameters:
systemID- a "system identifier", which is an URI according to [xml1.0]
-
lookahead
protected final boolean lookahead(char c) Returns whether the next character to read is equal to the parameter. -
lookahead
protected final boolean lookahead(int k, char c) Returns whether the next character after (k-1) consumptions would be equal to the parameter. -
lookahead
Returns whether the current input is prefixed by the string parameter. -
lookahead
Returns whether the next character to read is contained in the parameter. -
lookahead
Returns whether the next character after (k-1) consumptions would be contained in the parameter. -
matchahead
protected final boolean matchahead(char c) Likelookahead(char), and thenconsume()if success. -
matchahead
Likelookahead(String), and thenconsume()if success. -
matchahead
Likelookahead(CharSet), and thenconsume()if success. -
match
protected final void match(char c) -
match
-
match
-
match
protected final char match()Consumes any character and returns it. -
matchUpto
Consumes all characters upto (excluding) the given delimiter and returns them.
CallsfatalError(String)if reading beyond end of input. -
matchUpto
Consumes all characters upto (excluding) the given delimiter and returns them.
CallsfatalError(String)if reading beyond end of input. -
skipUpto
Consumes all characters upto (excluding) the given delimiter and discard them.
CallsfatalError(String)if reading beyond end of input. -
consume
protected void consume()Advance input by one character position. -
eof
protected void eof()Assume end of input reached. CallfatalError(String)if not. -
lookaheadEOF
protected boolean lookaheadEOF()Report whether end of input reached. -
word
Accept any sequence of characters from the given set, including the empty word, and return it.
-