Skip to content

Commit 280b5f2

Browse files
authored
Merge pull request #10 from SSlinky/dev
Overhaul Parser
2 parents 92e2cbf + f7d7bff commit 280b5f2

File tree

21 files changed

+3914
-1613
lines changed

21 files changed

+3914
-1613
lines changed

client/src/syntaxes/vba.tmLanguage.yaml

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ patterns:
1111
repository:
1212
fileStructure:
1313
patterns:
14+
- include: "#moduleHeader"
1415
- include: "#comments" # Handle comments here so they aren't broken by other stuff.
1516
- include: "#strings" # Handle strings here so they aren't broken by other stuff.
1617
- include: "#labels" # Handle labels first so they aren't handled by lines.
18+
- include: "#inlineMethod" # Try not to be too sad people can, and do, do this.
1719
- include: "#methodSignature"
1820
- include: "#continuations" # Consume continuations so they "continue" other matches.
1921
- include: "#enum"
@@ -52,7 +54,6 @@ repository:
5254

5355
main:
5456
patterns:
55-
- include: "#moduleHeader"
5657
- include: "#declareFunctionSignature"
5758
- include: "#methodSignature"
5859
- include: "#variableDeclarations"
@@ -68,8 +69,8 @@ repository:
6869
- include: "#operators"
6970
- include: "#keywords"
7071
- include: "#functionCall"
71-
- include: "#subCall"
7272
- include: "#objectModel"
73+
- include: "#subCall"
7374

7475

7576
literals:
@@ -82,7 +83,7 @@ repository:
8283
repository:
8384
string:
8485
name: string.quoted.double.vba
85-
match: '"[^\r\n]*"'
86+
match: '"("")*([^"\n]*)((?:"")[^"\n]+)?"("")*'
8687
boolean:
8788
name: constant.language.boolean.vba
8889
match: "(?i)(true|false)"
@@ -151,11 +152,11 @@ repository:
151152
repository:
152153
flowDecision:
153154
name: keyword.control.flow.decision.vba
154-
match: (?i)(^|\s+)(#if|then|#elseif|[#]?else|#end if|select case|case|switch|end select)\b
155+
match: (?i)(^|\s+)(#if|then|#elseif|[#]?else|[#]?end if|select case|case|switch|end select)\b
155156

156157
flowLoop:
157158
name: keyword.control.flow.loop.vba
158-
match: (?i)\b(do|exit\s+do|while|until|loop|for|each|in|to|exit\s+for|next|with)\b
159+
match: (?i)\b(do|exit\s+do|while|wend|until|loop|for|each|in|to|exit\s+for|next|with)\b
159160

160161
forEachLoop:
161162
name: meta.flow.foreach.vba
@@ -352,10 +353,10 @@ repository:
352353
repository:
353354
primativeType:
354355
name: support.type.primitive.vba
355-
match: (?i)(?<=\bAs)\s+(boolean|byte|currency|date|decimal|double|integer|long(long|ptr)?|single|string|variant)\b
356+
match: (?i)(?<=\bAs)(?:\s+|\s+_\s*\n)+(boolean|byte|currency|date|decimal|double|integer|long(long|ptr)?|single|string|variant)\b
356357
objectType:
357358
name: support.type.object.vba
358-
match: (?i)(?<=\bAs)(\s+New)?\s+([A-Z][A-Z0-9_]*)\b
359+
match: (?i)(?<=\bAs)((?:\s+(?:\s*_\s*\n)*)New)?(?:\s+(?:\s*_\s*\n)*)([A-Z][A-Z0-9_]*)\b
359360
captures:
360361
1:
361362
name: keyword.storage.new.vba
@@ -371,22 +372,24 @@ repository:
371372
- include: "#paramArray"
372373
- include: "#functionCall"
373374
- include: "#argsVariable"
374-
- include: "#argsLiteral"
375375
- include: "#language"
376+
- include: "#argsLiteral"
376377
repository:
377378
argsVariable:
378-
match: (?i),?\s*(Optional\s+)?((?:ByVal|ByRef)\s+)?([a-z][a-z0-9_]*)(?:\s*(\bas\s+[a-z][a-z0-9_]*))?\b(\s+=\s+[^,)]*)?
379+
name: meta.arguments.argsVariable.vba
380+
match: (?i),?\s*((?:Optional\s+)?(?:(?:ByVal|ByRef)\s+)?)?([a-z][a-z0-9_]*)(?:\s+(as\s+[a-z][a-z0-9_]*))?(\s*=\s*[^,)]+)?
381+
# Attempted replacing \s with (?:\s+|\s*_\s*\n) to consume a space or a line ending but it refuses to play the game.
382+
# 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)]+)?
383+
# 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)*[^,)]+)?
379384
captures:
380-
1:
385+
1: # Optional? ByVal|ByRef?
381386
name: storage.type.modifier.vba
382-
2:
383-
name: storage.type.modifier.vba
384-
3:
387+
2: # Identifier
385388
name: variable.parameter.vba
386-
4:
389+
3: # As Type?
387390
patterns:
388391
- include: "#types"
389-
5:
392+
4:
390393
patterns:
391394
- include: "#language"
392395

