forked from wooorm/starry-night
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.vba.js
126 lines (125 loc) · 4.14 KB
/
source.vba.js
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
// This is a TextMate grammar distributed by `starry-night`.
// This grammar is developed at
// <https://github.com/serkonda7/vscode-vba>
// and licensed `mpl-2.0`.
// See <https://github.com/wooorm/starry-night> for more info.
/** @type {import('../lib/index.js').Grammar} */
const grammar = {
extensions: ['.frm', '.vba'],
names: ['vba', 'visual-basic-for-applications'],
patterns: [
{include: '#comments'},
{include: '#functions'},
{include: '#keywords'},
{include: '#metadata'},
{include: '#numbers'},
{include: '#storage'},
{include: '#strings'},
{include: '#types'},
{match: '_(?=\\s*\\n)', name: 'constant.other.vba'}
],
repository: {
comments: {
begin:
"(?=')|(?:^(?:(\\d*)\\s*|[a-zA-Z][a-zA-Z0-9]{0,254}:\\s*)|:\\s*)(?=(?i:Rem ))",
beginCaptures: {1: {name: 'constant.numeric.decimal'}},
end: '(?<!\\s_)$\\n',
patterns: [
{match: "\\'.*", name: 'comment.line.quote'},
{match: 'Rem .*', name: 'comment.line.rem'},
{match: '^.*', name: 'comment.line.continuation'}
]
},
functions: {name: 'entity.name.function.vba'},
keywords: {
patterns: [
{
match:
'(?i:\\b(Do( While| Until)?|While|Case( Else)?|Else(If)?|For( Each)?|(I)?If|In|New|(Select )?Case|Then|To|Step|With)\\b)',
name: 'keyword.conditional.vba'
},
{
match:
'(?i:\\b(End( )?If|End (Select|With)|Next|Wend|Loop( While| Until)?|Exit (For|Do|While))\\b)',
name: 'keyword.conditional.end.vba'
},
{
match:
'(?i:\\b(Exit (Function|Property|Sub)|As|And|By(Ref|Val)|Goto|Is|Like|Mod|Not|On Error|Optional|Or|Resume Next|Stop|Xor|Eqv|Imp|TypeOf|AddressOf)\\b|(\\b(End)\\b(?=\\n)))',
name: 'keyword.control.vba'
},
{
match:
'(?i:\\b(Open|Close|Line Input|Lock|Unlock|Print|Seek|Get|Put|Write)\\b)',
name: 'keyword.io.vba'
},
{match: '(?i:\\b(Input)(?= \\#))', name: 'keyword.io.vba'},
{
match:
'(?i:\\b(Attribute|Call|End (Function|Property|Sub|Type|Enum)|(Const|Function|Property|Sub|Type|Enum)|Declare|PtrSafe|WithEvents|Event|RaiseEvent|Implements)\\b)',
name: 'keyword.other.vba'
},
{
match:
'(?i)\\bOption (Base [01]|Compare (Binary|Text)|Explicit|Private Module)\\b',
name: 'keyword.other.option.vba'
},
{
match: '(?i:\\b(Private|Public|Friend)\\b)',
name: 'keyword.other.visibility.vba'
},
{
match: '(?i)\\b(Empty|False|Nothing|Null|True)\\b',
name: 'constant.language.vba'
}
]
},
metadata: {
begin: '(?i)^\\s*(BEGIN)\\b',
beginCaptures: {1: {name: 'keyword.metadata.vba'}},
end: '(?i)^\\s*(END)\\b',
endCaptures: {0: {name: 'keyword.metadata.vba'}},
name: 'metadata.vba',
patterns: [{include: 'source.vba'}]
},
numbers: {
patterns: [
{
match:
'(?i)\\#((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)|[0-9]{1,2})(-|\\/)[0-9]{1,2}((-|\\/)[0-9]{1,4})?\\#',
name: 'constant.numeric.date'
},
{match: '(?<!\\w)-?\\d+(\\.\\d+)?', name: 'constant.numeric.decimal'},
{match: '(?i)-?&O[0-7]+', name: 'constant.numeric.octal'},
{match: '(?i)-?&H[0-9A-F]+', name: 'constant.numeric.hexadecimal'}
]
},
storage: {
patterns: [
{
match:
'(?i)\\b(Class|Const|Dim|(G|L|S)et|ReDim( Preserve)?|Erase|Static)\\b',
name: 'storage.modifier.vba'
}
]
},
strings: {
patterns: [{match: '\\"[^\\n\\r\\"]*"', name: 'string.quoted.double'}]
},
types: {
patterns: [
{
match:
'(?i)\\b(Any|Byte|Boolean|Currency|Collection|Date|Double|Integer|Long(Long|Ptr)?|Object|Single|String|Variant)\\b',
name: 'support.type.builtin.vba'
},
{
captures: {1: {name: 'support.type'}},
match: '(?i)(?<= As )([a-zA-Z][a-zA-Z0-9_]*)'
}
]
}
},
scopeName: 'source.vba'
}
export default grammar