まとめ 【トークン読み込み用クラス (Delphi用)】

TokenReaderDelphi.cs


using System;

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

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

return false;
}
//---------------------------------------------------------------------------------------------------
// 状態を更新 (複数行コメント)
//---------------------------------------------------------------------------------------------------
protected override void getNextStateComMul()
{
base.getNextStateComMul();

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

if (_context.currToken.tokenString.Length > 1)
if ((_context.currToken.tokenString[0] == '{') && (_context.currChar == '}'))
_context.State = "その他";
}
//---------------------------------------------------------------------------------------------------
// 状態を更新 (文字)
//---------------------------------------------------------------------------------------------------
protected override void getNextStateCha()
{
base.getNextStateCha();

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

return true;
}
//---------------------------------------------------------------------------------------------------
// 状態を更新 (ディレクティブ)
//---------------------------------------------------------------------------------------------------
protected override void getNextStateDir()
{
base.getNextStateDir();

if (_context.currChar == '}')
_context.State = "その他";

}
}
}