トークン読み込み用クラス (大文字・小文字を意識する 言語用)

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

TokenReaderCase.h


//*******************************************************************************************************
// トークンごとに 文字列と その種類を返す ( 大文字・小文字を意識する 言語用 )
//*******************************************************************************************************
#ifndef TokenReaderCaseH
#define TokenReaderCaseH
//---------------------------------------------------------------------------
#include "TokenReaderCommon.h"
//---------------------------------------------------------------------------
class TTokenReaderCase : public TTokenReaderCommon
{
protected:
// 文字列か?
bool __fastcall IsString();
// 文字か?
bool __fastcall IsChar();
// ディレクティブか?
bool __fastcall IsDirective();
// 予約語ではないか?
WideString __fastcall getKeyWord();
// 状態を更新 (文字列)
void __fastcall getNextStateStr();
// 状態を更新 (文字)
void __fastcall getNextStateCha();
// 状態を更新 (ディレクティブ)
void __fastcall getNextStateDir();

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

TokenReaderCase.cpp


//*******************************************************************************************************
// トークンごとに 文字列と その種類を返す ( 大文字・小文字を意識する 言語用 )
//*******************************************************************************************************
#pragma hdrstop
#include <vcl.h>
#include "TokenReaderCase.h"
//-------------------------------------------------------------------------------------------------------
#pragma package(smart_init)
//-------------------------------------------------------------------------------------------------------
// 初期化
//-------------------------------------------------------------------------------------------------------
__fastcall TTokenReaderCase::TTokenReaderCase(TTextReader* reader, AnsiString langType):TTokenReaderCommon(reader, langType)
{
}
//-------------------------------------------------------------------------------------------------------
// 文字列か?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderCase::IsString()
{
return (_context->currChar == '\"');
}
//-------------------------------------------------------------------------------------------------------
// 文字か?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderCase::IsChar()
{
return (_context->currChar == '\'');
}
//-------------------------------------------------------------------------------------------------------
// ディレクティブか?
//-------------------------------------------------------------------------------------------------------
bool __fastcall TTokenReaderCase::IsDirective()
{
return (_context->currChar == '#');
}
//-------------------------------------------------------------------------------------------------------
// 予約語ではないか?
//-------------------------------------------------------------------------------------------------------
WideString __fastcall TTokenReaderCase::getKeyWord()
{
//識別子が 予約語であれば、その文字列を返す
if (_keyWords->IndexOf(_context->currToken->tokenString) >= 0)
return _context->currToken->tokenString;

return "";
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (文字列)
//-------------------------------------------------------------------------------------------------------
void __fastcall TTokenReaderCase::getNextStateStr()
{
TTokenReaderCommon::getNextStateStr();

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

else if (_context->currChar == '\\')
_context->State = "文字列中のエスケープシーケンス";
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (文字)
//-------------------------------------------------------------------------------------------------------
void __fastcall TTokenReaderCase::getNextStateCha()
{
TTokenReaderCommon::getNextStateCha();

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

else if (_context->currChar == '\\')
_context->State = "文字中のエスケープシーケンス";
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (ディレクティブ)
//-------------------------------------------------------------------------------------------------------
void __fastcall TTokenReaderCase::getNextStateDir()
{
TTokenReaderCommon::getNextStateDir();

if (_context->currChar == '\n')
_context->State = "その他";

else if (!IsLetter(_context->currChar))
_context->State = "不明";
}