我正在制作一个用于我的编程语言的文本编辑器。它运行得非常好,但我有一个问题:当我输入类似以下内容时:
void Example() {
for (int i = 0, 10; i++) {
console.println(i);
}
}
for循环的结束括号
for (int i = 0, 10; i++) {
console.println(i);
} <== This one
没有加亮显示。有人能帮我吗? 提前感谢!
下面是我的代码:
Imports System.Drawing.Color
Imports System.Drawing.Font
Public Class Form1
Private Sub Highlight(ByRef Text As String(), ByRef Name As String)
Dim Color As Color = Nothing
Dim Font As Font = Nothing
Select Case Name
Case "Keywords"
Color = Blue
Font = NewFont(FontStyle.Regular)
Case "Functions"
Color = Black
Font = NewFont(FontStyle.Italic)
Case "Classes"
Color = Cyan
Font = NewFont(FontStyle.Regular)
Case "Types"
Color = Purple
Font = NewFont(FontStyle.Regular)
Case "Operators"
Color = GreenYellow
Font = NewFont(FontStyle.Regular)
Case "Brackets"
Color = Red
Font = NewFont(FontStyle.Regular)
End Select
Dim CursorPos As Integer = tb.SelectionStart
For i As Integer = 0 To Text.Length - 1
FindAll(tb, Text(i))
tb.SelectionColor = Color
tb.SelectionFont = Font
tb.DeselectAll()
Next
tb.SelectionStart = CursorPos
tb.SelectionColor = Nothing
tb.SelectionFont = NewFont(FontStyle.Regular)
End Sub
Private Function NewFont(ByVal Style As FontStyle)
Return New Font(tb.Font, Style)
End Function
Private Sub FindAll(ByRef tb As RichTextBox, ByRef Find As String)
Dim StartIndex As Integer = 0
Dim Text As String = tb.Text
Do
Dim Index As Integer = Text.IndexOf(Find, StartIndex)
If Index < 0 Then
Exit Do
End If
tb.Select(Index, Find.Length)
StartIndex = Index + 1
Loop
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb.TextChanged
Dim Keywords As String() = {"new", "using", "void", "function", "public", "protected", "private", "if", "else", "for", "loop", "while", "until", "true", "false", "null", "default"}
Dim Types As String() = {"string", "int", "long", "byte", "char"}
Dim Brackets As String() = {"(", ")", "[", "]", "{", "}"}
Dim Operators As String() = {"+", "-", "=", "/", "*"}
Dim Classes As String() = {"console", "color", "font"}
Dim Functions As String() = {"print", "println"}
Highlight(Keywords, "Keywords")
Highlight(Types, "Types")
Highlight(Brackets, "Brackets")
Highlight(Operators, "Operators")
Highlight(Classes, "Classes")
Highlight(Functions, "Functions")
End Sub
End Class