antlr

Class CharScanner

public abstract class CharScanner extends Object implements TokenStream

Field Summary
protected booleancaseSensitive
protected booleancaseSensitiveLiterals
protected booleancommitToPath
Used during filter mode to indicate that path is desired.
static charEOF_CHAR
protected ANTLRHashStringhashString
protected LexerSharedInputStateinputState
protected Hashtableliterals
static charNO_CHAR
protected booleansaveConsumedInput
protected inttabsize
Tab chars are handled by tab() according to this value; override method to do anything weird with tabs.
protected ANTLRStringBuffertext
protected ClasstokenObjectClass
protected inttraceDepth
Used to keep track of indentdepth for traceIn/Out
protected Token_returnToken
Constructor Summary
CharScanner()
CharScanner(InputBuffer cb)
CharScanner(LexerSharedInputState sharedState)
Method Summary
voidappend(char c)
voidappend(String s)
voidcommit()
voidconsume()
voidconsumeUntil(int c)
Consume chars until one matches the given char
voidconsumeUntil(BitSet set)
Consume chars until one matches the given set
booleangetCaseSensitive()
booleangetCaseSensitiveLiterals()
intgetColumn()
booleangetCommitToPath()
StringgetFilename()
InputBuffergetInputBuffer()
LexerSharedInputStategetInputState()
intgetLine()
intgetTabSize()
StringgetText()
return a copy of the current text buffer
TokengetTokenObject()
charLA(int i)
protected TokenmakeToken(int t)
intmark()
voidmatch(char c)
voidmatch(BitSet b)
voidmatch(String s)
voidmatchNot(char c)
voidmatchRange(char c1, char c2)
voidnewline()
voidpanic()
voidpanic(String s)
This method is executed by ANTLR internally when it detected an illegal state that cannot be recovered from.
voidreportError(RecognitionException ex)
Parser error-reporting function can be overridden in subclass
voidreportError(String s)
Parser error-reporting function can be overridden in subclass
voidreportWarning(String s)
Parser warning-reporting function can be overridden in subclass
voidresetText()
voidrewind(int pos)
voidsetCaseSensitive(boolean t)
voidsetColumn(int c)
voidsetCommitToPath(boolean commit)
voidsetFilename(String f)
voidsetInputState(LexerSharedInputState state)
voidsetLine(int line)
voidsetTabSize(int size)
voidsetText(String s)
voidsetTokenObjectClass(String cl)
voidtab()
advance the current column number by an appropriate amount according to tab size.
inttestLiteralsTable(int ttype)
inttestLiteralsTable(String text, int ttype)
Test the text passed in against the literals table Override this method to perform a different literals test This is used primarily when you want to test a portion of a token.
chartoLower(char c)
voidtraceIn(String rname)
voidtraceIndent()
voidtraceOut(String rname)
voiduponEOF()
This method is called by YourLexer.nextToken() when the lexer has hit EOF condition.

Field Detail

caseSensitive

protected boolean caseSensitive

caseSensitiveLiterals

protected boolean caseSensitiveLiterals

commitToPath

protected boolean commitToPath
Used during filter mode to indicate that path is desired. A subsequent scan error will report an error as usual if acceptPath=true;

EOF_CHAR

public static final char EOF_CHAR

hashString

protected ANTLRHashString hashString

inputState

protected LexerSharedInputState inputState

literals

protected Hashtable literals

NO_CHAR

static final char NO_CHAR

saveConsumedInput

protected boolean saveConsumedInput

tabsize

protected int tabsize
Tab chars are handled by tab() according to this value; override method to do anything weird with tabs.

text

protected ANTLRStringBuffer text

tokenObjectClass

protected Class tokenObjectClass

traceDepth

protected int traceDepth
Used to keep track of indentdepth for traceIn/Out

_returnToken

protected Token _returnToken

Constructor Detail

CharScanner

public CharScanner()

CharScanner

public CharScanner(InputBuffer cb)

CharScanner

public CharScanner(LexerSharedInputState sharedState)

Method Detail

append

public void append(char c)

append

public void append(String s)

commit

public void commit()

consume

public void consume()

consumeUntil

public void consumeUntil(int c)
Consume chars until one matches the given char

consumeUntil

public void consumeUntil(BitSet set)
Consume chars until one matches the given set

getCaseSensitive

public boolean getCaseSensitive()

getCaseSensitiveLiterals

public final boolean getCaseSensitiveLiterals()

getColumn

public int getColumn()

getCommitToPath

public boolean getCommitToPath()

getFilename

public String getFilename()

getInputBuffer

public InputBuffer getInputBuffer()

getInputState

public LexerSharedInputState getInputState()

getLine

public int getLine()

getTabSize

public int getTabSize()

getText

public String getText()
return a copy of the current text buffer

getTokenObject

public Token getTokenObject()

LA

public char LA(int i)

makeToken

protected Token makeToken(int t)

mark

public int mark()

match

public void match(char c)

match

public void match(BitSet b)

match

public void match(String s)

matchNot

public void matchNot(char c)

matchRange

public void matchRange(char c1, char c2)

newline

public void newline()

panic

public void panic()

See Also: panic

panic

public void panic(String s)
This method is executed by ANTLR internally when it detected an illegal state that cannot be recovered from. The default implementation of this method calls java.lang.System.exit(int) and writes directly to java.lang.System.err) , which is usually not appropriate when a translator is embedded into a larger application. It is highly recommended that this method be overridden to handle the error in a way appropriate for your application (e.g. throw an unchecked exception).

reportError

public void reportError(RecognitionException ex)
Parser error-reporting function can be overridden in subclass

reportError

public void reportError(String s)
Parser error-reporting function can be overridden in subclass

reportWarning

public void reportWarning(String s)
Parser warning-reporting function can be overridden in subclass

resetText

public void resetText()

rewind

public void rewind(int pos)

setCaseSensitive

public void setCaseSensitive(boolean t)

setColumn

public void setColumn(int c)

setCommitToPath

public void setCommitToPath(boolean commit)

setFilename

public void setFilename(String f)

setInputState

public void setInputState(LexerSharedInputState state)

setLine

public void setLine(int line)

setTabSize

public void setTabSize(int size)

setText

public void setText(String s)

setTokenObjectClass

public void setTokenObjectClass(String cl)

tab

public void tab()
advance the current column number by an appropriate amount according to tab size. This method is called from consume().

testLiteralsTable

public int testLiteralsTable(int ttype)

testLiteralsTable

public int testLiteralsTable(String text, int ttype)
Test the text passed in against the literals table Override this method to perform a different literals test This is used primarily when you want to test a portion of a token.

toLower

public char toLower(char c)

traceIn

public void traceIn(String rname)

traceIndent

public void traceIndent()

traceOut

public void traceOut(String rname)

uponEOF

public void uponEOF()
This method is called by YourLexer.nextToken() when the lexer has hit EOF condition. EOF is NOT a character. This method is not called if EOF is reached during syntactic predicate evaluation or during evaluation of normal lexical rules, which presumably would be an IOException. This traps the "normal" EOF condition. uponEOF() is called after the complete evaluation of the previous token and only if your parser asks for another token beyond that last non-EOF token. You might want to throw token or char stream exceptions like: "Heh, premature eof" or a retry stream exception ("I found the end of this file, go back to referencing file").