Skip to content

Commit 9e2eae2

Browse files
committed
Updated namespaces and converted syntax highlighting from C# (not yet applied)
1 parent 261dde3 commit 9e2eae2

18 files changed

+961
-84
lines changed

VB/App_Data/ScriptHelp.sdf

0 Bytes
Binary file not shown.

VB/Forms/frmSettings.vb

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Option Strict On
22
Option Explicit On
33

4-
Imports System.Environment
54
Imports System.Drawing
65
Imports System.Windows.Forms
6+
Imports ScriptHelp.Scripts
77

88
Public Class frmSettings
99

@@ -12,24 +12,29 @@ Public Class frmSettings
1212
My.Settings.Save()
1313

1414
Catch ex As Exception
15-
Call ErrorMsg(ex)
15+
ErrorHandler.DisplayMessage(ex)
1616
Exit Try
1717

1818
End Try
1919

2020
End Sub
2121

2222
Private Sub frmSettings_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
23-
Call LoadSettings()
24-
Call SetFormIcon(Me, My.Resources.Save)
25-
Dim strVersion As String = My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor & "." & My.Application.Info.Version.Build & "." & My.Application.Info.Version.Revision
26-
Me.Text = "Settings for " & My.Application.Info.Title.ToString.Replace("&", "&&") & Space(1) & strVersion
23+
Try
24+
Call LoadSettings()
25+
Call SetFormIcon(Me, My.Resources.Save)
26+
Dim version As String = My.Application.Info.Version.Major & "." & My.Application.Info.Version.Minor & "." & My.Application.Info.Version.Build & "." & My.Application.Info.Version.Revision
27+
Me.Text = "Settings for " & My.Application.Info.Title.ToString.Replace("&", "&&") & Space(1) & version
28+
29+
Catch ex As Exception
30+
ErrorHandler.DisplayMessage(ex)
31+
Exit Try
32+
33+
End Try
34+
2735
End Sub
2836

2937
Public Sub LoadSettings()
30-
'--------------------------------------------------------------------------------------------------------------------
31-
' Purpose: load settings
32-
'--------------------------------------------------------------------------------------------------------------------
3338
Try
3439
Me.pgdSettings.SelectedObject = My.Settings
3540
''Only show "user" settings
@@ -38,42 +43,23 @@ Public Class frmSettings
3843
'pgdSettings.BrowsableAttributes = attrs
3944

4045
Catch ex As Exception
41-
Call ErrorMsg(ex)
46+
ErrorHandler.DisplayMessage(ex)
4247
Exit Try
4348

4449
End Try
4550

4651
End Sub
4752

48-
Public Sub SetFormIcon(ByRef frmCurrent As Form, ByRef bmp As Bitmap)
49-
'--------------------------------------------------------------------------------------------------------------------
50-
' Purpose: set form icon
51-
'--------------------------------------------------------------------------------------------------------------------
53+
Public Sub SetFormIcon(ByRef frmCurrent As System.Windows.Forms.Form, ByRef bmp As Bitmap)
5254
Try
5355
frmCurrent.Icon = Icon.FromHandle(bmp.GetHicon)
5456

5557
Catch ex As Exception
56-
Call ErrorMsg(ex)
58+
ErrorHandler.DisplayMessage(ex)
5759
Exit Try
5860

5961
End Try
6062

6163
End Sub
6264

63-
Public Sub ErrorMsg(ByRef ex As Exception)
64-
'--------------------------------------------------------------------------------------------------------------------
65-
' Global error message for all procedures
66-
'--------------------------------------------------------------------------------------------------------------------
67-
Dim Msg As String
68-
Dim sf As New System.Diagnostics.StackFrame(1)
69-
Dim caller As System.Reflection.MethodBase = sf.GetMethod()
70-
Dim Proc As String = (caller.Name).Trim
71-
72-
Msg = "Contact your system administrator." & vbCrLf
73-
Msg += "Procedure: " & Proc & vbCrLf
74-
Msg += "Description: " & ex.ToString & vbCrLf '
75-
MsgBox(Msg, vbCritical, "Unexpected Error")
76-
77-
End Sub
78-
7965
End Class

