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

TokenReaderCase.cs


using System;

namespace SourceToHtml
{
//*******************************************************************************************************
// トークンごとに 文字列と その種類を返す ( 大文字・小文字を意識する 言語用 )
//*******************************************************************************************************
public class TokenReaderCase : TokenReaderCommon
{
//---------------------------------------------------------------------------------------------------
// 初期化
//---------------------------------------------------------------------------------------------------
public TokenReaderCase(Reader reader, string langType) : base(reader, langType) {}
//---------------------------------------------------------------------------------------------------
// 文字列か?
//---------------------------------------------------------------------------------------------------
protected override bool IsString()
{
return (_context.currChar == '\"');
}
//---------------------------------------------------------------------------------------------------
// 文字か?
//---------------------------------------------------------------------------------------------------
protected override bool IsChar()
{
return (_context.currChar == '\'');
}
//---------------------------------------------------------------------------------------------------
// ディレクティブか?
//---------------------------------------------------------------------------------------------------
protected override bool IsDirective()
{
return (_context.currChar == '#');
}
//---------------------------------------------------------------------------------------------------
// 予約語ではないか?
//---------------------------------------------------------------------------------------------------
protected override string getKeyWord()
{
//識別子が 予約語であれば、その文字列を返す
if (_keyWords.Contains(_context.currToken.tokenString))
return _context.currToken.tokenString;

return "";
}
//---------------------------------------------------------------------------------------------------
// 状態を更新 (文字列)
//---------------------------------------------------------------------------------------------------
protected override void getNextStateStr()
{
base.getNextStateStr();

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

else if (_context.currChar == '\\')
_context.State = "文字列中のエスケープシーケンス";
}
//---------------------------------------------------------------------------------------------------
// 状態を更新 (文字)
//---------------------------------------------------------------------------------------------------
protected override void getNextStateCha()
{
base.getNextStateCha();

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

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

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

else if (!Char.IsLetter(_context.currChar))
_context.State = "不明";
}
}
}