Suppose I have code like this:
If (x = 1)
Msgbox, X is 1!
Msgbox, You get this message regardless of what x is.
So the first line has If
and the condition. The second line has the outcome/body of the conditional; on the third line, the conditional is done, and normal code flow continues. What I’d like to do is put a meta scope on this outcome/body line.
So, after the second line, this meta scope should end, and we should return to source
. The problem is that the outcome scope begins and ends at the same regex: ^
(the beginning of a new line). That doesn’t work: either the scope begins and ends immediately, when ^
is the first line within the scope; or it is never triggered, because the other lines within the scope are always triggered first. This is my attempt, which doesn’t work:
if:
- match: '(?i:^\s*(if)\b)'
captures:
1: meta.conditional.ahk keyword.control.conditional.ahk
push:
- meta_content_scope: meta.conditional.condition.ahk
- match: '='
scope: keyword.operator.comparison.ahk
- match: '^' # We are on line 2: the condition has ended, so here the outcome must begin.
set: outcome
outcome:
- meta_content_scope: meta.conditional.outcome.ahk
- include: messagebox
- match: '^' # When the outcome scope encounters a new line, it is finished.
pop: true
messagebox: # This is just an example of the various commands that could be in the outcome, or anywhere else in the main scope.
- match: '(?i:\b(msgbox)\b),?(.*)$'
captures:
1: support.type.builtin.command.ahk
2: string.ahk
When the line that includes messagebox
is above match: '^'
, the outcome never ends; when they are reversed, the outcome scope ends immediately after it begins, covering nothing.
How can I make sure the meta.outcome
scope is applied only to line 2?