|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.multijava.mjc.ParsingController
This class manages the parsing of source code. It supports the use of multiple lexers and parsers to process nested languages (as in javadoc comments in Java programs). It includes most of the functionality of antlr.TokenStreamSelector, though for efficiency it duplicates the necessary code rather than inheriting it. This class buffers the tokens produced by multiple lexers and allows client parsers to accept tokens from just a single lexer.
| Nested Class Summary | |
static class |
ParsingController.ConfigurationException
This inner class represents exceptions that can be thrown because of misconfiguration of the parsing controller. |
class |
ParsingController.FilteredTokenStream
This inner class provides a token stream that accesses one of the lexers managed by the controller. |
(package private) class |
ParsingController.IndexedTokenBuffer
This inner class buffers tokens of a nested language and allows selection and discarding of a subset of these buffered tokens based on a reference to an index token of the surrounding language. |
(package private) static class |
ParsingController.InputState
This nested class is a hack to expose the line and column fields of LexerSharedInputState for reading. |
static class |
ParsingController.KeyException
This inner class represents exceptions that can be thrown because of bad key values passed as arguments to the outer classes methods. |
(package private) class |
ParsingController.StreamBufferPair
This inner class encapsulates a buffer and an input stream so they can be the stored as a single value in a map. |
static class |
ParsingController.TokenWrapper
This inner class wraps a single token. |
| Field Summary | |
private String |
activeKey
The key of the currently active input stream. |
private ParsingController.StreamBufferPair |
activeStreamBuffer
The currently active input stream and token buffer. |
private boolean |
discarding
Indicates whether tokens for the currently active stream are to be discarded. |
private boolean |
endOfFileReached
Indicates whether an end-of-file token has been received on some input stream. |
private boolean |
fetching
Indicates that a token fetch request is in progress for the active input stream. |
static antlr.Token |
IGNORE
A token that may be returned by lexers upon detecting a lexical pattern that triggers a switch between lexers (e.g., /** for switching to javadoc). |
private ParsingController.FilteredTokenStream |
initialFilteredStream
The output stream for the initially selected lexer. |
private boolean |
initialSet
Indicates whether the initial input stream has been selected. |
private ParsingController.InputState |
inputState
The input state that should be shared by the lexers bound to this parsing controller. |
private Stack |
keyStack
For efficiency, used to track the keys when switching between input streams. |
private Set |
keysToDiscard
The set of keys corresponding to lexers whose output are being discarded. |
private Map |
keyStreamBufferMap
Maps keys to lexers and buffers |
private int |
ltCount
|
private ParsingController.IndexedTokenBuffer |
nestedLanguageBuffer
The active buffer before the last pop operation. |
private static int |
NONE
When operationPending equals this, then no operations are pending. |
private int |
operationPending
Indicates whether any input stream switching operations (i.e., push, pop) are pending on completion of the current call to bufferNextToken. |
private String |
pendingKey
The key of any pending push operation. |
private static int |
POP
When operationPending equals this, then a pop operation is pending. |
private static int |
PUSH
When operationPending equals this, then a push operation is pending. |
private Stack |
streamBufferStack
Tracks the active input streams. |
private int |
unmatchedTypeLT
Number of LT tokens that have not been matched by GT in Type Arguments or Type Parameters |
private Set |
usedKeys
The set of keys corresponding to lexers whose output are being discarded or have been bound to output token streams. |
| Constructor Summary | |
ParsingController(Reader r,
File file)
Establish a parsing controller for the given reader. |
|
| Method Summary | |
void |
addInputStream(antlr.TokenStream stream,
String key)
Adds the given input stream to the controller and binds it to the given key. |
private void |
bufferNextToken()
Retrieves the next token from the currently active lexer and adds it to the appropriate buffer or discards it if necessary. |
int |
column()
Returns the current column number in the input. |
void |
discardAllTokensFor(String key)
Indicates that tokens generated by the lexer bound to the given key should be discarded instead of buffered. |
boolean |
discardTokensBefore(String key,
antlr.Token index)
Discards all tokens from the lexer bound to the given key that precede the given token of the surrounding language. |
File |
file()
Returns the file name of the input. |
antlr.TokenStream |
get(String key)
Returns the TokenStream corresponding to a given name. |
antlr.TokenStream |
getCurrentStream()
Returns the currently active input stream. |
antlr.TokenStream |
getStream(String sname)
Returns the named input stream (previously added with addInputStream). |
int |
getUnmatchedTypeLT()
get the value of unmatchedTypeLT |
ParsingController.FilteredTokenStream |
initialOutputStream()
Returns a token stream that provides tokens generated by the initial lexer. |
int |
line()
Returns the current line number in the input. |
private ParsingController.IndexedTokenBuffer |
newBlockedEmptyBuffer()
Factory method creates a new token buffer that is blocked and empty. |
void |
pop()
Pops a stream from the stack of input streams. |
private void |
processPop()
Pops a stream from the stack of input streams. |
private void |
processPush(String key)
Switches to a new input stream, maintaining a stack of the old input streams. |
void |
push(String key)
Switches to a new input stream for future token requests, maintaining a stack of the old input streams. |
void |
selectInitial(String key)
Makes the lexer bound to the given key the initial lexer. |
private void |
setActive(String key,
ParsingController.StreamBufferPair sbp)
Sets the given key, input stream, and token buffer to be active. |
void |
setUnmatchedTypeLT(int count)
set the value of unmatchedTypeLT |
antlr.LexerSharedInputState |
sharedInputState()
Returns an input state that can be shared by the lexers attached to this controller. |
ParsingController.FilteredTokenStream |
streamForBefore(String key,
antlr.Token index)
Returns a token stream from the lexer bound to the given key and containing all the tokens preceding the given token of the surrounding language. |
private void |
useKey(String key)
Registers that tokens generated by the lexer bound to the given key will be used or discarded. |
private void |
verifyHasKey(String key)
Verifies that the given key is bound to a lexer. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private ParsingController.InputState inputState
private boolean initialSet
private ParsingController.FilteredTokenStream initialFilteredStream
private Map keyStreamBufferMap
private Set usedKeys
private Set keysToDiscard
private boolean discarding
private Stack keyStack
private Stack streamBufferStack
private String activeKey
private ParsingController.StreamBufferPair activeStreamBuffer
private ParsingController.IndexedTokenBuffer nestedLanguageBuffer
private boolean endOfFileReached
private boolean fetching
private int operationPending
private int ltCount
private String pendingKey
operationPendingprivate int unmatchedTypeLT
private static final int NONE
operationPendingprivate static final int POP
operationPendingprivate static final int PUSH
operationPendingpublic static final antlr.Token IGNORE
/** for switching to javadoc). This token is not
passed to any client parsers but is swallowed by the parsing
controller. Using this token in a lexer allows the associated
parser to ignore the lexical triggers. Note that using a
"skip" token in ANTLR doesn't work for this purpose because the
generated lexer code will not return from a nextToken call
until a non-skip token is found. Thus using a skip token
causes the lexer switch to be delayed.
| Constructor Detail |
public ParsingController(Reader r,
File file)
sharedInputState() on this.
sharedInputState()| Method Detail |
public antlr.LexerSharedInputState sharedInputState()
public void addInputStream(antlr.TokenStream stream,
String key)
throws ParsingController.KeyException
ParsingController.KeyException - the given key is already bound or if
either argument is null public antlr.TokenStream getCurrentStream()
public antlr.TokenStream getStream(String sname)
public void selectInitial(String key)
throws ParsingController.KeyException,
ParsingController.ConfigurationException
ParsingController.KeyException - if the given key is not bound
ParsingController.ConfigurationException - if the initial lexer has already
been selected
public ParsingController.FilteredTokenStream initialOutputStream()
throws ParsingController.ConfigurationException
ParsingController.ConfigurationException - if the initial lexer has not been
selected. selectInitial(String)
public void discardAllTokensFor(String key)
throws ParsingController.KeyException
ParsingController.KeyException - if the given key is not bound
to a lexer or if a TokenStream for the key has already been exposed
public ParsingController.FilteredTokenStream streamForBefore(String key,
antlr.Token index)
throws ParsingController.KeyException
ParsingController.KeyException - if the given key is not bound to a
lexer
public boolean discardTokensBefore(String key,
antlr.Token index)
throws ParsingController.KeyException
ParsingController.KeyException - if the given key is not bound to a lexer
public void pop()
throws antlr.TokenStreamException
antlr.TokenStreamException - if a pending operation prevents
popping
public antlr.TokenStream get(String key)
throws ParsingController.KeyException,
antlr.TokenStreamException
key - the name of the TokenStream to return
ParsingController.KeyException
antlr.TokenStreamException
public void push(String key)
throws ParsingController.KeyException,
antlr.TokenStreamException
key - the unique identifier of the lexer to switch to
antlr.TokenStreamException - if a pending operation prevents
pushing
ParsingController.KeyException - if the given key is not bound to a lexer public File file()
public int line()
public int column()
private void bufferNextToken()
throws antlr.TokenStreamException
antlr.TokenStreamException - passed on from underlying lexer private void processPush(String key)
key - the unique identifier of the lexer to switch to private void processPop()
private void useKey(String key)
throws ParsingController.KeyException
key - the unique identifier of the lexer whose tokens are
to be discarded or passed to an output stream
ParsingController.KeyException - if the given key is not bound
to a lexer or if a TokenStream for the key has already been exposed
private void verifyHasKey(String key)
throws ParsingController.KeyException
ParsingController.KeyException - if the given key is not bound
private void setActive(String key,
ParsingController.StreamBufferPair sbp)
private ParsingController.IndexedTokenBuffer newBlockedEmptyBuffer()
public int getUnmatchedTypeLT()
public void setUnmatchedTypeLT(int count)
|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||