-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Promote Lua input detection to first class
- Loading branch information
Showing
5 changed files
with
79 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local base = require("inputters.base") | ||
|
||
local lua = pl.class(base) | ||
lua._name = "lua" | ||
|
||
lua.order = 99 | ||
|
||
function lua.appropriate (round, filename, doc) | ||
if round == 1 then | ||
return filename:match("lua$") | ||
elseif round == 2 then | ||
local sniff = doc:sub(1, 100) | ||
return sniff:match("^--") or sniff:match("^local") or sniff:match("^return") | ||
elseif round == 3 then | ||
local _, err = pcall(function () assert(load(doc)) end) | ||
return not err | ||
end | ||
end | ||
|
||
function lua:process (doc) | ||
local root = SILE.documentState.documentClass == nil | ||
local tree = load(doc)() | ||
if root then self:classInit(tree) end | ||
end | ||
|
||
return lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters