ANTLR Support Libraries 2.7.1+
Classes | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Attributes | List of all members
CharScanner Class Referenceabstract

#include <CharScanner.hpp>

Inheritance diagram for CharScanner:
Inheritance graph
[legend]
Collaboration diagram for CharScanner:
Collaboration graph
[legend]

Classes

class  Tracer
 

Public Member Functions

 CharScanner (InputBuffer &cb, bool case_sensitive)
 
 CharScanner (InputBuffer *cb, bool case_sensitive)
 
 CharScanner (const LexerSharedInputState &state, bool case_sensitive)
 
virtual ~CharScanner ()
 
virtual int LA (unsigned int i)
 
virtual void append (char c)
 
virtual void append (const std ::string &s)
 
virtual void commit ()
 
virtual void recover (const RecognitionException &ex, const BitSet &tokenSet)
 
virtual void consume ()
 
virtual void consumeUntil (int c)
 
virtual void consumeUntil (const BitSet &set)
 
virtual unsigned int mark ()
 Mark the current position and return a id for it. More...
 
virtual void rewind (unsigned int pos)
 Rewind the scanner to a previously marked position. More...
 
virtual void match (int c)
 See if input contains character 'c' throw MismatchedCharException if not. More...
 
virtual void match (const BitSet &b)
 
virtual void match (const char *s)
 
virtual void match (const std ::string &s)
 
virtual void matchNot (int c)
 
virtual void matchRange (int c1, int c2)
 
virtual bool getCaseSensitive () const
 
virtual void setCaseSensitive (bool t)
 
virtual bool getCaseSensitiveLiterals () const =0
 
virtual int getLine () const
 Get the line the scanner currently is in (starts at 1) More...
 
virtual void setLine (int l)
 set the line number More...
 
virtual int getColumn () const
 Get the column the scanner currently is in (starts at 1) More...
 
virtual void setColumn (int c)
 set the column number More...
 
virtual const std ::string & getFilename () const
 get the filename for the file currently used More...
 
virtual void setFilename (const std ::string &f)
 Set the filename the scanner is using (used in error messages) More...
 
virtual bool getCommitToPath () const
 
virtual void setCommitToPath (bool commit)
 
virtual const std ::string & getText () const
 
virtual void setText (const std ::string &s)
 
virtual void resetText ()
 
virtual RefToken getTokenObject () const
 
virtual void newline ()
 
virtual void tab ()
 
int setTabsize (int size)
 set the tabsize. Returns the old tabsize More...
 
int getTabSize () const
 Return the tabsize used by the scanner. More...
 
virtual void reportError (const RecognitionException &e)
 
virtual void reportError (const std ::string &s)
 
virtual void reportWarning (const std ::string &s)
 
virtual InputBuffergetInputBuffer ()
 
virtual LexerSharedInputState getInputState ()
 
virtual void setInputState (LexerSharedInputState state)
 
virtual void setTokenObjectFactory (factory_type factory)
 Set the factory for created tokens. More...
 
virtual int testLiteralsTable (int ttype) const
 
virtual int testLiteralsTable (const std ::string &txt, int ttype) const
 
virtual int toLower (int c) const
 Override this method to get more specific case handling. More...
 
virtual void uponEOF ()
 
virtual void traceIndent ()
 Methods used to change tracing behavior. More...
 
virtual void traceIn (const char *rname)
 
virtual void traceOut (const char *rname)
 
- Public Member Functions inherited from TokenStream
virtual RefToken nextToken ()=0
 
virtual ~TokenStream ()
 

Static Public Attributes

static const int EOF_CHAR = EOF
 

Protected Types

typedef RefToken(* factory_type) ()
 

Protected Member Functions

virtual RefToken makeToken (int t)
 Create a new RefToken of type t. More...
 

Protected Attributes

std ::string text
 
bool saveConsumedInput
 flag indicating wether consume saves characters More...
 
factory_type tokenFactory
 Factory for tokens. More...
 
bool caseSensitive
 Is this lexer case sensitive. More...
 
std ::map< std ::string, int, CharScannerLiteralsLessliterals
 
RefToken _returnToken
 used to return tokens w/o using return val More...
 
LexerSharedInputState inputState
 Input state, gives access to input stream, shared among different lexers. More...
 
bool commitToPath
 
int tabsize
 tab size the scanner uses. More...
 
int traceDepth
 

Private Member Functions

 CharScanner (const CharScanner &other)
 
