Skip to content

Commit 91247fe

Browse files
committed
Add multi-line support
1 parent e1f9090 commit 91247fe

File tree

3 files changed

+142
-109
lines changed

3 files changed

+142
-109
lines changed

client/src/syntaxes/vba.tmLanguage.yaml

Lines changed: 54 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ repository:
8282
name: keyword.control.line-continuation.vba
8383
match: (?<=\s)_\s*\n
8484

85-
syntaxLines:
86-
name: meta.syntax-lines.vba
87-
match: ((?:[^\n"':]|"(?:\\.|[^\n"\\])*")+|"(?:\\.|[^\n"\\])*")(?:('.*)*)?
88-
captures:
89-
1: # Split line
90-
patterns:
91-
- include: "#main"
92-
2: # Comments
93-
patterns:
94-
- include: "#comments"
95-
9685
main:
9786
patterns:
9887
- include: "#declareFunctionSignature"
@@ -109,10 +98,11 @@ repository:
10998
- include: "#literals"
11099
- include: "#operators"
111100
- include: "#keywords"
112-
- include: "#variables"
101+
- include: "#kw-storageMe"
113102
- include: "#functionCall"
114103
- include: "#objectModel"
115104
- include: "#subCall"
105+
- include: "#subCallNoArgs"
116106

117107

118108
literals:
@@ -335,10 +325,6 @@ repository:
335325
name: invalid.illegal.vba
336326
match: "^#.*"
337327

338-
variables:
339-
name: variable.language.me.vba
340-
match: (?i)\s+(Me)(?=\.|\s)
341-
342328
labels:
343329
# name: variable.other.constant.label.vba
344330
match: '(?i)^(\s*[a-z][a-z0-9_]*|\d+):'
@@ -461,63 +447,15 @@ repository:
461447
2: # Identifier
462448
name: variable.parameter.vba
463449

464-
# TODO: This needs to be repurposed to sub / function CALL rather than signature.
465-
# Will need to separate arguments by comma, take line endings into account, and ignore commas inside parentheses.
466-
# someSub someVar, "someLiteral", someFunc(1, 2, 3), _
467-
# someNextLineFunc()
468450
arguments:
469-
# Rules that have no match will never return a name in the hierarchy.
470-
# This name doesn't do anything but leaving this as usage notes.
471-
name: source.args.vba
451+
name: meta.arguments.vba
452+
begin: (\s+|\(\s*)
453+
end: (?=[\n')])
472454
patterns:
473455
- include: "#lineContinuation"
474-
- include: "#paramArray"
475456
- include: "#functionCall"
476-
- include: "#argsVariable"
477-
- include: "#language"
478-
- include: "#argsLiteral"
479-
repository:
480-
argsVariable:
481-
name: meta.arguments.argsVariable.vba
482-
match: (?i),?\s*((?:Optional\s+)?(?:(?:ByVal|ByRef)\s+)?)?([a-z][a-z0-9_]*)(\(\))?(?:\s+(as\s+[a-z][a-z0-9_]*))?(\s*=\s*[^,)]+)?
483-
# Attempted replacing \s with (?:\s+|\s*_\s*\n) to consume a space or a line ending but it refuses to play the game.
484-
# match: ~~ doesn't work (?i),?(?:\s+|\s*_\s*\n)*((?:Optional(?:\s+|\s*_\s*\n)+)?(?:(?:ByVal|ByRef)(?:\s+|\s*_\s*\n)+)?)?([a-z][a-z0-9_]*)(?:(?:\s+|\s*_\s*\n)+(as(?:\s+|\s*_\s*\n)+[a-z][a-z0-9_]*))?((?:\s+|\s*_\s*\n)*=(?:\s+|\s*_\s*\n)*[^,\n)]+)?
485-
# match: ~~ all broken (?i),?(?:\s*_\s*\n)*((?:Optional(?:\s+(?:\s*_\s*\n)*))?(?:(?:ByVal|ByRef)(?:\s+(?:\s*_\s*\n)*))?)?([a-z][a-z0-9_]*)(?:(?:\s+(?:\s*_\s*\n)*)(as\(?:\s+(?:\s*_\s*\n)*)[a-z][a-z0-9_]*))?((?:\s*_\s*\n)*=(?:\s*_\s*\n)*[^,)]+)?
486-
captures:
487-
1: # Optional? ByVal|ByRef?
488-
name: storage.type.modifier.vba
489-
2: # Identifier
490-
name: variable.parameter.vba
491-
3: # As Type?
492-
patterns:
493-
- include: "#types"
494-
4:
495-
patterns:
496-
- include: "#language"
497-
498-
argsLiteral:
499-
# Should ideally only match on something that could be considered a literal.
500-
# This kludge will at least not consume unmatched close parentheses.
501-
name: meta.arguments.argsLiteral.vba
502-
match: ((?:[^(",\n()]|"(?:\\.|[^\n"\\])*"|\([^)]*\))+|"(?:\\.|[^\n"\\])*")
503-
captures:
504-
1:
505-
patterns:
506-
- include: "#literals"
507-
508-
paramArray:
509-
name: meta.args.paramarray.vba
510-
match: (?i)(,)?\s*(ParamArray)\s+([a-z][a-z0-9_]*)(?:\(\))(\s+As\s+Variant)?
511-
captures:
512-
1:
513-
name: punctuation.separator.vba
514-
2:
515-
name: storage.type.modifier.array.vba
516-
3:
517-
name: variable.parameter.vba
518-
4:
519-
patterns:
520-
- include: "#types"
457+
- include: "#separator"
458+
- include: "#expression"
521459

522460
comments:
523461
patterns:
@@ -796,12 +734,9 @@ repository:
796734
blockLines:
797735
name: source.methodlines.vba
798736
match: (?:(^(?:\s*[a-z0-9]*?:\s*)(?:\s+'.*)?$)|(.*):)
799-
# match: (?:(^(?:\s*[a-z0-9]*?:\s*)(?:\s+'.*)?$)|(.*):)
800737
captures:
801738
1: # label
802739
name: source.methodlines.label.vba
803-
# patterns:
804-
# - include: "#labels"
805740
2: # colon separated line
806741
patterns:
807742
- include: "#block"
@@ -859,25 +794,23 @@ repository:
859794
- include: "#language"
860795

861796
variableAssignment:
862-
match: (?i)(?:(Get|Let|Set)\s+)?(?:([a-z][a-z0-9_]*))?(\.(?:(?:[a-z][a-z0-9_]*)?\.)*)?([a-z][a-z0-9_]*)?(\s*=\s*)(.*)
863-
captures:
864-
1: # Get|Let|Set
797+
name: meta.variable-assignment.vba
798+
begin: (?i)(?:(Let|Set)\s+)?((?:[a-z][a-z0-9_]*)?(?:\.(?:(?:[a-z][a-z0-9_]*)?\.)*)?(?:[a-z][a-z0-9_]*)?)(\s*=\s*)
799+
end: (?=[':\n])
800+
beginCaptures:
801+
1: # Let|Set
865802
name: keyword.control.vba
866-
2: # Variable name
867-
name: variable.other.assignment.vba
868-
3: # Properties
869-
patterns:
870-
- include: "#propertyChain"
871-
4: # Property name
872-
name: support.variable.property.vba
873-
5: # =
874-
name: keyword.operator.assignment.vba
875-
6: # Expression
803+
2: # Variable property chain name
876804
patterns:
877-
- include: "#expression"
878-
- include: "#functionCall"
879805
- include: "#variable"
880-
- include: "#language"
806+
3: # =
807+
name: keyword.operator.assignment.vba
808+
patterns:
809+
- include: "#expression"
810+
- include: "#functionCall"
811+
- include: "#variable"
812+
- include: "#language"
813+
- include: "#lineContinuation"
881814

882815
propertyChain:
883816
match: (?i)(\.)([a-z][a-z0-9_]*)*
@@ -902,31 +835,56 @@ repository:
902835

903836
functionCall:
904837
name: meta.function.call.vba
905-
begin: (?i)([a-z][a-z0-9_]*)\(
906-
end: \)
838+
begin: (?i)(?:([a-z][a-z0-9_]*)(?=\.))?(\.(?:(?:[a-z][a-z0-9_]*)?\.)*)?([a-z][a-z0-9_]*)([&%#!@$^])?(?=\()
839+
end: (\)|(?='))
907840
beginCaptures:
908841
1:
842+
patterns:
843+
- include: "#kw-storageMe"
844+
- include: "#variable"
845+
2:
846+
patterns:
847+
- include: "#propertyChain"
848+
3:
909849
name: entity.name.function.call.vba
850+
4:
851+
name: support.type.primitive.vba
910852
patterns:
911853
# These calls need to be back to a top level group because
912854
# textMate does not seem to support a repository in a begin/end
913855
- include: "#arguments"
914-
- include: "#lineContinuation"
915856

916857
subCall:
917858
name: meta.sub-call.vba
918-
begin: (?i)([a-z][a-z0-9._]*)\s+(.*)
859+
begin: (?i)(?:([a-z][a-z0-9_]*)(?=\.))?(\.(?:(?:[a-z][a-z0-9_]*)?\.)*)?([a-z][a-z0-9_]*)\s*(?=\s[^,'\n])
860+
end: (?=[\n'])
919861
beginCaptures:
920862
1:
921-
name: entity.name.function.call.vba
863+
patterns:
864+
- include: "#kw-storageMe"
865+
- include: "#variable"
922866
2:
923867
patterns:
924-
- include: "#arguments"
925-
end: \n
868+
- include: "#propertyChain"
869+
3:
870+
name: entity.name.function.call.vba
926871
patterns:
927-
# - include: "#subCallMultiLine"
928872
- include: "#arguments"
929873

874+
subCallNoArgs:
875+
name: meta.sub-call.vba
876+
match: (?i)(?:([a-z][a-z0-9_]*)(?=\.))?(\.(?:(?:[a-z][a-z0-9_]*)?\.)*)?([a-z][a-z0-9_]*)
877+
captures:
878+
1:
879+
patterns:
880+
- include: "#kw-storageMe"
881+
- include: "#variable"
882+
2:
883+
patterns:
884+
- include: "#propertyChain"
885+
3:
886+
name: entity.name.function.call.vba
887+
930888
testing:
931889
patterns:
932890
- name: keyword.control

test/textmate/unit/classHeaders.vba

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ BEGIN
1010

1111
MultiUse = -1 'True
1212
' ^^^^^^^^^^^^^^^^^^^^ entity.other.attribute-name.block.vba
13-
' ^ keyword.operator.comparison.vba
13+
' ^^^^^^^^ support.variable.property.vba
14+
' ^ keyword.operator.assignment.vba
1415
' ^^ constant.numeric.vba
1516
' ^^^^^ comment.line.apostrophe.vba
1617

@@ -20,43 +21,43 @@ END
2021
Attribute VB_Name = "ClassName"
2122
' <------------------------------ meta.attribute.vba
2223
' <--------- keyword.attribute.vba
23-
' ^^^^^^^ entity.other.attribute-name.vba
24-
' ^ keyword.operator.comparison.vba
24+
' ^^^^^^^ support.variable.property.vba
25+
' ^ keyword.operator.assignment.vba
2526
' ^^^^^^^^^^^ string.quoted.double.vba
2627

2728
Attribute VB_Description = "Class description goes here"
2829
' <------------------------------------------------------- meta.attribute.vba
2930
' <--------- keyword.attribute.vba
30-
' ^^^^^^^^^^^^^^ entity.other.attribute-name.vba
31-
' ^ keyword.operator.comparison.vba
31+
' ^^^^^^^^^^^^^^ support.variable.property.vba
32+
' ^ keyword.operator.assignment.vba
3233
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.vba
3334

3435
Attribute VB_GlobalNameSpace = False
3536
' <----------------------------------- meta.attribute.vba
3637
' <--------- keyword.attribute.vba
37-
' ^^^^^^^^^^^^^^^^^^ entity.other.attribute-name.vba
38-
' ^ keyword.operator.comparison.vba
38+
' ^^^^^^^^^^^^^^^^^^ support.variable.property.vba
39+
' ^ keyword.operator.assignment.vba
3940
' ^^^^^ constant.language.boolean.vba
4041

4142
Attribute VB_Creatable = False
4243
' <----------------------------- meta.attribute.vba
4344
' <--------- keyword.attribute.vba
44-
' ^^^^^^^^^^^^ entity.other.attribute-name.vba
45-
' ^ keyword.operator.comparison.vba
45+
' ^^^^^^^^^^^^ support.variable.property.vba
46+
' ^ keyword.operator.assignment.vba
4647
' ^^^^^ constant.language.boolean.vba
4748

4849
Attribute VB_PredeclaredId = False
4950
' <--------------------------------- meta.attribute.vba
5051
' <--------- keyword.attribute.vba
51-
' ^^^^^^^^^^^^^^^^ entity.other.attribute-name.vba
52-
' ^ keyword.operator.comparison.vba
52+
' ^^^^^^^^^^^^^^^^ support.variable.property.vba
53+
' ^ keyword.operator.assignment.vba
5354
' ^^^^^ constant.language.boolean.vba
5455

5556
Attribute VB_Exposed = False
5657
' <--------------------------- meta.attribute.vba
5758
' <--------- keyword.attribute.vba
58-
' ^^^^^^^^^^ entity.other.attribute-name.vba
59-
' ^ keyword.operator.comparison.vba
59+
' ^^^^^^^^^^ support.variable.property.vba
60+
' ^ keyword.operator.assignment.vba
6061
' ^^^^^ constant.language.boolean.vba
6162

6263
Option Explicit

test/textmate/unit/params.vba

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
' SYNTAX TEST "source.vba" "params"
2+
3+
' Parameters passed to method calls.
4+
5+
Sub SubCallTesting()
6+
Foo bar, True, "abc,123", func(123, &H0000) ' Comment
7+
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.sub-call.vba
8+
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.arguments.vba
9+
' ^^^ entity.name.function.call.vba
10+
' ^^^ meta.variable-or-property.vba variable.other.object.vba
11+
' ^ ^ ^ ^ punctuation.separator.vba
12+
' ^^^^ constant.language.boolean.vba
13+
' ^^^^^^^^^ string.quoted.double.vba
14+
' ^^^^^^^^^^^^^^^^^ meta.function.call.vba
15+
' ^^^ constant.numeric.vba
16+
' ^^^^^^ constant.numeric.hex.vba
17+
' ^^^^^^^^ comment.line.apostrophe.vba - meta.sub-call.vba
18+
19+
Foo bar, _
20+
' ^^^^^^^^^^ meta.sub-call.vba
21+
' ^^^ meta.arguments.vba meta.variable-or-property.vba variable.other.object.vba
22+
' ^ meta.arguments.vba punctuation.separator.vba
23+
' ^ meta.arguments.vba keyword.control.line-continuation.vba
24+
True, _
25+
' ^^^^ meta.arguments.vba constant.language.boolean.vba
26+
"abc,123", _
27+
' ^^^^^^^^^ meta.arguments.vba string.quoted.double.vba
28+
' ^ meta.arguments.vba punctuation.separator.vba
29+
' ^ meta.arguments.vba keyword.control.line-continuation.vba
30+
func(123, &H0000)
31+
' ^^^^^^^^^^^^^^^^^ meta.function.call.vba
32+
' ^^^^^^^^^^^ meta.arguments.vba meta.arguments.vba
33+
' ^^^ constant.numeric.vba
34+
' ^ meta.arguments.vba punctuation.separator.vba
35+
' ^^^^^^ constant.numeric.hex.vba
36+
End Sub
37+
38+
Sub FuncCallTesting()
39+
x = Foo(bar, True, "abc,123", Func&(123, &H0000)) ' Comment
40+
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.call.vba
41+
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.arguments.vba
42+
' ^ ^ ^ ^ punctuation.separator.vba
43+
' ^^^ meta.variable-or-property.vba variable.other.object.vba
44+
' ^^^^ constant.language.boolean.vba
45+
' ^^^^^^^^^ string.quoted.double.vba
46+
' ^^^^^^^^^^^^^^^^^^ meta.function.call.vba
47+
' ^^^^ entity.name.function.call.vba
48+
' ^ support.type.primitive.vba
49+
' ^^^ constant.numeric.vba
50+
' ^^^^^^ constant.numeric.hex.vba
51+
' ^^^^^^^^ comment.line.apostrophe.vba - meta.function.call.vba
52+
53+
x = Foo(bar, _
54+
' ^^^ meta.function.call.vba entity.name.function.call.vba
55+
' ^^^ meta.function.call.vba meta.arguments.vba variable.other.object.vba
56+
' ^ meta.function.call.vba meta.arguments.vba punctuation.separator.vba
57+
' ^ meta.function.call.vba meta.arguments.vba keyword.control.line-continuation.vba
58+
True, _
59+
' ^^^^ meta.function.call.vba meta.arguments.vba constant.language.boolean.vba
60+
' ^ meta.function.call.vba meta.arguments.vba punctuation.separator.vba
61+
' ^ meta.function.call.vba meta.arguments.vba keyword.control.line-continuation.vba
62+
"abc,123", _
63+
' ^^^^^^^^^ meta.function.call.vba meta.arguments.vba string.quoted.double.vba
64+
' ^ meta.function.call.vba meta.arguments.vba punctuation.separator.vba
65+
' ^ meta.function.call.vba meta.arguments.vba keyword.control.line-continuation.vba
66+
func&(123, &H0000)) ' Comment
67+
' ^^^^^^^^^^^^^^^^^ meta.function.call.vba meta.arguments.vba meta.function.call.vba
68+
' ^^^^ meta.function.call.vba meta.arguments.vba meta.function.call.vba entity.name.function.call.vba
69+
' ^ meta.function.call.vba meta.arguments.vba meta.function.call.vba support.type.primitive.vba
70+
' ^^^ meta.function.call.vba meta.arguments.vba meta.function.call.vba meta.arguments.vba constant.numeric.vba
71+
' ^ meta.function.call.vba meta.arguments.vba meta.function.call.vba meta.arguments.vba punctuation.separator.vba
72+
' ^^^^^^ meta.function.call.vba meta.arguments.vba meta.function.call.vba meta.arguments.vba constant.numeric.hex.vba
73+
' ^^^^^^^^^ comment.line.apostrophe.vba - meta.function.call.vba
74+
End Sub

0 commit comments

Comments
 (0)