Skip to content

Commit

Permalink
Grammar: #If directive highlight (#323)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Wiemer <7833360+mark-wiemer@users.noreply.github.com>
Closes #69
  • Loading branch information
kyklish committed Jan 29, 2023
1 parent f8566da commit f2b0cab
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
11 changes: 10 additions & 1 deletion language/ahk.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ repository:
example: '^c::'
function-call:
patterns:
- captures:
'1':
patterns:
- include: '$self'
'2':
name: comment.line.semicolon.if.ahk
match: '#\b(?i:if)\b(.*?)(\s+;.*)?$'
name: keyword.control.if.ahk
example: '#if [expression]'
- captures:
'1':
name: string.parameter.import.ahk
Expand All @@ -92,7 +101,7 @@ repository:
'2':
name: comment.line.semicolon.directive.ahk
match: >-
#\b(?i:allowsamelinecomments|clipboardtimeout|commentflag|errorstdout|escapechar|hotkeyinterval|hotkeymodifiertimeout|hotstring|if|iftimeout|ifwinactive|ifwinexist|ifwinnotactive|ifwinnotexist|inputlevel|installkeybdhook|installmousehook|keyhistory|ltrim|maxhotkeysperinterval|maxmem|maxthreads|maxthreadsbuffer|maxthreadsperhotkey|menumaskkey|noenv|notrayicon|persistent|requires|singleinstance|usehook|warn|winactivateforce)\b(.*?)(\s+;.*)?$
#\b(?i:allowsamelinecomments|clipboardtimeout|commentflag|errorstdout|escapechar|hotkeyinterval|hotkeymodifiertimeout|hotstring|iftimeout|ifwinactive|ifwinexist|ifwinnotactive|ifwinnotexist|inputlevel|installkeybdhook|installmousehook|keyhistory|ltrim|maxhotkeysperinterval|maxmem|maxthreads|maxthreadsbuffer|maxthreadsperhotkey|menumaskkey|noenv|notrayicon|persistent|requires|singleinstance|usehook|warn|winactivateforce)\b(.*?)(\s+;.*)?$
name: keyword.control.directives.ahk
example: '#persistent'
- match: >-
Expand Down
2 changes: 2 additions & 0 deletions src/test/suite/grammar/samples/69-if-directive.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
; [Issue #69](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/69)
#If WinActive("ahk_class Notepad") or WinActive(MyWindowTitle) ;Comment
21 changes: 21 additions & 0 deletions src/test/suite/grammar/samples/69-if-directive.ahk.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
>; [Issue #69](https://github.com/mark-wiemer/vscode-autohotkey-plus-plus/issues/69)
#^ source.ahk comment.line.semicolon.ahk punctuation.definition.comment.ahk
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ahk comment.line.semicolon.ahk
>#If WinActive("ahk_class Notepad") or WinActive(MyWindowTitle) ;Comment
#^^^ source.ahk keyword.control.if.ahk
# ^ source.ahk keyword.control.if.ahk
# ^^^^^^^^^ source.ahk keyword.control.if.ahk support.function.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
# ^ source.ahk keyword.control.if.ahk string.quoted.double.ahk punctuation.definition.string.begin.ahk
# ^^^^^^^^^^^^^^^^^ source.ahk keyword.control.if.ahk string.quoted.double.ahk
# ^ source.ahk keyword.control.if.ahk string.quoted.double.ahk punctuation.definition.string.end.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
# ^ source.ahk keyword.control.if.ahk
# ^^ source.ahk keyword.control.if.ahk keyword.other.ahk
# ^ source.ahk keyword.control.if.ahk
# ^^^^^^^^^ source.ahk keyword.control.if.ahk support.function.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
# ^^^^^^^^^^^^^ source.ahk keyword.control.if.ahk variable.def.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
# ^^^^^^^^^ source.ahk keyword.control.if.ahk comment.line.semicolon.if.ahk
>
36 changes: 26 additions & 10 deletions src/test/suite/grammar/samples/ahk-explorer.ahk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ahk keyword.control.directives.ahk comment.line.semicolon.directive.ahk
>#SingleInstance, force
#^^^^^^^^^^^^^^^ source.ahk keyword.control.directives.ahk
# ^^^^^^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
# ^^^^^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
>SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#^^^^^^^^ source.ahk support.function.ahk
# ^ source.ahk
Expand All @@ -38,7 +38,7 @@
# ^ source.ahk constant.numeric.ahk
>#KeyHistory 0
#^^^^^^^^^^^ source.ahk keyword.control.directives.ahk
# ^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
# ^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
>ListLines Off
#^^^^^^^^^ source.ahk support.function.ahk
# ^ source.ahk
Expand All @@ -59,10 +59,10 @@
>
>#MaxThreads, 20
#^^^^^^^^^^^ source.ahk keyword.control.directives.ahk
# ^^^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
# ^^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
>#MaxThreadsPerHotkey, 4
#^^^^^^^^^^^^^^^^^^^^ source.ahk keyword.control.directives.ahk
# ^^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
# ^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
>SetTitleMatchMode, 2
#^^^^^^^^^^^^^^^^^ source.ahk support.function.ahk
# ^ source.ahk punctuation.ahk
Expand Down Expand Up @@ -24348,8 +24348,12 @@
#^ source.ahk comment.line.semicolon.ahk punctuation.definition.comment.ahk
# ^^^^^^^ source.ahk comment.line.semicolon.ahk
>#if winactive(thisUniqueWintitle)
#^^^ source.ahk keyword.control.directives.ahk
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
#^^^ source.ahk keyword.control.if.ahk
# ^ source.ahk keyword.control.if.ahk
# ^^^^^^^^^ source.ahk keyword.control.if.ahk support.function.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
# ^^^^^^^^^^^^^^^^^^ source.ahk keyword.control.if.ahk variable.def.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
>^e::
#^^ source.ahk hotkeyline.ahk entity.name.function.label.ahk
# ^^ source.ahk hotkeyline.ahk punctuation.definition.equals.colon
Expand Down Expand Up @@ -27822,8 +27826,14 @@
#^^^^^^ source.ahk keyword.control.ahk
>
>#if winactive("renamingWinTitle ahk_class AutoHotkeyGUI")
#^^^ source.ahk keyword.control.directives.ahk
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
#^^^ source.ahk keyword.control.if.ahk
# ^ source.ahk keyword.control.if.ahk
# ^^^^^^^^^ source.ahk keyword.control.if.ahk support.function.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
# ^ source.ahk keyword.control.if.ahk string.quoted.double.ahk punctuation.definition.string.begin.ahk
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ahk keyword.control.if.ahk string.quoted.double.ahk
# ^ source.ahk keyword.control.if.ahk string.quoted.double.ahk punctuation.definition.string.end.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
>
>$esc::
#^^^^ source.ahk hotkeyline.ahk entity.name.function.label.ahk
Expand Down Expand Up @@ -27910,8 +27920,14 @@
#^^^^^^ source.ahk keyword.control.ahk
>
>#if winactive("create_folder ahk_class AutoHotkeyGUI")
#^^^ source.ahk keyword.control.directives.ahk
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ahk keyword.control.directives.ahk string.parameter.directives.ahk
#^^^ source.ahk keyword.control.if.ahk
# ^ source.ahk keyword.control.if.ahk
# ^^^^^^^^^ source.ahk keyword.control.if.ahk support.function.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
# ^ source.ahk keyword.control.if.ahk string.quoted.double.ahk punctuation.definition.string.begin.ahk
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ahk keyword.control.if.ahk string.quoted.double.ahk
# ^ source.ahk keyword.control.if.ahk string.quoted.double.ahk punctuation.definition.string.end.ahk
# ^ source.ahk keyword.control.if.ahk punctuation.bracket.ahk
>
>$enter::
#^^^^^^ source.ahk hotkeyline.ahk entity.name.function.label.ahk
Expand Down

0 comments on commit f2b0cab

Please sign in to comment.