X Tutup
Skip to content

Commit 60efd73

Browse files
committed
use lexer_mod.path to check for lexers, update path to support sub lexers
1 parent d712b1c commit 60efd73

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

syntaxhighlight/init.lua

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
local lexer_mod
1+
local lexer_mod = require("syntaxhighlight.textadept.lexer")
2+
local parts
3+
do
4+
local _accum_0 = { }
5+
local _len_0 = 1
6+
for part in lexer_mod.path:gmatch('[^;]+') do
7+
_accum_0[_len_0] = part:gsub("%?%.lua", "syntaxhighlight/textadept/?.lua")
8+
_len_0 = _len_0 + 1
9+
end
10+
parts = _accum_0
11+
end
12+
lexer_mod.path = table.concat(parts, ";")
213
local lexers = setmetatable({ }, {
314
__index = function(self, name)
415
local prev_mod = package.loaded.lexer
5-
if not (lexer_mod) then
6-
lexer_mod = require("syntaxhighlight.textadept.lexer")
16+
local source_path = package.searchpath(name, lexer_mod.path)
17+
local mod
18+
local success
19+
if source_path then
20+
package.loaded.lexer = lexer_mod
21+
mod = require("syntaxhighlight.textadept." .. tostring(name))
22+
package.loaded.lexer = prev_mod
23+
success = true
24+
else
25+
success = false
726
end
8-
package.loaded.lexer = lexer_mod
9-
local success, mod = pcall(function()
10-
return require("syntaxhighlight.textadept." .. tostring(name))
11-
end)
12-
package.loaded.lexer = prev_mod
1327
if success then
1428
self[name] = mod
1529
return self[name]

syntaxhighlight/init.moon

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
local lexer_mod
2-
1+
lexer_mod = require "syntaxhighlight.textadept.lexer"
2+
3+
-- setup the path so including sub-grammars looks at right place
4+
parts = for part in lexer_mod.path\gmatch '[^;]+'
5+
part\gsub "%?%.lua", "syntaxhighlight/textadept/?.lua"
6+
7+
lexer_mod.path = table.concat parts, ";"
8+
39
lexers = setmetatable {}, {
410
__index: (name) =>
511
prev_mod = package.loaded.lexer
6-
unless lexer_mod
7-
lexer_mod = require "syntaxhighlight.textadept.lexer"
812

9-
package.loaded.lexer = lexer_mod
10-
success, mod = pcall ->
11-
require("syntaxhighlight.textadept.#{name}")
12-
package.loaded.lexer = prev_mod
13+
-- see if the module exists
14+
-- package.searchpath is defined in lexer.lua for lua 5.1
15+
source_path = package.searchpath name, lexer_mod.path
16+
17+
local mod
18+
19+
success = if source_path
20+
package.loaded.lexer = lexer_mod
21+
mod = require("syntaxhighlight.textadept.#{name}")
22+
package.loaded.lexer = prev_mod
23+
true
24+
else
25+
false
1326

1427
if success
1528
@[name] = mod

0 commit comments

Comments
 (0)
X Tutup