|
Shinya Kitaoka |
810553 |
#pragma once
|
|
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 |
|
|
|
e280ae |
#ifdef _MSC_VER
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
namespace TSyntax {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DVAPI Token {
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
enum Type { None, Space, Ident, Number, Punct, Eos };
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Token(int pos = 0) : m_text(""), m_type(None), m_pos(pos) {}
|
|
Shinya Kitaoka |
120a6e |
Token(int p0, int p1) : m_text(p1 - p0 + 1, ' '), m_type(Space), m_pos(p0) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Token(std::string text, Type type, int pos)
|
|
Shinya Kitaoka |
120a6e |
: m_text(text), m_type(type), m_pos(pos) {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
Type getType() const { return m_type; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::string getText() const { return m_text; }
|
|
Shinya Kitaoka |
120a6e |
int getIntValue() const;
|
|
Shinya Kitaoka |
120a6e |
double getDoubleValue() const;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int getPos() const { return m_pos; }
|
|
Shinya Kitaoka |
120a6e |
int getPos1() const { return m_pos + m_text.length() - 1; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Shinya Kitaoka |
120a6e |
std::string m_text;
|
|
Shinya Kitaoka |
120a6e |
int m_pos;
|
|
Shinya Kitaoka |
120a6e |
Type m_type;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
class DVAPI Tokenizer {
|
|
Shinya Kitaoka |
120a6e |
std::string m_buffer;
|
|
Shinya Kitaoka |
120a6e |
std::vector<token> m_tokens;</token>
|
|
Shinya Kitaoka |
120a6e |
int m_index;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
Tokenizer();
|
|
Shinya Kitaoka |
120a6e |
Tokenizer(std::string buffer);
|
|
Shinya Kitaoka |
120a6e |
~Tokenizer();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void setBuffer(std::string buffer);
|
|
Shinya Kitaoka |
120a6e |
std::string getBuffer() const { return m_buffer; }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int getTokenCount() const;
|
|
Shinya Kitaoka |
120a6e |
const Token &getToken(int index) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! get the token containing the pos-th character in the input string
|
|
Shinya Kitaoka |
120a6e |
Token getTokenFromPos(int pos) const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! reset the token index. (set it to 0)
|
|
Shinya Kitaoka |
120a6e |
void reset();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! return the current token (possibly Eos)
|
|
Shinya Kitaoka |
120a6e |
const Token &getToken();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! same as getToken(), but post-increment the token index (if !eos())
|
|
Shinya Kitaoka |
120a6e |
Token nextToken();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! return true if the current token is the last one
|
|
Shinya Kitaoka |
120a6e |
bool eos() const;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
//! to read all the sequence:
|
|
Shinya Kitaoka |
120a6e |
//! while(!tokenizer.eos()) {token = tokenizer.nextToken();...}
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace TSyntax
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
e280ae |
#ifdef _MSC_VER
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(pop)
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|