Skip to content

Commit ba95d7b

Browse files
committed
Require terminator before function definition
The current grammar assumes it found a function whenever it encounters the keyword `function` followed by any word, which is too aggressive and can lead to false positives. This change requires that the function definition is preceded by a terminator (`^|;|&`) and (optional) whitespace. This approach can still produce false positives (it doesn’t recognise when the line break was escaped, for example) but should work well enough. It also now includes the preceding whitespace in the `meta.function.shell` scope (due to the limitations on variable-width look-behinds), which I don’t like but also don’t see a way around. We might want to consider doing something similar for loop constructs. Closes #36
1 parent ed8de7e commit ba95d7b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Syntaxes/Shell-Unix-Bash.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
<array>
337337
<dict>
338338
<key>begin</key>
339-
<string>(?&lt;=^|;|&amp;|\s)(function)\s+([^\s&lt;&gt;;'"\\|$&amp;()]+)(?:\s*(\(\)))?</string>
339+
<string>(?&lt;=^|;|&amp;)\s*(function)\s+([^\s&lt;&gt;;'"\\|$&amp;()]+)(?:\s*(\(\)))?</string>
340340
<key>beginCaptures</key>
341341
<dict>
342342
<key>1</key>
@@ -377,7 +377,7 @@
377377
</dict>
378378
<dict>
379379
<key>begin</key>
380-
<string>(?&lt;=^|;|&amp;|\s)([^\s&lt;&gt;;'"\\|$&amp;()]+)\s*(\(\))</string>
380+
<string>(?&lt;=^|;|&amp;)\s*([^\s&lt;&gt;;'"\\|$&amp;()]+)\s*(\(\))</string>
381381
<key>beginCaptures</key>
382382
<dict>
383383
<key>1</key>

0 commit comments

Comments
 (0)