@@ -399,6 +402,7 @@ repository:
399402
- include: "#literals"
400403

401404
paramArray:
405+
name: meta.args.paramarray.vba
402406
match: (?i),?\s*(ParamArray)\s+([a-z][a-z0-9_]*)(?:\(\))(\s+As\s+Variant)?
403407
captures:
404408
1:
@@ -431,10 +435,12 @@ repository:
431435
match: (?i)(?<=^|:)\s*Rem\b.*
432436

433437
attribute:
434-
name: entity.other.attribute-name.vba
435-
match: (?i)^Attribute(.*)
438+
name: meta.attribute.vba
439+
match: (?i)^\s*(Attribute VB_\w+)\s+(.*)$
436440
captures:
437-
0:
441+
1:
442+
name: entity.other.attribute-name.vba
443+
2:
438444
patterns:
439445
- include: "#language"
440446

@@ -450,7 +456,7 @@ repository:
450456
moduleAttributeBlock:
451457
name: entity.other.attribute-name.block.vba
452458
begin: (?i)^VERSION
453-
end: ^(?i)End
459+
end: (?i)^END
454460
patterns:
455461
- include: "#comments"
456462
- include: "#literals"
@@ -566,10 +572,32 @@ repository:
566572
patterns:
567573
- include: "#arguments"
568574

575+
inlineMethod:
576+
name: source.inline-method.please-dont.vba
577+
match: (?i)^\s*((?:Public|Private)?\b\s*(?:(?:Sub|Function)|Property\s+(?:Let|Get|Set)))\s+([a-z][a-z0-9_]*)\s*\((.+)?\)(\s+as\s+[a-z][a-z0-9_]*)?:(.*)?:\s*(End\s+(?:Sub|Function|Property))
578+
captures:
579+
1: # Method type
580+
name: storage.type.method.vba
581+
2: # Identifier
582+
name: entity.name.function.vba
583+
3: # Arguments?
584+
patterns:
585+
- include: "#arguments"
586+
4: # Return type?
587+
patterns:
588+
- include: "#types"
589+
5: # Method lines
590+
patterns:
591+
- include: "#fileStructure"
592+
6: # End method
593+
name: storage.type.method.close.vba
594+
595+
596+
569597
methodSignature:
570598
name: source.method.signature.vba
571-
begin: '(?i)^\s*((?:Public|Private)?\b\s*(?:(?:Sub|Function)|Property\s+(?:Let|Get|Set)))\s+([a-z][a-z0-9_]*)\s*(\()'
572-
end: '(?i)(\))\s+(as\s+[a-z][a-z0-9_]*)?'
599+
begin: (?i)^\s*((?:Public|Private)?\b\s*(?:(?:Sub|Function)|Property\s+(?:Let|Get|Set)))\s+([a-z][a-z0-9_]*)\s*(\()
600+
end: (?i)\s*(\))\s+(as\s+[a-z][a-z0-9_]*)?
573601
beginCaptures:
574602
1:
575603
name: storage.type.method.vba
@@ -591,17 +619,18 @@ repository:
591619
match: (?i)^\s*End\s+(Sub|Function|Property)
592620

593621
expression:
594-
# (?:[*&/\+-]|\bMod\b)|
622+
# (?:[*&\/\+-]|\bMod\b)|
595623
# (?:[<>=]|\b(is|like)\b)|
596624
# (?:[&+])|
597625
# (?:\b(and|eqv|imp|not|or|xor)\b)|
598626
# (?:\b(addressof|typeof)\b)
599627

600628
# This match just made up of the operators matchs. Don't look at it too hard.
601-
match: (?i)(.*?)\s+((?:[*&/\+-]|\bMod\b)|(?:[<>=]|\b(is|like)\b)|(?:[&+])|(?:\b(and|eqv|imp|not|or|xor)\b)|(?:\b(addressof|typeof)\b))\s+(.*)
629+
match: (?i)(.*?)\s+((?:[*&\/\+-]|\bMod\b)|(?:[<>=]|\b(is|like)\b)|(?:[&+])|(?:\b(and|eqv|imp|not|or|xor)\b)|(?:\b(addressof|typeof)\b))\s+(.*)
602630
captures:
603631
1: # Left sided of expression
604632
patterns:
633+
- include: "#functionCall"
605634
- include: "#literal"
606635
2: # Operator
607636
patterns:
@@ -709,7 +738,8 @@ repository:
709738
- include: "#lineContinuation"
710739

711740
subCall:
712-
begin: (?i)([a-z][a-z0-9._]*)\s+(.*,.*)
741+
name: meta.sub-call.vba
742+
begin: (?i)([a-z][a-z0-9._]*)\s+(.*)
713743
beginCaptures:
714744
1:
715745
name: entity.name.function.call.vba

0 commit comments

Comments
 (0)