トークン読み込み用クラス (VisualBasic用)

これまでC# で作成してきた「SourceToHTML」を、C++Builder に焼きなおしてみます。

TokenReaderVB.h


//*******************************************************************************************************
// トークンごとに 文字列と その種類を返す ( VisualBasic用 )
//*******************************************************************************************************
#ifndef TokenReaderVBH
#define TokenReaderVBH
//---------------------------------------------------------------------------
#include "TokenReaderNoCase.h"
//---------------------------------------------------------------------------
class TTokenReaderVB : public TTokenReaderNoCase
{
protected:
// 単一行コメントか?
bool __fastcall IsComSingle();
// 複数行コメントか?
bool __fastcall IsComMulti();
// 逐語的文字列か?
bool __fastcall IsLiteral();
// 日付か?
bool __fastcall IsDate();
// エスケープされた識別子か?
bool __fastcall IsEscape();
// 数字か?
bool __fastcall IsNumber();
// 状態を更新 (逐語的文字列)
void __fastcall getNextStateStrLit();
// 16進表記か?
bool __fastcall IsNotHex();
// 状態を更新 (エスケープされた識別子)
void __fastcall getNextStateIdwEsc();
// 状態を更新 (日付)
void __fastcall getNextStateDtm();

public:
// 初期化
__fastcall TTokenReaderVB(TTextReader* reader, AnsiString langType);
};
#endif

TokenReaderVB.cpp


//*******************************************************************************************************
// トークンごとに 文字列と その種類を返す ( VisualBasic用 )
//*******************************************************************************************************
#pragma hdrstop
#include <vcl.h>
#include "TokenReaderVB.h"
//-------------------------------------------------------------------------------------------------------
#pragma package(smart_init)
//-------------------------------------------------------------------------------------------------------
// 初期化
//-------------------------------------------------------------------------------------------------------
__fastcall TTokenReaderVB::TTokenReaderVB(TTextReader* reader, AnsiString langType):TTokenReaderNoCase(reader, langType)
{
}
//-------------------------------------------------------------------------------------------------------
// 単一行コメントか?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderVB::IsComSingle()
{
return (_context->currChar == '\'');
}
//-------------------------------------------------------------------------------------------------------
// 複数行コメントか?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderVB::IsComMulti()
{
return false;
}
//-------------------------------------------------------------------------------------------------------
// 逐語的文字列か?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderVB::IsLiteral()
{
return (_context->currChar == '\"');
}
//-------------------------------------------------------------------------------------------------------
// 日付か?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderVB::IsDate()
{
if (_context->currChar == '#')
{
if ((_context->prevToken != NULL) && (WideSameStr(_context->prevToken->tokenKind, "演算子")))
return true;
}

return false;
}
//-------------------------------------------------------------------------------------------------------
// エスケープされた識別子か?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderVB::IsEscape()
{
return (_context->currChar == '[');
}
//-------------------------------------------------------------------------------------------------------
// 数字か?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderVB::IsNumber()
{
if (_context->currChar == '&')
{
if (!WideSameStr(_context->State, "不明"))
{
if ((_context->nextChar == 'o') || (_context->nextChar == 'O')) return true;
if ((_context->nextChar == 'h') || (_context->nextChar == 'H')) return true;
}
}

if (IsDigit(_context->currChar)) return true;

return false;
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (逐語的文字列)
//-------------------------------------------------------------------------------------------------------
void __fastcall TTokenReaderVB::getNextStateStrLit()
{
TTokenReaderCommon::getNextStateStrLit();

if (_context->currChar == '\"')
_context->State = "その他";
}
//-------------------------------------------------------------------------------------------------------
// 16進表記か?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderVB::IsNotHex()
{
// &h で始まっていたら、16進
if (wcslen(_context->currToken->tokenString) > 1)
if (_context->currToken->tokenString[1] == '&')
if ((_context->currToken->tokenString[2] == 'h') || (_context->currToken->tokenString[2] == 'H'))
return false;

return true;
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (エスケープされた識別子)
//-------------------------------------------------------------------------------------------------------
void __fastcall TTokenReaderVB::getNextStateIdwEsc()
{
TTokenReaderNoCase::getNextStateIdwEsc();

if (wcslen(_context->currToken->tokenString) > 1)
{
if ((_context->currToken->tokenString[1] == '[') && (_context->currChar == ']'))
_context->State = "その他";
}
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (日付)
//-------------------------------------------------------------------------------------------------------
void __fastcall TTokenReaderVB::getNextStateDtm()
{
TTokenReaderNoCase::getNextStateDtm();

if (_context->currChar == '#')
_context->State = "その他";
}