diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Find a script's lexer from its shebang line
Scintillua's detect reads the first line as well as the name, and
without it hooks, bin scripts and anything else lacking an extension
stayed plain.
Diffstat (limited to 'tests/extensions/fake-lexers/lexer.lua')
| -rw-r--r-- | tests/extensions/fake-lexers/lexer.lua | 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 7 insertions, 4 deletions
diff --git a/tests/extensions/fake-lexers/lexer.lua b/tests/extensions/fake-lexers/lexer.lua index adf7d5b..0632744 100644 --- a/tests/extensions/fake-lexers/lexer.lua +++ b/tests/extensions/fake-lexers/lexer.lua @@ -1,9 +1,9 @@ -- A miniature stand-in for the Scintillua lexer module, just enough for the -- syntax-highlight checks to drive every path through the filter without the -- real collection installed. load() hands out one of the toy lexers below by --- name and detect() recognises a single filename suffix, so a check can tell --- the detection path apart from the extension path by which lexer ends up --- running. Anything the filter treats as optional, a lexer that will not +-- name and detect() recognises a single filename suffix or a shebang naming +-- fake, so a check can tell the detection path apart from the extension path +-- by which lexer ends up running. Anything the filter treats as optional, a lexer that will not -- load or one that raises while lexing, has a name here too. local M = {} @@ -67,10 +67,13 @@ function M.load(name) return lexer end -function M.detect(filename) +function M.detect(filename, line) if filename:match("%.viadetect$") then return "fake" end + if line ~= nil and line:match("^#!.*fake") then + return "fake" + end return nil end |
