X Tutup
Skip to content

Commit 98ddba3

Browse files
committed
vendor modules with updated require, simplify error handling when loading
1 parent b735517 commit 98ddba3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+163
-167
lines changed

syntaxhighlight/init.lua

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
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
1+
local load_lexer
2+
load_lexer = function()
3+
local lexer_mod = require("syntaxhighlight.textadept.lexer")
4+
local parts
5+
do
6+
local _accum_0 = { }
7+
local _len_0 = 1
8+
for part in lexer_mod.path:gmatch('[^;]+') do
9+
_accum_0[_len_0] = part:gsub("%?%.lua", "syntaxhighlight/textadept/?.lua")
10+
_len_0 = _len_0 + 1
11+
end
12+
parts = _accum_0
913
end
10-
parts = _accum_0
14+
lexer_mod.path = table.concat(parts, ";")
15+
return lexer_mod
1116
end
12-
lexer_mod.path = table.concat(parts, ";")
17+
local lexer_mod
1318
local lexers = setmetatable({ }, {
1419
__index = function(self, name)
15-
local prev_mod = package.loaded.lexer
20+
if not (lexer_mod) then
21+
lexer_mod = load_lexer()
22+
end
1623
local source_path = package.searchpath(name, lexer_mod.path)
1724
local mod
18-
local success
1925
if source_path then
20-
package.loaded.lexer = lexer_mod
2126
mod = require("syntaxhighlight.textadept." .. tostring(name))
22-
package.loaded.lexer = prev_mod
23-
success = true
24-
else
25-
success = false
26-
end
27-
if success then
28-
self[name] = mod
29-
return self[name]
3027
else
31-
self[name] = false
32-
return false
28+
mod = false
3329
end
30+
self[name] = mod
31+
return self[name]
3432
end
3533
})
3634
local tag_tokens

syntaxhighlight/init.moon

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
lexer_mod = require "syntaxhighlight.textadept.lexer"
1+
load_lexer = ->
2+
lexer_mod = require "syntaxhighlight.textadept.lexer"
23

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"
4+
-- setup the path so including sub-grammars looks at right place
5+
parts = for part in lexer_mod.path\gmatch '[^;]+'
6+
part\gsub "%?%.lua", "syntaxhighlight/textadept/?.lua"
67

7-
lexer_mod.path = table.concat parts, ";"
8+
lexer_mod.path = table.concat parts, ";"
9+
10+
lexer_mod
11+
12+
13+
local lexer_mod
814

915
lexers = setmetatable {}, {
1016
__index: (name) =>
11-
prev_mod = package.loaded.lexer
17+
unless lexer_mod
18+
lexer_mod = load_lexer!
1219

1320
-- see if the module exists
1421
-- package.searchpath is defined in lexer.lua for lua 5.1
1522
source_path = package.searchpath name, lexer_mod.path
1623

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+
mod = if source_path
25+
require("syntaxhighlight.textadept.#{name}")
2426
else
2527
false
2628

27-
if success
28-
@[name] = mod
29-
@[name]
30-
else
31-
@[name] = false
32-
false
29+
@[name] = mod
30+
@[name]
3331
}
3432

3533
tag_tokens = (source, tokens) ->

syntaxhighlight/textadept/actionscript.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Copyright 2006-2019 Mitchell mitchell.att.foicica.com. See License.txt.
22
-- Actionscript LPeg lexer.
33

4-
local lexer = require('lexer')
4+
local lexer = require('syntaxhighlight.textadept.lexer')
55
local token, word_match = lexer.token, lexer.word_match
66
local P, R, S = lpeg.P, lpeg.R, lpeg.S
77

syntaxhighlight/textadept/ada.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Copyright 2006-2019 Mitchell mitchell.att.foicica.com. See License.txt.
22
-- Ada LPeg lexer.
33

4-
local lexer = require('lexer')
4+
local lexer = require('syntaxhighlight.textadept.lexer')
55
local token, word_match = lexer.token, lexer.word_match
66
local P, R, S = lpeg.P, lpeg.R, lpeg.S
77

syntaxhighlight/textadept/ansi_c.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Copyright 2006-2019 Mitchell mitchell.att.foicica.com. See License.txt.
22
-- C LPeg lexer.
33

4-
local lexer = require('lexer')
4+
local lexer = require('syntaxhighlight.textadept.lexer')
55
local token, word_match = lexer.token, lexer.word_match
66
local P, R, S = lpeg.P, lpeg.R, lpeg.S
77

syntaxhighlight/textadept/antlr.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Copyright 2006-2019 Mitchell mitchell.att.foicica.com. See License.txt.
22
-- ANTLR LPeg lexer.
33

4-
local lexer = require('lexer')
4+
local lexer = require('syntaxhighlight.textadept.lexer')
55
local token, word_match = lexer.token, lexer.word_match
66
local P, R, S = lpeg.P, lpeg.R, lpeg.S
77

syntaxhighlight/textadept/apdl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Copyright 2006-2019 Mitchell mitchell.att.foicica.com. See License.txt.
22
-- APDL LPeg lexer.
33

4-
local lexer = require('lexer')
4+
local lexer = require('syntaxhighlight.textadept.lexer')
55
local token, word_match = lexer.token, lexer.word_match
66
local P, R, S = lpeg.P, lpeg.R, lpeg.S
77

syntaxhighlight/textadept/apl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Copyright 2015-2019 David B. Lamkins <david@lamkins.net>. See License.txt.
22
-- APL LPeg lexer.
33

4-
local lexer = require('lexer')
4+
local lexer = require('syntaxhighlight.textadept.lexer')
55
local token, word_match = lexer.token, lexer.word_match
66
local P, R, S = lpeg.P, lpeg.R, lpeg.S
77

syntaxhighlight/textadept/applescript.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Copyright 2006-2019 Mitchell mitchell.att.foicica.com. See License.txt.
22
-- Applescript LPeg lexer.
33

4-
local lexer = require('lexer')
4+
local lexer = require('syntaxhighlight.textadept.lexer')
55
local token, word_match = lexer.token, lexer.word_match
66
local P, R, S = lpeg.P, lpeg.R, lpeg.S
77

syntaxhighlight/textadept/asm.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Copyright 2006-2019 Mitchell mitchell.att.foicica.com. See License.txt.
22
-- NASM Assembly LPeg lexer.
33

4-
local lexer = require('lexer')
4+
local lexer = require('syntaxhighlight.textadept.lexer')
55
local token, word_match = lexer.token, lexer.word_match
66
local P, R, S = lpeg.P, lpeg.R, lpeg.S
77

0 commit comments

Comments
 (0)
X Tutup