Skip to content

Commit 3732004

Browse files
committed
Fix multiple issues with grammar
1 parent 6db28b9 commit 3732004

File tree

1 file changed

+75
-13
lines changed

1 file changed

+75
-13
lines changed

client/src/syntaxes/vba.tmLanguage.yaml

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ repository:
1717
- include: "#moduleHeader"
1818
- include: "#enum"
1919
- include: "#struct"
20+
- include: "#funcDeclareSig"
2021
- include: "#mthdSig"
2122
- include: "#variableDeclarations"
2223
- include: "#block"
@@ -41,6 +42,7 @@ repository:
4142
name: source.language.vba
4243
patterns:
4344
- include: "#comments"
45+
- include: "#vbaBuiltIns"
4446
- include: "#literals"
4547
- include: "#operators"
4648
- include: "#keywords"
@@ -127,7 +129,7 @@ repository:
127129
repository:
128130
flowDecision:
129131
name: keyword.control.flow.decision.vba
130-
match: "(?i)\\b(if|then|elseif|else|end if|select case|case|switch|end select)\\b"
132+
match: '(?i)(^|\s+)([#]?if|then|[#]?elseif|[#]?else|[#]?end if|select case|case|switch|end select)\b'
131133

132134
flowLoop:
133135
name: keyword.control.flow.loop.vba
@@ -204,6 +206,18 @@ repository:
204206
name: variable.other.constant.label.vba
205207
match: "(?i)^([a-z][a-z0-9_]*|\\d+):"
206208

209+
vbaBuiltIns:
210+
patterns:
211+
- include: "#vbaEnum"
212+
- include: "#vbaConstant"
213+
repository:
214+
vbaEnum:
215+
match: (?i)(vba7|win64)
216+
name: constant.numeric.enum.vba
217+
vbaConstant:
218+
match: (?i)(vbNewLine|vbCr|vbLf|vbCrLf)
219+
name: constant.numeric.enum.vba
220+
207221
objectModel:
208222
patterns:
209223
- include: "#application"
@@ -266,22 +280,26 @@ repository:
266280
name: support.type.primitive.vba
267281
match: "(?i)(?<=\\bAs)\\s+(boolean|byte|currency|date|decimal|double|integer|long(long|ptr)?|single|string|variant)\\b"
268282
objectType:
269-
name: entity.name.type.vba
270-
match: "(?i)(?<=\\bAs)\\s+([A-Z][A-Z0-9_]*)\\b"
283+
name: support.type.object.vba
284+
match: (?i)(?<=\bAs)(\s+New)?\s+([A-Z][A-Z0-9_]*)\b
285+
captures:
286+
1:
287+
name: keyword.storage.new.vba
288+
2:
289+
name: support.type.object.vba
271290

272291
arguments:
273292
name: source.args.vba
274293
patterns:
275294
- include: "#lineContinuation"
276295
- include: "#paramArray"
277296
- include: "#funcCall"
278-
- include: "#subCall"
279297
- include: "#argsVariable"
280298
- include: "#argsLiteral"
281299
- include: "#language"
282300
repository:
283301
argsVariable:
284-
match: "(?i),?\\s*(Optional\\s+)?((?:ByVal|ByRef)\\s+)?([a-z][a-z0-9_]*)(?:\\s*(\\bas\\s+[a-z][a-z0-9_]*))?\\b(\\s+=\\s+[^,)]*)?"
302+
match: (?i),?\s*(Optional\s+)?((?:ByVal|ByRef)\s+)?([a-z][a-z0-9_]*)(?:\s*(\bas\s+[a-z][a-z0-9_]*))?\b(\s+=\s+[^,)]*)?
285303
captures:
286304
1:
287305
name: storage.type.modifier.vba
@@ -422,10 +440,40 @@ repository:
422440
patterns:
423441
- include: "#types"
424442

