C# 클래스 Spring.Expressions.Parser.antlr.TokenStreamRewriteEngine

This token stream tracks the *entire* token stream coming from a lexer, but does not pass on the whitespace (or whatever else you want to discard) to the parser.

This class can then be asked for the ith token in the input stream. Useful for dumping out the input stream exactly after doing some augmentation or other manipulations. Tokens are index from 0..n-1

You can insert stuff, replace, and delete chunks. Note that the operations are done lazily--only if you convert the buffer to a string. This is very efficient because you are not moving data around all the time. As the buffer of tokens is converted to strings, the toString() method(s) check to see if there is an operation at the current index. If so, the operation is done and then normal string rendering continues on the buffer. This is like having multiple Turing machine instruction streams (programs) operating on a single input tape. :)

Since the operations are done lazily at toString-time, operations do not screw up the token index values. That is, an insert operation at token index i does not change the index values for tokens i+1..n-1.

Because operations never actually alter the buffer, you may always get the original token stream back without undoing anything. Since the instructions are queued up, you can easily simulate transactions and roll back any changes if there is an error just by removing instructions. For example,

For example: TokenStreamRewriteEngine rewriteEngine = new TokenStreamRewriteEngine(lexer); JavaRecognizer parser = new JavaRecognizer(rewriteEngine); ... rewriteEngine.insertAfter("pass1", t, "foobar");} rewriteEngine.insertAfter("pass2", u, "start");} System.Console.Out.WriteLine(rewriteEngine.ToString("pass1")); System.Console.Out.WriteLine(rewriteEngine.ToString("pass2"));

You can also have multiple "instruction streams" and get multiple rewrites from a single pass over the input. Just name the instruction streams and use that name again when printing the buffer. This could be useful for generating a C file and also its header file--all from the same buffer.

If you don't use named rewrite streams, a "default" stream is used.

Terence Parr, [email protected] University of San Francisco February 2004

상속: TokenStream
파일 보기 프로젝트 열기: spring-projects/spring-net

보호된 프로퍼티들

프로퍼티 타입 설명
discardMask antlr.collections.impl.BitSet
index int
lastRewriteTokenIndexes System.Collections.IDictionary
programs System.Collections.IDictionary
stream TokenStream
tokens System.Collections.IList

공개 메소드들

메소드 설명
ToDebugString ( ) : string
ToDebugString ( int start, int end ) : string
ToOriginalString ( ) : string
ToOriginalString ( int start, int end ) : string
ToString ( ) : string
ToString ( int start, int end ) : string
ToString ( string programName ) : string
ToString ( string programName, int start, int end ) : string
TokenStreamRewriteEngine ( TokenStream upstream )
TokenStreamRewriteEngine ( TokenStream upstream, int initialSize )
delete ( IToken indexT ) : void
delete ( IToken from, IToken to ) : void
delete ( int index ) : void
delete ( int from, int to ) : void
delete ( string programName, IToken from, IToken to ) : void
delete ( string programName, int from, int to ) : void
deleteProgram ( ) : void
deleteProgram ( string programName ) : void

Reset the program so that no instructions exist

discard ( int ttype ) : void
getLastRewriteTokenIndex ( ) : int
getToken ( int i ) : TokenWithIndex
getTokenStreamSize ( ) : int
insertAfter ( IToken t, string text ) : void
insertAfter ( int index, string text ) : void
insertAfter ( string programName, IToken t, string text ) : void
insertAfter ( string programName, int index, string text ) : void
insertBefore ( IToken t, string text ) : void
insertBefore ( int index, string text ) : void
insertBefore ( string programName, IToken t, string text ) : void
insertBefore ( string programName, int index, string text ) : void
nextToken ( ) : IToken
replace ( IToken from, IToken to, string text ) : void
replace ( IToken indexT, string text ) : void
replace ( int from, int to, string text ) : void
replace ( int index, string text ) : void
replace ( string programName, IToken from, IToken to, string text ) : void
replace ( string programName, int from, int to, string text ) : void
rollback ( int instructionIndex ) : void
rollback ( string programName, int instructionIndex ) : void

Rollback the instruction stream for a program so that the indicated instruction (via instructionIndex) is no longer in the stream.

UNTESTED!

보호된 메소드들

메소드 설명
addToSortedRewriteList ( RewriteOperation op ) : void

If op.index > lastRewriteTokenIndexes, just add to the end. Otherwise, do linear

addToSortedRewriteList ( string programName, RewriteOperation op ) : void
getLastRewriteTokenIndex ( string programName ) : int
getProgram ( string name ) : System.Collections.IList
setLastRewriteTokenIndex ( string programName, int i ) : void

비공개 메소드들

메소드 설명
initializeProgram ( string name ) : System.Collections.IList

메소드 상세

ToDebugString() 공개 메소드

public ToDebugString ( ) : string
리턴 string

ToDebugString() 공개 메소드

public ToDebugString ( int start, int end ) : string
start int
end int
리턴 string

ToOriginalString() 공개 메소드

public ToOriginalString ( ) : string
리턴 string

ToOriginalString() 공개 메소드

public ToOriginalString ( int start, int end ) : string
start int
end int
리턴 string

ToString() 공개 메소드

public ToString ( ) : string
리턴 string

ToString() 공개 메소드

public ToString ( int start, int end ) : string
start int
end int
리턴 string

ToString() 공개 메소드

public ToString ( string programName ) : string
programName string
리턴 string

ToString() 공개 메소드

public ToString ( string programName, int start, int end ) : string
programName string
start int
end int
리턴 string

TokenStreamRewriteEngine() 공개 메소드

