1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class VisualBasic < RegexLexer
title "Visual Basic"
desc "Visual Basic"
tag 'vb'
aliases 'visualbasic'
filenames '*.vbs', '*.vb'
mimetypes 'text/x-visualbasic', 'application/x-visualbasic'
def self.keywords
@keywords ||= Set.new %w(
AddHandler Alias ByRef ByVal CBool CByte CChar CDate CDbl CDec
CInt CLng CObj CSByte CShort CSng CStr CType CUInt CULng CUShort
Call Case Catch Class Const Continue Declare Default Delegate
Dim DirectCast Do Each Else ElseIf End EndIf Enum Erase Error
Event Exit False Finally For Friend Function Get Global GoSub
GoTo Handles If Implements Imports Inherits Interface Let
Lib Loop Me Module MustInherit MustOverride MyBase MyClass
Namespace Narrowing New Next Not NotInheritable NotOverridable
Nothing Of On Operator Option Optional Overloads Overridable
Overrides ParamArray Partial Private Property Protected Public
RaiseEvent ReDim ReadOnly RemoveHandler Resume Return Select Set
Shadows Shared Single Static Step Stop Structure Sub SyncLock
Then Throw To True Try TryCast Using Wend When While Widening
With WithEvents WriteOnly
)
end
def self.keywords_type
@keywords_type ||= Set.new %w(
Boolean Byte Char Date Decimal Double Integer Long Object
SByte Short Single String Variant UInteger ULong UShort
)
end
def self.operator_words
@operator_words ||= Set.new %w(
AddressOf And AndAlso As GetType In Is IsNot Like Mod Or OrElse
TypeOf Xor
)
end
def self.builtins
@builtins ||= Set.new %w(
Console ConsoleColor
)
end
id = /[a-z_]\w*/i
upper_id = /[A-Z]\w*/
state :whitespace do
rule %r/\s+/, Text
rule %r/\n/, Text, :bol
rule %r/rem\b.*?$/i, Comment::Single
rule %r(%\{.*?%\})m, Comment::Multiline
rule %r/'.*$/, Comment::Single
end
state :bol do
rule %r/\s+/, Text
rule %r/<.*?>/, Name::Attribute
rule(//) { :pop! }
end
state :root do
mixin :whitespace
rule %r(
[#]If\b .*? \bThen
| [#]ElseIf\b .*? \bThen
| [#]End \s+ If
| [#]Const
| [#]ExternalSource .*? \n
| [#]End \s+ ExternalSource
| [#]Region .*? \n
| [#]End \s+ Region
| [#]ExternalChecksum
)x, Comment::Preproc
rule %r/[.]/, Punctuation, :dotted
rule %r/[(){}!#,:]/, Punctuation
rule %r/Option\s+(Strict|Explicit|Compare)\s+(On|Off|Binary|Text)/,
Keyword::Declaration
rule %r/End\b/, Keyword, :end
rule %r/(Dim|Const)\b/, Keyword, :dim
rule %r/(Function|Sub|Property)\b/, Keyword, :funcname
rule %r/(Class|Structure|Enum)\b/, Keyword, :classname
rule %r/(Module|Namespace|Imports)\b/, Keyword, :namespace
rule upper_id do |m|
match = m[0]
if self.class.keywords.include? match
token Keyword
elsif self.class.keywords_type.include? match
token Keyword::Type
elsif self.class.operator_words.include? match
token Operator::Word
elsif self.class.builtins.include? match
token Name::Builtin
else
token Name
end
end
rule(
%r(&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|<=|>=|<>|[-&*/\\^+=<>.]),
Operator
)
rule %r/"/, Str, :string
rule %r/#{id}[%&@!#\$]?/, Name
rule %r/#.*?#/, Literal::Date
rule %r/(\d+\.\d*|\d*\.\d+)(f[+-]?\d+)?/i, Num::Float
rule %r/\d+([SILDFR]|US|UI|UL)?/, Num::Integer
rule %r/&H[0-9a-f]+([SILDFR]|US|UI|UL)?/, Num::Integer
rule %r/&O[0-7]+([SILDFR]|US|UI|UL)?/, Num::Integer
rule %r/_\n/, Keyword
end
state :dotted do
mixin :whitespace
rule id, Name, :pop!
end
state :string do
rule %r/""/, Str::Escape
rule %r/"C?/, Str, :pop!
rule %r/[^"]+/, Str
end
state :dim do
mixin :whitespace
rule id, Name::Variable, :pop!
rule(//) { pop! }
end
state :funcname do
mixin :whitespace
rule id, Name::Function, :pop!
end
state :classname do
mixin :whitespace
rule id, Name::Class, :pop!
end
state :namespace do
mixin :whitespace
rule %r/#{id}([.]#{id})*/, Name::Namespace, :pop!
end
state :end do
mixin :whitespace
rule %r/(Function|Sub|Property|Class|Structure|Enum|Module|Namespace)\b/,
Keyword, :pop!
rule(//) { pop! }
end
end
end
end
|