|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TTOKENIZER_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define TTOKENIZER_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(push)
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4251)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TNZBASE_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace TSyntax
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI Token
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
enum Type { None,
|
|
Toshihiro Shimizu |
890ddd |
Space,
|
|
Toshihiro Shimizu |
890ddd |
Ident,
|
|
Toshihiro Shimizu |
890ddd |
Number,
|
|
Toshihiro Shimizu |
890ddd |
Punct,
|
|
Toshihiro Shimizu |
890ddd |
Eos };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Token(int pos = 0)
|
|
Toshihiro Shimizu |
890ddd |
: m_text(""), m_type(None), m_pos(pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
Token(int p0, int p1)
|
|
Toshihiro Shimizu |
890ddd |
: m_text(p1 - p0 + 1, ' '), m_type(Space), m_pos(p0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
Token(std::string text, Type type, int pos)
|
|
Toshihiro Shimizu |
890ddd |
: m_text(text), m_type(type), m_pos(pos)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Type getType() const { return m_type; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string getText() const { return m_text; }
|
|
Toshihiro Shimizu |
890ddd |
int getIntValue() const;
|
|
Toshihiro Shimizu |
890ddd |
double getDoubleValue() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getPos() const { return m_pos; }
|
|
Toshihiro Shimizu |
890ddd |
int getPos1() const { return m_pos + m_text.length() - 1; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_text;
|
|
Toshihiro Shimizu |
890ddd |
int m_pos;
|
|
Toshihiro Shimizu |
890ddd |
Type m_type;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI Tokenizer
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_buffer;
|
|
Toshihiro Shimizu |
890ddd |
std::vector<token> m_tokens;</token>
|
|
Toshihiro Shimizu |
890ddd |
int m_index;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
Tokenizer();
|
|
Shinya Kitaoka |
3bfa54 |
Tokenizer(std::string buffer);
|
|
Toshihiro Shimizu |
890ddd |
~Tokenizer();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void setBuffer(std::string buffer);
|
|
Shinya Kitaoka |
3bfa54 |
std::string getBuffer() const { return m_buffer; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int getTokenCount() const;
|
|
Toshihiro Shimizu |
890ddd |
const Token &getToken(int index) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//! get the token containing the pos-th character in the input string
|
|
Toshihiro Shimizu |
890ddd |
Token getTokenFromPos(int pos) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//! reset the token index. (set it to 0)
|
|
Toshihiro Shimizu |
890ddd |
void reset();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//! return the current token (possibly Eos)
|
|
Toshihiro Shimizu |
890ddd |
const Token &getToken();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//! same as getToken(), but post-increment the token index (if !eos())
|
|
Toshihiro Shimizu |
890ddd |
Token nextToken();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//! return true if the current token is the last one
|
|
Toshihiro Shimizu |
890ddd |
bool eos() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//! to read all the sequence:
|
|
Toshihiro Shimizu |
890ddd |
//! while(!tokenizer.eos()) {token = tokenizer.nextToken();...}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} // namespace TSyntax
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(pop)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|