public TokenStreamRewriteEngine ( TokenStream upstream )
upstream TokenStream

TokenStreamRewriteEngine() 공개 메소드

public TokenStreamRewriteEngine ( TokenStream upstream, int initialSize )
upstream TokenStream
initialSize int

addToSortedRewriteList() 보호된 메소드

If op.index > lastRewriteTokenIndexes, just add to the end. Otherwise, do linear
protected addToSortedRewriteList ( RewriteOperation op ) : void
op RewriteOperation
리턴 void

addToSortedRewriteList() 보호된 메소드

protected addToSortedRewriteList ( string programName, RewriteOperation op ) : void
programName string
op RewriteOperation
리턴 void

delete() 공개 메소드

public delete ( IToken indexT ) : void
indexT IToken
리턴 void

delete() 공개 메소드

public delete ( IToken from, IToken to ) : void
from IToken
to IToken
리턴 void

delete() 공개 메소드

public delete ( int index ) : void
index int
리턴 void

delete() 공개 메소드

public delete ( int from, int to ) : void
from int
to int
리턴 void

delete() 공개 메소드

public delete ( string programName, IToken from, IToken to ) : void
programName string
from IToken
to IToken
리턴 void

delete() 공개 메소드

public delete ( string programName, int from, int to ) : void
programName string
from int
to int
리턴 void

deleteProgram() 공개 메소드

public deleteProgram ( ) : void
리턴 void

deleteProgram() 공개 메소드

Reset the program so that no instructions exist
public deleteProgram ( string programName ) : void
programName string
리턴 void

discard() 공개 메소드

public discard ( int ttype ) : void
ttype int
리턴 void

getLastRewriteTokenIndex() 공개 메소드

public getLastRewriteTokenIndex ( ) : int
리턴 int

getLastRewriteTokenIndex() 보호된 메소드

protected getLastRewriteTokenIndex ( string programName ) : int
programName string
리턴 int

getProgram() 보호된 메소드

protected getProgram ( string name ) : System.Collections.IList
name string
리턴 System.Collections.IList

getToken() 공개 메소드

public getToken ( int i ) : TokenWithIndex
i int
리턴 TokenWithIndex

getTokenStreamSize() 공개 메소드

public getTokenStreamSize ( ) : int
리턴 int

insertAfter() 공개 메소드

public insertAfter ( IToken t, string text ) : void
t IToken
text string
리턴 void

insertAfter() 공개 메소드

public insertAfter ( int index, string text ) : void
index int
text string
리턴 void

insertAfter() 공개 메소드

public insertAfter ( string programName, IToken t, string text ) : void
programName string
t IToken
text string
리턴 void

insertAfter() 공개 메소드

public insertAfter ( string programName, int index, string text ) : void
programName string
index int
text string
리턴 void

insertBefore() 공개 메소드

public insertBefore ( IToken t, string text ) : void
t IToken
text string
리턴 void

insertBefore() 공개 메소드

public insertBefore ( int index, string text ) : void
index int
text string
리턴 void

insertBefore() 공개 메소드

public insertBefore ( string programName, IToken t, string text ) : void
programName string
t IToken
text string
리턴 void

insertBefore() 공개 메소드

public insertBefore ( string programName, int index, string text ) : void
programName string
index int
text string
리턴 void

nextToken() 공개 메소드

public nextToken ( ) : IToken
리턴 IToken

replace() 공개 메소드

public replace ( IToken from, IToken to, string text ) : void
from IToken
to IToken
text string
리턴 void

replace() 공개 메소드

public replace ( IToken indexT, string text ) : void
indexT IToken
text string
리턴 void

replace() 공개 메소드

public replace ( int from, int to, string text ) : void
from int
to int
text string
리턴 void

replace() 공개 메소드

public replace ( int index, string text ) : void
index int
text string
리턴 void

replace() 공개 메소드

public replace ( string programName, IToken from, IToken to, string text ) : void
programName string
from IToken
to IToken
text string
리턴 void

replace() 공개 메소드

public replace ( string programName, int from, int to, string text ) : void
programName string
from int
to int
text string
리턴 void

rollback() 공개 메소드

public rollback ( int instructionIndex ) : void
instructionIndex int
리턴 void

rollback() 공개 메소드

Rollback the instruction stream for a program so that the indicated instruction (via instructionIndex) is no longer in the stream.
UNTESTED!
public rollback ( string programName, int instructionIndex ) : void
programName string
instructionIndex int
리턴 void

setLastRewriteTokenIndex() 보호된 메소드

protected setLastRewriteTokenIndex ( string programName, int i ) : void
programName string
i int
리턴 void

프로퍼티 상세

discardMask 보호되어 있는 프로퍼티

Which (whitespace) token(s) to throw out
protected antlr.collections.impl.BitSet discardMask
리턴 antlr.collections.impl.BitSet

index 보호되어 있는 프로퍼티

track index of tokens
protected int index
리턴 int

lastRewriteTokenIndexes 보호되어 있는 프로퍼티

Map string (program name) -> Integer index
protected System.Collections.IDictionary lastRewriteTokenIndexes
리턴 System.Collections.IDictionary

programs 보호되어 있는 프로퍼티

You may have multiple, named streams of rewrite operations. I'm calling these things "programs." Maps string (name) -> rewrite (List)
protected System.Collections.IDictionary programs
리턴 System.Collections.IDictionary

stream 보호되어 있는 프로퍼티

Who do we suck tokens from?
protected TokenStream stream
리턴 TokenStream

tokens 보호되어 있는 프로퍼티

Track the incoming list of tokens
protected System.Collections.IList tokens
리턴 System.Collections.IList