1#ifndef INC_CharScanner_hpp__
2#define INC_CharScanner_hpp__
11#include <antlr/config.hpp>
16#ifdef HAS_NOT_CCTYPE_H
22#if ( _MSC_VER == 1200 )
28#include <antlr/TokenStream.hpp>
29#include <antlr/RecognitionException.hpp>
30#include <antlr/SemanticException.hpp>
31#include <antlr/MismatchedCharException.hpp>
32#include <antlr/InputBuffer.hpp>
33#include <antlr/BitSet.hpp>
34#include <antlr/LexerSharedInputState.hpp>
36#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
40class ANTLR_API CharScanner;
44#ifdef ANTLR_REALLY_NO_STRCASECMP
47inline int strcasecmp(
const char *s1,
const char *s2)
51 char c1 = tolower(*s1++),
53 if (c1 < c2)
return -1;
54 if (c1 > c2)
return 1;
55 if (c1 == 0)
return 0;
62ANTLR_C_USING(strcasecmp)
72#ifdef NO_TEMPLATE_PARTS
80 using result_type = bool;
81 using first_argument_type = ANTLR_USE_NAMESPACE(std)string;
82 using second_argument_type = ANTLR_USE_NAMESPACE(std)string;
84 bool operator() (
const ANTLR_USE_NAMESPACE(std)
string& x,
const ANTLR_USE_NAMESPACE(std)
string& y)
const;
105 virtual int LA(
unsigned int i);
107 virtual void append(
char c)
109 if (saveConsumedInput)
111 size_t l = text.length();
116 text.replace(l,0,&c,1);
120 virtual void append(
const ANTLR_USE_NAMESPACE(std)
string& s)
122 if( saveConsumedInput )
126 virtual void commit()
128 inputState->getInput().commit();
137 consumeUntil(tokenSet);
140 virtual void consume()
142 if (inputState->guessing == 0)
153 append(inputState->getInput().LA(1));
160 inputState->column++;
162 inputState->getInput().consume();
171 if( la_1 == EOF_CHAR || la_1 == c )
183 if( la_1 == EOF_CHAR || set.member(la_1) )
192 return inputState->getInput().mark();
197 inputState->getInput().rewind(pos);
216 if ( !b.member(la_1) )
229 int la_1 = LA(1), c = (*s++ & 0xFF);
240 virtual void match(
const ANTLR_USE_NAMESPACE(std)
string& s)
242 size_t len = s.length();
244 for (
size_t i = 0; i < len; i++)
247 int la_1 = LA(1), c = (s[i] & 0xFF);
274 if ( la_1 < c1 || la_1 > c2 )
280 virtual bool getCaseSensitive()
const
282 return caseSensitive;
285 virtual void setCaseSensitive(
bool t)
290 virtual bool getCaseSensitiveLiterals()
const=0;
295 return inputState->line;
301 inputState->line = l;
307 return inputState->column;
312 inputState->column = c;
318 return inputState->filename;
323 inputState->filename = f;
326 virtual bool getCommitToPath()
const
331 virtual void setCommitToPath(
bool commit)
333 commitToPath = commit;
337 virtual const ANTLR_USE_NAMESPACE(std)
string&
getText()
const
342 virtual void setText(
const ANTLR_USE_NAMESPACE(std)
string& s)
347 virtual void resetText()
350 inputState->tokenStartColumn = inputState->column;
351 inputState->tokenStartLine = inputState->line;
354 virtual RefToken getTokenObject()
const
365 inputState->column = 1;
375 int nc = ( ((c-1)/tabsize) + 1) * tabsize + 1;
381 int oldsize = tabsize;
395 virtual void reportError(
const ANTLR_USE_NAMESPACE(std)
string& s);
398 virtual void reportWarning(
const ANTLR_USE_NAMESPACE(std)
string& s);
402 return inputState->getInput();
405 virtual LexerSharedInputState getInputState()
420 tokenFactory = factory;
428 ANTLR_USE_NAMESPACE(std)map<ANTLR_USE_NAMESPACE(std)string,int,
CharScannerLiteralsLess>::const_iterator i = literals.find(text);
429 if (i != literals.end())
441 ANTLR_USE_NAMESPACE(std)map<ANTLR_USE_NAMESPACE(std)string,int,
CharScannerLiteralsLess>::const_iterator i = literals.find(txt);
442 if (i != literals.end())
453 return (c == EOF_CHAR ? EOF_CHAR : tolower(c));
476 virtual void traceIndent();
477 virtual void traceIn(
const char* rname);
478 virtual void traceOut(
const char* rname);
480#ifndef NO_STATIC_CONSTS
481 static const int EOF_CHAR = EOF;
488 ANTLR_USE_NAMESPACE(std)
string text;
490 bool saveConsumedInput;
513 tok->setColumn(inputState->tokenStartColumn);
514 tok->setLine(inputState->tokenStartLine);
531 parser->traceIn(text);
535 parser->traceOut(text);
544#ifndef NO_STATIC_CONSTS
545 static const int NO_CHAR = 0;
553inline int CharScanner::LA(
unsigned int i)
563inline bool CharScannerLiteralsLess::operator() (
const ANTLR_USE_NAMESPACE(std)
string& x,
const ANTLR_USE_NAMESPACE(std)
string& y)
const
565 if (scanner->getCaseSensitiveLiterals())
566 return ANTLR_USE_NAMESPACE(std)less<ANTLR_USE_NAMESPACE(std)string>()(x,y);
570 return (_stricmp(x.c_str(),y.c_str())<0);
572 return (strcasecmp(x.c_str(),y.c_str())<0);
577#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
A BitSet to replace java.util.BitSet.
Tracer class, used when -traceLexer is passed to antlr.
Superclass of generated lexers.
virtual int getColumn() const
Get the column the scanner currently is in (starts at 1)
virtual void matchRange(int c1, int c2)
See if input contains character in range c1-c2 throw MismatchedCharException if not.
virtual void setTokenObjectFactory(factory_type factory)
Set the factory for created tokens.
virtual void consumeUntil(int c)
Consume chars until one matches the given char.
virtual void consumeUntil(const BitSet &set)
Consume chars until one matches the given set.
bool caseSensitive
Is this lexer case sensitive.
virtual int getLine() const
Get the line the scanner currently is in (starts at 1)
virtual unsigned int mark()
Mark the current position and return a id for it.
virtual void uponEOF()
This method is called by YourLexer::nextToken() when the lexer has hit EOF condition.
virtual void setInputState(LexerSharedInputState state)
set the input state for the lexer.
virtual int testLiteralsTable(const std ::string &txt, int ttype) const
Test the text passed in against the literals table Override this method to perform a different litera...
LexerSharedInputState inputState
Input state, gives access to input stream, shared among different lexers.
std::string text
Text of current token flag indicating wether consume saves characters.
virtual void setFilename(const std ::string &f)
Set the filename the scanner is using (used in error messages)
virtual RefToken makeToken(int t)
Create a new RefToken of type t.
virtual void setLine(int l)
set the line number
virtual int toLower(int c) const
Override this method to get more specific case handling.
virtual const std::string & getText() const
return a copy of the current text buffer
virtual const std::string & getFilename() const
get the filename for the file currently used
int setTabsize(int size)
set the tabsize. Returns the old tabsize
virtual int testLiteralsTable(int ttype) const
Test the token text against the literals table Override this method to perform a different literals t...
int getTabSize() const
Return the tabsize used by the scanner.
virtual void matchNot(int c)
See if input does not contain character 'c' throw MismatchedCharException if not.
virtual void newline()
Used to keep track of line breaks, needs to be called from within generated lexers when a \r is enc...
virtual void rewind(unsigned int pos)
Rewind the scanner to a previously marked position.
virtual void match(const BitSet &b)
See if input contains element from bitset b throw MismatchedCharException if not.
factory_type tokenFactory
Factory for tokens.
virtual void setColumn(int c)
set the column number
bool commitToPath
Used during filter mode to indicate that path is desired.
virtual void tab()
Advance the current column number by an appropriate amount according to the tabsize.
virtual void match(const std ::string &s)
See if input contains string 's' throw MismatchedCharException if not.
virtual void recover(const RecognitionException &, const BitSet &tokenSet)
called by the generated lexer to do error recovery, override to customize the behaviour.
RefToken _returnToken
used to return tokens w/o using return val
int tabsize
tab size the scanner uses.
virtual void match(int c)
See if input contains character 'c' throw MismatchedCharException if not.
virtual void match(const char *s)
See if input contains string 's' throw MismatchedCharException if not.
Functor for the literals map.
This interface allows any object to pretend it is a stream of tokens.