Skip to content

Commit be7e6d7

Browse files
derecksondeathaxe
andauthored
[TCL] Allow shebang detection (#4407)
Co-authored-by: deathaxe <[email protected]>
1 parent 3999862 commit be7e6d7

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

TCL/Tcl.sublime-syntax

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ file_extensions:
99

1010
first_line_match: |-
1111
(?xi:
12-
^ \s* \# .*? -\*- .*? \btcl\b .*? -\*- # editorconfig
12+
^ \#! .* {{shebang_language}}
13+
| ^ \s* \# .*? -\*- .*? \btcl\b .*? -\*- # editorconfig
1314
)
1415
1516
variables:
17+
shebang_language: \b(?:tclsh(?:\d(?:\.\d+)?)?|jimsh)\b
1618
special_chars: '[;{}\[\]"\\]'
1719
unquoted_string: '[^\s{{special_chars}}][^\s${{special_chars}}]*'
1820
end_chars: '[;\n\}\]]'
@@ -22,7 +24,26 @@ variables:
2224

2325
contexts:
2426
main:
25-
- include: commands
27+
- meta_include_prototype: false
28+
- match: ''
29+
push: [commands, shebang]
30+
31+
shebang:
32+
- meta_include_prototype: false
33+
- match: ^\s*(\#!)
34+
captures:
35+
1: punctuation.definition.comment.tcl
36+
set: shebang-body
37+
- match: ^|(?=\S) # Note: Ensure to highlight shebang if tcl is embedded.
38+
pop: true
39+
40+
shebang-body:
41+
- meta_include_prototype: false
42+
- meta_scope: comment.line.shebang.tcl
43+
- match: '{{shebang_language}}'
44+
scope: constant.language.shebang.tcl
45+
- match: $\n?
46+
pop: true
2647

2748
commands:
2849
- match: ^(?=\s*[^\[\{])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! SYNTAX TEST "Tcl.sublime-syntax" jimsh
2+
#!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.shebang.tcl
3+
#! ^^^^^ constant.language.shebang.tcl
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! SYNTAX TEST "Tcl.sublime-syntax" tclsh
2+
#!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.shebang.tcl
3+
#! ^^^^^ constant.language.shebang.tcl
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! SYNTAX TEST "Tcl.sublime-syntax" tclsh8
2+
#!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.shebang.tcl
3+
#! ^^^^^^ constant.language.shebang.tcl
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! SYNTAX TEST "Tcl.sublime-syntax" tclsh8.6
2+
#!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.shebang.tcl
3+
#! ^^^^^^^^ constant.language.shebang.tcl

0 commit comments

Comments
 (0)