CharScanneroperator= (const CharScanner &other)
 

Static Private Attributes

static const int NO_CHAR = 0
 

Detailed Description

Superclass of generated lexers

Member Typedef Documentation

◆ factory_type

typedef RefToken(* CharScanner::factory_type) ()
protected

Constructor & Destructor Documentation

◆ CharScanner() [1/4]

CharScanner::CharScanner ( InputBuffer cb,
bool  case_sensitive 
)

◆ CharScanner() [2/4]

CharScanner::CharScanner ( InputBuffer cb,
bool  case_sensitive 
)

◆ CharScanner() [3/4]

CharScanner::CharScanner ( const LexerSharedInputState state,
bool  case_sensitive 
)

◆ ~CharScanner()

virtual CharScanner::~CharScanner ( )
inlinevirtual

◆ CharScanner() [4/4]

CharScanner::CharScanner ( const CharScanner other)
private

Member Function Documentation

◆ append() [1/2]

virtual void CharScanner::append ( char  c)
inlinevirtual

◆ append() [2/2]

virtual void CharScanner::append ( const std ::string &  s)
inlinevirtual

◆ commit()

virtual void CharScanner::commit ( )
inlinevirtual

◆ consume()

virtual void CharScanner::consume ( )
inlinevirtual

◆ consumeUntil() [1/2]

virtual void CharScanner::consumeUntil ( int  c)
inlinevirtual

Consume chars until one matches the given char

◆ consumeUntil() [2/2]

virtual void CharScanner::consumeUntil ( const BitSet set)
inlinevirtual

Consume chars until one matches the given set

◆ getCaseSensitive()

virtual bool CharScanner::getCaseSensitive ( ) const
inlinevirtual

◆ getCaseSensitiveLiterals()

virtual bool CharScanner::getCaseSensitiveLiterals ( ) const
pure virtual

◆ getColumn()

virtual int CharScanner::getColumn ( ) const
inlinevirtual

Get the column the scanner currently is in (starts at 1)

◆ getCommitToPath()

virtual bool CharScanner::getCommitToPath ( ) const
inlinevirtual

◆ getFilename()

virtual const std ::string& CharScanner::getFilename ( ) const
inlinevirtual

get the filename for the file currently used

◆ getInputBuffer()

virtual InputBuffer& CharScanner::getInputBuffer ( )
inlinevirtual

◆ getInputState()

virtual LexerSharedInputState CharScanner::getInputState ( )
inlinevirtual

◆ getLine()

virtual int CharScanner::getLine ( ) const
inlinevirtual

Get the line the scanner currently is in (starts at 1)

◆ getTabSize()

int CharScanner::getTabSize ( ) const
inline

Return the tabsize used by the scanner.

◆ getText()

virtual const std ::string& CharScanner::getText ( ) const
inlinevirtual

return a copy of the current text buffer

◆ getTokenObject()

virtual RefToken CharScanner::getTokenObject ( ) const
inlinevirtual

◆ LA()

int CharScanner::LA ( unsigned int  i)
inlinevirtual

◆ makeToken()

virtual RefToken CharScanner::makeToken ( int  t)
inlineprotectedvirtual

Create a new RefToken of type t.

◆ mark()

virtual unsigned int CharScanner::mark ( )
inlinevirtual

Mark the current position and return a id for it.

◆ match() [1/4]

virtual void CharScanner::match ( int  c)
inlinevirtual

See if input contains character 'c' throw MismatchedCharException if not.

◆ match() [2/4]

virtual void CharScanner::match ( const BitSet b)
inlinevirtual

See if input contains element from bitset b throw MismatchedCharException if not

◆ match() [3/4]

virtual void CharScanner::match ( const char *  s)
inlinevirtual

See if input contains string 's' throw MismatchedCharException if not

Note
the string cannot match EOF

◆ match() [4/4]

virtual void CharScanner::match ( const std ::string &  s)
inlinevirtual

See if input contains string 's' throw MismatchedCharException if not

Note
the string cannot match EOF

◆ matchNot()

virtual void CharScanner::matchNot ( int  c)
inlinevirtual

See if input does not contain character 'c' throw MismatchedCharException if not

◆ matchRange()

virtual void CharScanner::matchRange ( int  c1,
int  c2 
)
inlinevirtual

See if input contains character in range c1-c2 throw MismatchedCharException if not

◆ newline()

virtual void CharScanner::newline ( )
inlinevirtual

