@@ -17,6 +17,7 @@ repository:
1717 - include : " #methodSignature"
1818 - include : " #continuations" # Consume continuations so they "continue" other matches.
1919 - include : " #enum"
20+ - include : " #struct"
2021 - include : " #syntaxLines" # Split document lines into syntax lines.
2122
2223 continuations :
@@ -40,16 +41,18 @@ repository:
4041
4142 syntaxLines :
4243 name : meta.syntax-lines.vba
43- match : ((?:[^\n":]|"(?:\\.|[^\n"\\])*")+|"(?:\\.|[^\n"\\])*")
44+ match : ((?:[^\n"' :]|"(?:\\.|[^\n"\\])*")+|"(?:\\.|[^\n"\\])*")(?:('.*)*)?
4445 captures :
4546 1 : # Split line
4647 patterns :
4748 - include : " #main"
49+ 2 : # Comments
50+ patterns :
51+ - include : " #comments"
4852
4953 main :
5054 patterns :
5155 - include : " #moduleHeader"
52- - include : " #struct"
5356 - include : " #declareFunctionSignature"
5457 - include : " #methodSignature"
5558 - include : " #variableDeclarations"
@@ -148,12 +151,11 @@ repository:
148151 repository :
149152 flowDecision :
150153 name : keyword.control.flow.decision.vba
151- match : ' (?i)(^|\s+)(#if|then|#elseif|#else|#end if|select case|case|switch|end select)\b'
152- # match: '(?i)(^|\s+)([#]?if|then|[#]?elseif|[#]?else|[#]?end if|select case|case|switch|end select)\b'
154+ match : (?i)(^|\s+)(#if|then|#elseif|[#]?else|#end if|select case|case|switch|end select)\b
153155
154156 flowLoop :
155157 name : keyword.control.flow.loop.vba
156- match : " (?i)\\ b(do|exit\\ s+do|while|until|loop|for|each|in|to|exit\\ s+for|next|with)\\ b "
158+ match : (?i)\b(do|exit\s+do|while|until|loop|for|each|in|to|exit\s+for|next|with)\b
157159
158160 forEachLoop :
159161 name : meta.flow.foreach.vba
@@ -170,7 +172,7 @@ repository:
170172
171173 inlineIfElse :
172174 name : meta.flow.inline-if-else.vba
173- match : (?i)\b( if)\s+(.*?)\s+(then)\s+(.*)\s+(else)\s+(. *)
175+ match : (?i)\s*((?:else)? if)\s+(.*?)\s+(then)\s+(.*)\s+(else)\s+([^'\n] *)
174176 captures :
175177 1 :
176178 name : keyword.control.flow.decision.vba
@@ -193,7 +195,7 @@ repository:
193195
194196 inlineIf :
195197 name : meta.flow.inline-if.vba
196- match : (?i)\b( if)\s+(.*?)\s+(then)
198+ match : (?i)\s*((?:else)? if)\s+(.*?)\s+(then)
197199 captures :
198200 1 :
199201 name : keyword.control.flow.decision.vba
@@ -417,13 +419,13 @@ repository:
417419 # The sub-pattern consumes the \n if preceded by line continuation.
418420 # Capturing it there prevents the end pattern being matched.
419421 name : comment.block.vba
420- begin : (?i)'.*\s_\s*
422+ begin : (?i)\s* '.*\s_\s*
421423 end : \n
422424 patterns :
423425 - include : " #lineContinuation"
424426 apostropheComments :
425- name : comment.line.apostrophe .vba
426- match : (?i)'.*
427+ name : comment.line.apostropheXX .vba
428+ match : (?i)\s* '.*
427429 remarkComments :
428430 name : comment.line.remark.vba
429431 match : (?i)(?<=^|:)\s*Rem\b.*
@@ -459,7 +461,7 @@ repository:
459461
460462 enum :
461463 name : meta.enum.declaration.vba
462- begin : (?i)^\s*((?:(?:Public|Private)\s+)?\s*Enum)\s+([a-z][a-z0-9_]+)(\s+(?:'|Rem).*)
464+ begin : (?i)^\s*((?:(?:Public|Private)\s+)?\s*Enum)\s+([a-z][a-z0-9_]+)(\s+(?:'|Rem).*)?
463465 beginCaptures :
464466 1 :
465467 name : storage.type.enum.vba
@@ -471,13 +473,17 @@ repository:
471473 patterns :
472474 - include : " #comment"
473475 - include : " #enumMember"
474- end : (?i)^\s*End\s+Enum\b
476+ - include : " #language"
477+ end : (?i)^\s*(End\s+Enum)(\s+'.*)?
475478 endCaptures :
476- 0 :
479+ 1 :
477480 name : storage.type.enum.vba
481+ 2 :
482+ patterns :
483+ - include : " #comments"
478484
479485 enumMember :
480- match : (?i)^\s*([a-z][a-z0-9_]*)(?:\s+(=)\s+([^\n']*)\s+)?(' .*)?$
486+ match : (?i)^\s*([a-z][a-z0-9_]*)(?:\s+(=)\s+([^\n']*))?( \s+(?:'|Rem) .*)?
481487 captures :
482488 1 :
483489 name : constant.numeric.enum.vba
@@ -493,34 +499,42 @@ repository:
493499
494500 struct :
495501 name : meta.struct.declaration.vba
496- begin : " (?i)^\\ s*((?:(?:Public|Private) )? \\ s* Type)\\ s+([a-z][a-z0-9_]*)"
502+ begin : (?i)^\s*((?:(?:Public|Private)\s+)? Type)\s+([a-z][a-z0-9_]*)?(\s+(?:'|Rem).*)?
497503 beginCaptures :
498- 1 :
504+ 1 : # Type declaration
499505 name : storage.type.struct.vba
500- 2 :
506+ 2 : # Type name
501507 name : entity.name.type.struct.vba
508+ 3 : # Comments?
509+ patterns :
510+ - include : " #comments"
502511 patterns :
512+ - include : " #comment"
503513 - include : " #structProperty"
514+ - include : " #language"
504515
505- end : " (?i)^\\ s* End\\ s+Type\\ b "
516+ end : (?i)^\s*( End\s+Type)(\s+'.*)?
506517 endCaptures :
507- 0 :
518+ 1 :
508519 name : storage.type.struct.vba
520+ 2 :
521+ patterns :
522+ - include : " #comments"
509523
510524 structProperty :
511- match : " (?i)^\\ s*([a-z][a-z0-9_]*)(\\ (.*\\ ))?(\\ s+As\\ s+[a-z][a-z0-9_]*)?"
525+ match : (?i)^\s*([a-z][a-z0-9_]*)(\(.*\))?(\s+As\s+[a-z][a-z0-9_]*)?(\s+(?:'|Rem).*)?
512526 captures :
513- 1 :
514- # Property
527+ 1 : # Property
515528 name : variable.other.readwrite.vba
516- 2 :
517- # Array bounds?
529+ 2 : # Array bounds?
518530 patterns :
519531 - include : " #language"
520- 3 :
521- # As Type
532+ 3 : # As Type?
522533 patterns :
523534 - include : " #types"
535+ 4 : # Comments?
536+ patterns :
537+ - include : " #comments"
524538
525539 declareFunctionSignature :
526540 name : source.declare.signature.vba
0 commit comments