VB/ScriptHelp.vbproj

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,6 @@
246246
<Compile Include="Scripts\Form.vb" />
247247
<Compile Include="Scripts\Formula.vb" />
248248
<Compile Include="Scripts\Ribbon.vb" />
249-
<Compile Include="Scripts\Syntax\CaseInsensitivePatternDefinition.vb" />
250-
<Compile Include="Scripts\Syntax\ColorUtils.vb" />
251-
<Compile Include="Scripts\Syntax\Expression.vb" />
252-
<Compile Include="Scripts\Syntax\ExpressionType.vb" />
253-
<Compile Include="Scripts\Syntax\PatternDefinition.vb" />
254-
<Compile Include="Scripts\Syntax\PatternStyleMap.vb" />
255-
<Compile Include="Scripts\Syntax\StringExtensions.vb" />
256-
<Compile Include="Scripts\Syntax\StyleGroupPair.vb" />
257-
<Compile Include="Scripts\Syntax\SyntaxHighlighter.vb" />
258-
<Compile Include="Scripts\Syntax\SyntaxStyle.vb" />
259-
<Compile Include="Scripts\Syntax\TextBoxBaseExtensions.vb" />
260249
<Compile Include="TaskPane\GraphData.Designer.vb">
261250
<DependentUpon>GraphData.vb</DependentUpon>
262251
</Compile>
@@ -378,7 +367,9 @@
378367
<ItemGroup>
379368
<Service Include="{94E38DFF-614B-4CBD-B67C-F211BB35CE8B}" />
380369
</ItemGroup>
381-
<ItemGroup />
370+
<ItemGroup>
371+
<Folder Include="Scripts\Syntax\" />
372+
</ItemGroup>
382373
<PropertyGroup>
383374
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
384375
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1-
Public Class CaseInsensitivePatternDefinition
1+
Imports System.Collections.Generic
22

3-
End Class
3+
Namespace Scripts
4+
Namespace Syntax
5+
6+
Public Class CaseInsensitivePatternDefinition
7+
8+
Inherits PatternDefinition
9+
10+
Public Sub New(tokens As IEnumerable(Of String))
11+
'MyBase.New(False, tokens)
12+
End Sub
13+
14+
Public Sub New(ParamArray tokens As String())
15+
'MyBase.New(False, tokens)
16+
End Sub
17+
18+
End Class
19+
20+
End Namespace
21+
End Namespace

VB/Scripts/Syntax/ColorUtils.vb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1-
Public Class ColorUtils
1+
Imports System.Drawing
22

3-
End Class
3+
Namespace Scripts
4+
Namespace Syntax
5+
6+
Public Class ColorUtils
7+
8+
Public Shared Function ColorToRtfTableEntry(color As Color) As String
9+
Return [String].Format("\red{0}\green{1}\blue{2}", color.R, color.G, color.B)
10+
End Function
11+
12+
End Class
13+
14+
End Namespace
15+
End Namespace

VB/Scripts/Syntax/Expression.vb

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,65 @@
1-
Public Class Expression
1+
2+
Namespace Scripts
3+
Namespace Syntax
24

3-
End Class
5+
Public Class Expression
6+
7+
Public Property Type() As ExpressionType
8+
Get
9+
Return m_Type
10+
End Get
11+
Private Set
12+
m_Type = Value
13+
End Set
14+
End Property
15+
Private m_Type As ExpressionType
16+
17+
Public Property Content() As String
18+
Get
19+
Return m_Content
20+
End Get
21+
Private Set
22+
m_Content = Value
23+
End Set
24+
End Property
25+
Private m_Content As String
26+
27+
Public Property Group() As String
28+
Get
29+
Return m_Group
30+
End Get
31+
Private Set
32+
m_Group = Value
33+
End Set
34+
End Property
35+
Private m_Group As String
36+
37+
Public Sub New(content__1 As String, type__2 As ExpressionType, group__3 As String)
38+
If content__1 Is Nothing Then
39+
Throw New ArgumentNullException("content")
40+
End If
41+
If group__3 Is Nothing Then
42+
Throw New ArgumentNullException("group")
43+
End If
44+
45+
Type = type__2
46+
Content = content__1
47+
Group = group__3
48+
End Sub
49+
50+
Public Sub New(content As String, type As ExpressionType)
51+
Me.New(content, type, [String].Empty)
52+
End Sub
53+
54+
Public Overrides Function ToString() As String
55+
If Type = ExpressionType.Newline Then
56+
Return [String].Format("({0})", Type)
57+
End If
58+
59+
Return [String].Format("({0} --> {1}{2})", Content, Type, If(Group.Length > 0, Convert.ToString(" --> ") & Group, [String].Empty))
60+
End Function
61+
62+
End Class
63+
64+
End Namespace
65+
End Namespace
Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1-
Public Class ExpressionType
1+
2+
Namespace Scripts
3+
Namespace Syntax
24