Used to keep track of line breaks, needs to be called from within generated lexers when a
is encountered.

◆ operator=()

CharScanner& CharScanner::operator= ( const CharScanner other)
private

◆ recover()

virtual void CharScanner::recover ( const RecognitionException ex,
const BitSet tokenSet 
)
inlinevirtual

called by the generated lexer to do error recovery, override to customize the behaviour.

◆ reportError() [1/2]

void CharScanner::reportError ( const RecognitionException ex)
virtual

Report exception errors caught in nextToken()

◆ reportError() [2/2]

void CharScanner::reportError ( const std ::string &  s)
virtual

Parser error-reporting function can be overridden in subclass

◆ reportWarning()

void CharScanner::reportWarning ( const std ::string &  s)
virtual

Parser warning-reporting function can be overridden in subclass

◆ resetText()

virtual void CharScanner::resetText ( )
inlinevirtual

◆ rewind()

virtual void CharScanner::rewind ( unsigned int  pos)
inlinevirtual

Rewind the scanner to a previously marked position.

◆ setCaseSensitive()

virtual void CharScanner::setCaseSensitive ( bool  t)
inlinevirtual

◆ setColumn()

virtual void CharScanner::setColumn ( int  c)
inlinevirtual

set the column number

◆ setCommitToPath()

virtual void CharScanner::setCommitToPath ( bool  commit)
inlinevirtual

◆ setFilename()

virtual void CharScanner::setFilename ( const std ::string &  f)
inlinevirtual

Set the filename the scanner is using (used in error messages)

◆ setInputState()

virtual void CharScanner::setInputState ( LexerSharedInputState  state)
inlinevirtual

set the input state for the lexer.

Note
state is a reference counted object, hence no reference

◆ setLine()

virtual void CharScanner::setLine ( int  l)
inlinevirtual

set the line number

◆ setTabsize()

int CharScanner::setTabsize ( int  size)
inline

set the tabsize. Returns the old tabsize

◆ setText()

virtual void CharScanner::setText ( const std ::string &  s)
inlinevirtual

◆ setTokenObjectFactory()

virtual void CharScanner::setTokenObjectFactory ( factory_type  factory)
inlinevirtual

Set the factory for created tokens.

◆ tab()

virtual void CharScanner::tab ( )
inlinevirtual

Advance the current column number by an appropriate amount according to the tabsize. This method needs to be explicitly called from the lexer rules encountering tabs.

◆ testLiteralsTable() [1/2]

virtual int CharScanner::testLiteralsTable ( int  ttype) const
inlinevirtual

Test the token text against the literals table Override this method to perform a different literals test

◆ testLiteralsTable() [2/2]

virtual int CharScanner::testLiteralsTable ( const std ::string &  txt,
int  ttype 
) const
inlinevirtual

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()

virtual int CharScanner::toLower ( int  c) const
inlinevirtual

Override this method to get more specific case handling.

◆ traceIn()

void CharScanner::traceIn ( const char *  rname)
virtual

◆ traceIndent()

void CharScanner::traceIndent ( )
virtual

Methods used to change tracing behavior.

◆ traceOut()

void CharScanner::traceOut ( const char *  rname)
virtual

◆ uponEOF()

virtual void CharScanner::uponEOF ( )
inlinevirtual

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").

Member Data Documentation

◆ _returnToken

RefToken CharScanner::_returnToken
protected

used to return tokens w/o using return val

◆ caseSensitive

bool CharScanner::caseSensitive
protected

Is this lexer case sensitive.

◆ commitToPath

bool CharScanner::commitToPath
protected

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

const int CharScanner::EOF_CHAR = EOF
static

◆ inputState

LexerSharedInputState CharScanner::inputState
protected

Input state, gives access to input stream, shared among different lexers.

◆ literals

std ::map< std ::string,int,CharScannerLiteralsLess> CharScanner::literals
protected

◆ NO_CHAR

const int CharScanner::NO_CHAR = 0
staticprivate

◆ saveConsumedInput

bool CharScanner::saveConsumedInput
protected

flag indicating wether consume saves characters

◆ tabsize

int CharScanner::tabsize
protected

tab size the scanner uses.

◆ text

std ::string CharScanner::text
protected

Text of current token

◆ tokenFactory

factory_type CharScanner::tokenFactory
protected

Factory for tokens.

◆ traceDepth

int CharScanner::traceDepth
protected

The documentation for this class was generated from the following files: