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

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

TokenReaderDelphi.vb


'*******************************************************************************************************
' トークンごとに 文字列と その種類を返す (Delphi 用)
'*******************************************************************************************************
Public Class TokenReaderDelphi
Inherits TokenReaderNoCase
'---------------------------------------------------------------------------------------------------
' 初期化
'---------------------------------------------------------------------------------------------------
Friend Sub New(ByVal aReader As Reader, ByVal langType As String)
MyBase.New(aReader, langType)
End Sub
'---------------------------------------------------------------------------------------------------
' 終了
'---------------------------------------------------------------------------------------------------
Protected Overrides Sub Finalize()
End Sub
'---------------------------------------------------------------------------------------------------
' 複数行コメントか?
'---------------------------------------------------------------------------------------------------
Protected Overrides Function IsComMulti() As Boolean
If ((_context.currChar = "("c) AndAlso (_context.nextChar = "*"c)) Then Return True
If (_context.currChar = "{"c) Then Return True

Return False
End Function
'---------------------------------------------------------------------------------------------------
' 文字か?
'---------------------------------------------------------------------------------------------------
Protected Overrides Function IsChar() As Boolean
Return (_context.currChar = "#"c)
End Function
'---------------------------------------------------------------------------------------------------
' ディレクティブか?
'---------------------------------------------------------------------------------------------------
Protected Overrides Function IsDirective() As Boolean
Return ((_context.currChar = "{"c) AndAlso (_context.nextChar = "$"c))
End Function
'---------------------------------------------------------------------------------------------------
' 数字か?
'---------------------------------------------------------------------------------------------------
Protected Overrides Function IsNumber() As Boolean
If (_context.currChar = "$"c) Then Return True
If (Char.IsDigit(_context.currChar)) Then Return True

Return False
End Function
'---------------------------------------------------------------------------------------------------
' 状態を更新 (複数行コメント)
'---------------------------------------------------------------------------------------------------
Protected Overrides Sub getNextStateComMul()
MyBase.getNextStateComMul()

If (_context.currToken.tokenString.Length > 3) Then
If ((_context.currToken.tokenString.Chars(0) = "("c) AndAlso (_context.currToken.tokenString.Chars(1) = "*"c)) Then
If ((_context.prevChar = "*") AndAlso (_context.currChar = ")"c)) Then
_context.State = "その他"
End If
End If
End If

If (_context.currToken.tokenString.Length > 1) Then
If ((_context.currToken.tokenString.Chars(0) = "{"c) AndAlso (_context.currChar = "}"c)) Then
_context.State = "その他"
End If
End If
End Sub
'---------------------------------------------------------------------------------------------------
' 状態を更新 (文字)
'---------------------------------------------------------------------------------------------------
Protected Overrides Sub getNextStateCha()
MyBase.getNextStateCha()

If (Not Char.IsDigit(_context.currChar)) Then
_context.State = "不明"
End If
End Sub
'---------------------------------------------------------------------------------------------------
' 16進表記か?
'---------------------------------------------------------------------------------------------------
Protected Overrides Function IsNotHex() As Boolean
' $ で始まっていたら、16進
If (_context.currToken.tokenString.Length > 1) Then
If (_context.currToken.tokenString.Chars(0) = "$"c) Then
Return False
End If
End If

Return True
End Function
'---------------------------------------------------------------------------------------------------
' 状態を更新 (ディレクティブ)
'---------------------------------------------------------------------------------------------------
Protected Overrides Sub getNextStateDir()
MyBase.getNextStateDir()

If (_context.currChar = "}"c) Then
_context.State = "その他"
End If

End Sub
End Class