3-
End Class
5+
Public Enum ExpressionType
6+
''' <summary>
7+
''' None
8+
''' </summary>
9+
None = 0
10+
''' <summary>
11+
''' i.e. a word which is neither keyword nor inside any word-group
12+
''' </summary>
13+
Identifier
14+
''' <summary>
15+
''' Operator
16+
''' </summary>
17+
[Operator]
18+
''' <summary>
19+
''' Number
20+
''' </summary>
21+
Number
22+
''' <summary>
23+
''' Whitespace
24+
''' </summary>
25+
Whitespace
26+
''' <summary>
27+
''' Newline
28+
''' </summary>
29+
Newline
30+
''' <summary>
31+
''' Keyword
32+
''' </summary>
33+
Keyword
34+
''' <summary>
35+
''' Comment
36+
''' </summary>
37+
Comment
38+
''' <summary>
39+
''' CommentLine
40+
''' </summary>
41+
CommentLine
42+
''' <summary>
43+
''' String
44+
''' </summary>
45+
[String]
46+
''' <summary>
47+
''' needs extra argument
48+
''' </summary>
49+
DelimitedGroup
50+
''' <summary>
51+
''' needs extra argument
52+
''' </summary>
53+
WordGroup
54+
End Enum
55+
56+
57+
End Namespace
58+
End Namespace
Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
1-
Public Class PatternDefinition
1+
Imports System.Collections.Generic
2+
Imports System.Text.RegularExpressions
23

3-
End Class
4+
Namespace Scripts
5+
Namespace Syntax
6+
7+
Public Class PatternDefinition
8+
Private ReadOnly _regex As Regex
9+
Private _expressionType As ExpressionType = ExpressionType.Identifier
10+
Private ReadOnly _isCaseSensitive As Boolean = False
11+
12+
Public Sub New(regularExpression As Regex)
13+
If regularExpression Is Nothing Then
14+
Throw New ArgumentNullException("regularExpression")
15+
End If
16+
_regex = regularExpression
17+
End Sub
18+
19+
Public Sub New(regexPattern As String)
20+
If [String].IsNullOrEmpty(regexPattern) Then
21+
Throw New ArgumentException("regex pattern must not be null or empty", "regexPattern")
22+
End If
23+
24+
_regex = New Regex(regexPattern, RegexOptions.Compiled)
25+
End Sub
26+
27+
Public Sub New(ParamArray tokens As String())
28+
Me.New(True, tokens)
29+
End Sub
30+
31+
Public Sub New(tokens As IEnumerable(Of String))
32+
Me.New(True, tokens)
33+
End Sub
34+
35+
Friend Sub New(caseSensitive As Boolean, tokens As IEnumerable(Of String))
36+
If tokens Is Nothing Then
37+
Throw New ArgumentNullException("tokens")
38+
End If
39+
40+
caseSensitive = _isCaseSensitive
41+
42+
Dim regexTokens = New List(Of String)()
43+
44+
For Each token As var In tokens
45+
Dim escaptedToken = Regex.Escape(token.Trim())
46+
47+
If escaptedToken.Length > 0 Then
48+
If [Char].IsLetterOrDigit(escaptedToken(0)) Then
49+
regexTokens.Add([String].Format("\b{0}\b", escaptedToken))
50+
Else
51+
regexTokens.Add(escaptedToken)
52+
End If
53+
End If
54+
Next
55+
56+
Dim pattern As String = [String].Join("|", regexTokens)
57+
Dim regexOptions__1 = RegexOptions.Compiled
58+
If Not caseSensitive Then
59+
regexOptions__1 = regexOptions__1 Or RegexOptions.IgnoreCase
60+
End If
61+
_regex = New Regex(pattern, regexOptions__1)
62+
End Sub
63+
64+
Friend Property ExpressionType() As ExpressionType
65+
Get
66+
Return _expressionType
67+
End Get
68+
Set
69+
_expressionType = Value
70+
End Set
71+
End Property
72+
73+
Friend ReadOnly Property IsCaseSensitive() As Boolean
74+
Get
75+
Return _isCaseSensitive
76+
End Get
77+
End Property
78+
79+
Friend ReadOnly Property Regex() As Regex
80+
Get
81+
Return _regex
82+
End Get
83+
End Property
84+
85+
End Class
86+
87+
End Namespace
88+
End Namespace

0 commit comments

Comments
 (0)