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.
It is prepared for use as a base class for
The interface methods fall in different categories:
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.
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 interface
Auxiliary class which realizes a character set by the characteristic predicate.static class
Auxiliary 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 D
Id for generating locations in messages. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
TunableParser
(Reader in, D id, MessageReceiver<? super SimpleMessage<D>> msg) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
consume()
Advance input by one character position.protected void
eof()
Assume end of input reached.protected void
protected void
protected abstract void
fatalError
(String s) Signals parsing errors, must be re-defined by derived class.MessageReceiver<? super SimpleMessage<D>>
protected final boolean
lookahead
(char c) Returns whether the next character to read is equal to the parameter.protected final boolean
lookahead
(int k, char c) Returns whether the next character after (k-1) consumptions would be equal to the parameter.protected final boolean
lookahead
(int k, TunableParser.CharSet s) Returns whether the next character after (k-1) consumptions would be contained in the parameter.protected final boolean
Returns whether the next character to read is contained in the parameter.protected final boolean
Returns whether the current input is prefixed by the string parameter.protected boolean
Report whether end of input reached.protected final char
match()
Consumes any character and returns it.protected final void
match
(char c) Call tolookahead(char)
,must succeed, thenconsume()
.protected final char
Call tolookahead(CharSet)
,must succeed, thenconsume()
.protected final void
Call tolookahead(String)
,must succeed, thenconsume()
.protected final boolean
matchahead
(char c) Likelookahead(char)
, and thenconsume()
if success.protected final boolean
Likelookahead(CharSet)
, and thenconsume()
if success.protected final boolean
matchahead
(String prefix) Likelookahead(String)
, and thenconsume()
if success.protected String
matchUpto
(char end) Consumes all characters upto (excluding) the given delimiter and returns them.protected String
Consumes all characters upto (excluding) the given delimiter and returns them.readExternal
(String systemID) Read a file relative to the currentbase
and return its contents.void
set base for resolving include directives.void
setMessageReceiver
(MessageReceiver<? super SimpleMessage<D>> rec) protected void
Consumes all characters upto (excluding) the given delimiter and discard them.protected void
protected String
word
(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. -
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 currentbase
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.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. -
lookahead_eof
protected boolean lookahead_eof()Report whether end of input reached. -
word
Accept any sequence of characters from the given set, including the empty word, and return it.
-