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

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

TokenReaderDelphi.h


#pragma once

#include ".\TokenReaderNoCase.h"

namespace SourceToHtml
{
using namespace System;
//*******************************************************************************************************
// トークンごとに 文字列と その種類を返す ( Delphi用 )
//*******************************************************************************************************
public __gc class TokenReaderDelphi : public TokenReaderNoCase
{
protected:
// 複数行コメントか?
bool IsComMulti();
// 文字か?
bool IsChar();
// ディレクティブか?
bool IsDirective();
// 数字か?
bool IsNumber();
// 状態を更新 (複数行コメント)
void getNextStateComMul();
// 状態を更新 (文字)
void getNextStateCha();
// 16進表記か?
bool IsNotHex();
// 状態を更新 (ディレクティブ)
void getNextStateDir();

public:
// 初期化
TokenReaderDelphi(Reader* reader, String* langType);
// 終了
~TokenReaderDelphi();
};
}

TokenReaderDelphi.cpp


#include "StdAfx.h"
#include ".\TokenReaderDelphi.h"

namespace SourceToHtml
{
//*******************************************************************************************************
// トークンごとに 文字列と その種類を返す ( Delphi用 )
//*******************************************************************************************************
//-------------------------------------------------------------------------------------------------------
// 初期化
//-------------------------------------------------------------------------------------------------------
TokenReaderDelphi::TokenReaderDelphi(Reader* reader, String* langType):TokenReaderNoCase(reader, langType)
{
}
//-------------------------------------------------------------------------------------------------------
// 終了
//-------------------------------------------------------------------------------------------------------
TokenReaderDelphi::~TokenReaderDelphi()
{
}
//-------------------------------------------------------------------------------------------------------
// 複数行コメントか?
//-------------------------------------------------------------------------------------------------------
bool TokenReaderDelphi::IsComMulti()
{
if ((_context->currChar == '(') && (_context->nextChar == '*')) return true;
if (_context->currChar == '{') return true;

return false;
}
//-------------------------------------------------------------------------------------------------------
// 文字か?
//-------------------------------------------------------------------------------------------------------
bool TokenReaderDelphi::IsChar()
{
return (_context->currChar == '#');
}
//-------------------------------------------------------------------------------------------------------
// ディレクティブか?
//-------------------------------------------------------------------------------------------------------
bool TokenReaderDelphi::IsDirective()
{
return ((_context->currChar == '{') && (_context->nextChar == '$'));
}
//-------------------------------------------------------------------------------------------------------
// 数字か?
//-------------------------------------------------------------------------------------------------------
bool TokenReaderDelphi::IsNumber()
{
if (_context->currChar == '$') return true;
if (Char::IsDigit(_context->currChar)) return true;

return false;
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (複数行コメント)
//-------------------------------------------------------------------------------------------------------
void TokenReaderDelphi::getNextStateComMul()
{
TokenReaderNoCase::getNextStateComMul();

if (_context->currToken->tokenString->Length > 3)
if ((_context->currToken->tokenString->Chars[0] == '(') && (_context->currToken->tokenString->Chars[1] == '*'))
if ((_context->prevChar == '*') && (_context->currChar == ')'))
_context->State = S"その他";

if (_context->currToken->tokenString->Length > 1)
if ((_context->currToken->tokenString->Chars[0] == '{') && (_context->currChar == '}'))
_context->State = S"その他";
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (文字)
//-------------------------------------------------------------------------------------------------------
void TokenReaderDelphi::getNextStateCha()
{
TokenReaderNoCase::getNextStateCha();

if (!Char::IsDigit(_context->currChar))
_context->State = S"不明";
}
//-------------------------------------------------------------------------------------------------------
// 16進表記か?
//-------------------------------------------------------------------------------------------------------
bool TokenReaderDelphi::IsNotHex()
{
// $ で始まっていたら、16進
if (_context->currToken->tokenString->Length > 1)
if (_context->currToken->tokenString->Chars[0] == '$')
return false;

return true;
}
//-------------------------------------------------------------------------------------------------------
// 状態を更新 (ディレクティブ)
//-------------------------------------------------------------------------------------------------------
void TokenReaderDelphi::getNextStateDir()
{
TokenReaderNoCase::getNextStateDir();

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

}
}