-aggiunto espressione regolare per script

This commit is contained in:
Demetrio Cassarino
2025-02-27 11:03:47 +01:00
parent 93a54a47bb
commit 3388afffb5
+51 -8
View File
@@ -2,6 +2,7 @@
Imports EgtWPFLib5
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Public Class ScriptWindowVM
Inherits VMBase
@@ -552,7 +553,10 @@ Public Class ScriptWindowVM
End Sub
Public Sub SyntaxHighlighting(rtb As RichTextBox)
Dim keywords As String() = {"local ", "function ", "end", " if ", " then ", " else ", " for ", "while", "do", "return"}
Dim textRange As New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd)
Dim text As String = textRange.Text
Dim keywords As String() = {"local ", "function", "end", " if ", " then ", " else ", "for ", "while", "do", "return"}
Dim colorsArray As String() = {"WHITE", "LGRAY", "GRAY", "BLACK", "RED", "MAROON", "YELLOW", "OLIVE", "LIME", "GREEN",
"AQUA", "TEAL", "BLUE", "NAVY", "FUCHSIA", "PURPLE", "ORANGE", "BROWN"}
Dim keywordColor As Color = Colors.Blue
@@ -563,26 +567,37 @@ Public Class ScriptWindowVM
.G = 145,
.B = 120
}
Dim functionColor As Color = Colors.BlueViolet
Dim pattern As String = "(?<=function\s)[^(]+"
' Instantiate the regular expression object.
Dim regex As New Regex(pattern, RegexOptions.IgnoreCase)
' Ottieni tutte le corrispondenze
Dim matches As MatchCollection = regex.Matches(text)
' Itera attraverso tutte le corrispondenze e stampale
For Each match As Match In matches
HighlightText(rtb, text, " " & match.ToString(), functionColor)
Next
' Evidenzia le parole chiave
For Each keyword In keywords
HighlightText(rtb, keyword, keywordColor)
HighlightText(rtb, text, keyword, keywordColor)
Next
' Evidenzia le info
For Each color In colorsArray
HighlightText(rtb, "'" & color & "'", infoColor)
HighlightText(rtb, text, "'" & color & "'", infoColor)
Next
' Evidenzia i commenti
HighlightText(rtb, "--", commentColor, True)
HighlightText(rtb, text, "--", commentColor, True)
End Sub
Private Sub HighlightText(rtb As RichTextBox, word As String, color As Color, Optional isComment As Boolean = False)
Dim textRange As New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd)
Dim text As String = textRange.Text
Private Sub HighlightText(rtb As RichTextBox, text As String, word As String, color As Color, Optional isComment As Boolean = False)
Dim startIndex As Integer = 0
While startIndex < text.Length
If text.Contains(word) Then
@@ -623,6 +638,34 @@ Public Class ScriptWindowVM
Return navigator
End Function
Private Sub RegexFun(text As String)
Dim pattern As String = "(?<=function\s)[^(]+"
' Instantiate the regular expression object.
Dim r As Regex = New Regex(pattern, RegexOptions.IgnoreCase)
' Match the regular expression pattern against a text string.
Dim m As Match = r.Match(text)
Dim matchcount As Integer = 0
Do While m.Success
matchcount += 1
EgtOutLog("Match" & (matchcount))
Dim i As Integer
For i = 1 To 2
Dim g As Group = m.Groups(i)
EgtOutLog("Group" & i & "='" & g.ToString() & "'")
Dim cc As CaptureCollection = g.Captures
Dim j As Integer
For j = 0 To cc.Count - 1
Dim c As Capture = cc(j)
EgtOutLog("Capture" & j & "='" & c.ToString() _
& "', Position=" & c.Index)
Next
Next
m = m.NextMatch()
Loop
End Sub
#End Region ' Methods
#Region "COMMANDS"