443+
funcDeclareSig:
444+
name: source.declare.signature.vba
445+
begin: (?i)^\s*((?:Public|Private|Friend)?\b\s*Declare)\s+(PtrSafe\s+)?(Sub|Function)\s+([a-z][a-z0-9_]*)\s+(Lib)\s+("[a-z][a-z0-9._]*")(?:\s+(Alias)\s+("[a-z][a-z0-9_]*"))?\s+\(
446+
end: '(?i)(?:\))\s+(as\s+[a-z][a-z0-9_]*)'
447+
beginCaptures:
448+
1: # Public|Private|Friend Declare
449+
name: storage.type.method.vba
450+
2: # PtrSafe
451+
name: storage.type.method.vba
452+
3: # Sub|Function
453+
name: storage.type.method.vba
454+
4: # Name
455+
name: entity.name.function.vba
456+
5: # Lib
457+
name: storage.type.method.vba
458+
6: # Lib name
459+
patterns:
460+
- include: "#literals"
461+
7: # Alias
462+
name: storage.type.method.vba
463+
8: # Alias name
464+
patterns:
465+
- include: "#literals"
466+
endCaptures:
467+
1: # return type
468+
patterns:
469+
- include: "#types"
470+
patterns:
471+
- include: "#arguments"
472+
425473
mthdSig:
426474
name: source.method.signature.vba
427-
begin: "(?i)^\\s*((?:Public|Private)?\\b\\s*(?:(?:Sub|Function)|Property\\s+(?:Let|Get|Set)))\\s+([a-z][a-z0-9_]*)\\s*(\\()"
428-
end: "(?i)(\\))\\s+(as\\s+[a-z][a-z0-9_]*)?"
475+
begin: '(?i)^\s*((?:Public|Private)?\b\s*(?:(?:Sub|Function)|Property\s+(?:Let|Get|Set)))\s+([a-z][a-z0-9_]*)\s*(\()'
476+
end: '(?i)(\))\s+(as\s+[a-z][a-z0-9_]*)?'
429477
beginCaptures:
430478
1:
431479
name: storage.type.method.vba
@@ -439,7 +487,6 @@ repository:
439487
2: # return type
440488
patterns:
441489
- include: "#types"
442-
443490
patterns:
444491
- include: "#arguments"
445492

@@ -478,7 +525,7 @@ repository:
478525
repository:
479526
variableDeclaration:
480527
name: storage.var-declaration.vba
481-
match: "(?i)^\\s*(Dim|Public|Private)\\s+([a-z][a-z0-9_]*)(\\(.*\\))?(\\s+As\\s+[A-Z][A-Z0-9_]*)?"
528+
match: (?i)^\s*(Dim|Public|Private)\s+([a-z][a-z0-9_]*)(\(.*\))?(\s+As(?:\s+New)?\s+[A-Z][A-Z0-9_]*)?
482529
captures:
483530
1:
484531
# Dim|Private
@@ -513,8 +560,10 @@ repository:
513560
patterns:
514561
- include: "#language"
515562

563+
# TODO: Redo this so it can take into account chaining, e.g.:
564+
# MyClass.MyProp = SomeObject.Foo(20)
516565
variableAssignment:
517-
match: "(?i)((Get|Let|Set)\\s+)?([a-z][a-z0-9_]*)(\\s*=\\s*)(.*)"
566+
match: (?i)((Get|Let|Set)\s+)?([a-z][a-z0-9._]*)(\s*=\s*)(.*)
518567
captures:
519568
2:
520569
name: keyword.control.vba
@@ -525,7 +574,7 @@ repository:
525574
5:
526575
patterns:
527576
- include: "#funcCall"
528-
- include: "#subCall"
577+
# - include: "#subCall" # Why would a variable assignment ever have a sub call?
529578
- include: "#language"
530579

531580
funcCall:
@@ -543,10 +592,23 @@ repository:
543592
- include: "#lineContinuation"
544593

545594
subCall:
595+
begin: (?i)([a-z][a-z0-9._]*)\s+(.*,.*)
596+
beginCaptures:
597+
1:
598+
name: entity.name.function.call.vba
599+
2:
600+
patterns:
601+
- include: "#arguments"
602+
end: \n
603+
patterns:
604+
# - include: "#subCallMultiLine"
605+
- include: "#arguments"
606+
607+
subCallOld:
546608
# TODO: Better way to do this.
547609
# Captures sub calls with two or more args.
548610
# Required because they break properties somehow.
549-
begin: "(?i)([a-z][a-z0-9_]*)\\s+(.*,.*)"
611+
begin: (?i)([a-z][a-z0-9_]*)\s+(.*,.*)
550612
beginCaptures:
551613
1:
552614
name: entity.name.function.call.vba
@@ -565,7 +627,7 @@ repository:
565627
1:
566628
name: entity.name.function.call.vba
567629
patterns:
568-
- include: "#args"
630+
- include: "#arguments"
569631
end: "\\n"
570632

571633
args:

0 commit comments

Comments
 (0)