cling/lib/MetaProcessor/MetaLexer.h
Vassil Vassilev d98bece0ed Implement .? (fixes savannah #99730)
git-svn-id: http://root.cern.ch/svn/root/trunk@48300 27541ba8-7e3a-0410-8455-c3a389f83636
2013-01-15 10:11:52 +00:00

95 lines
2.5 KiB
C++

//--------------------------------------------------------------------*- C++ -*-
// CLING - the C++ LLVM-based InterpreterG :)
// version: $Id$
// author: Vassil Vassilev <vasil.georgiev.vasilev@cern.ch>
//------------------------------------------------------------------------------
#ifndef CLING_META_LEXER_H
#define CLING_META_LEXER_H
namespace llvm {
class StringRef;
}
namespace cling {
namespace tok {
enum TokenKind {
l_square, // "["
r_square, // "]"
l_paren, // "("
r_paren, // ")"
l_brace, // "{"
r_brace, // "}"
quote, // """
apostrophe, // "'"
comma, // ","
dot, // "."
excl_mark, // "!"
quest_mark, // "?"
slash, // "/"
backslash, // "\"
ident, // (a-zA-Z)[(0-9a-zA-Z)*]
raw_ident, // .*^(' '|'\t')
comment, // //
space, // (' ' | '\t')*
constant, // (0|1)
eof,
unknown
};
}
class Token {
private:
tok::TokenKind kind;
const char* bufStart;
unsigned length;
public:
void startToken(const char* Pos = 0) {
bufStart = Pos;
kind = tok::unknown;
}
tok::TokenKind getKind() const { return kind; }
void setKind(tok::TokenKind K) { kind = K; }
unsigned getLength() const { return length; }
void setLength(unsigned L) { length = L; }
const char* getBufStart() const { return bufStart; }
void setBufStart(const char* Pos) { bufStart = Pos; }
bool isNot(tok::TokenKind K) const { return kind != K; }
bool is(tok::TokenKind K) const { return kind == K; }
llvm::StringRef getIdent() const;
bool getConstant() const;
};
class MetaLexer {
protected:
const char* bufferStart;
const char* bufferEnd;
const char* curPos;
public:
MetaLexer(const char* bufStart)
: bufferStart(bufStart), curPos(bufStart)
{ }
MetaLexer(llvm::StringRef input);
void Lex(Token& Tok);
void LexAnyString(Token& Tok);
static void LexPunctuator(char C, Token& Tok);
// TODO: Revise. We might not need that.
static void LexPunctuatorAndAdvance(const char*& curPos, Token& Tok);
static void LexNumericConstant(const char* curPos, Token& Tok);
void LexIdentifier(char C, Token& Tok);
void LexEndOfFile(char C, Token& Tok);
void LexWhitespace(char C, Token& Tok);
void SkipWhitespace();
inline char getAndAdvanceChar(const char *&Ptr) {
return *Ptr++;
}
};
} //end namespace cling
#endif // CLING_PUNCTUATION_LEXER_H