Skip to content

Commit

Permalink
feat: Move pandoc builtins to their own module and split filters, rea…
Browse files Browse the repository at this point in the history
…ders, and writers
  • Loading branch information
alerque committed Aug 28, 2024
1 parent edd9456 commit 25021e0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
1 change: 1 addition & 0 deletions luacheck-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ build = {
["luacheck.builtin_standards"] = "src/luacheck/builtin_standards/init.lua",
["luacheck.builtin_standards.love"] = "src/luacheck/builtin_standards/love.lua",
["luacheck.builtin_standards.minetest"] = "src/luacheck/builtin_standards/minetest.lua",
["luacheck.builtin_standards.pandoc"] = "src/luacheck/builtin_standards/pandoc.lua",
["luacheck.builtin_standards.playdate"] = "src/luacheck/builtin_standards/playdate.lua",
["luacheck.builtin_standards.ngx"] = "src/luacheck/builtin_standards/ngx.lua",
["luacheck.cache"] = "src/luacheck/cache.lua",
Expand Down
24 changes: 5 additions & 19 deletions src/luacheck/builtin_standards/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local love = require "luacheck.builtin_standards.love"
local minetest = require "luacheck.builtin_standards.minetest"
local pandoc = require "luacheck.builtin_standards.pandoc"
local playdate = require "luacheck.builtin_standards.playdate"
local ngx = require "luacheck.builtin_standards.ngx"
local standards = require "luacheck.standards"
Expand Down Expand Up @@ -344,25 +345,10 @@ builtin_standards.sile = {
}
}

-- https://pandoc.org/lua-filters.html#global-variables
builtin_standards.pandoc = {
globals = {
-- Global modules
"pandoc", "lpeg", "re",
-- Global variables passed to filters
"FORMAT", "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_VERSION", "PANDOC_API_VERSION",
"PANDOC_SCRIPT_FILE", "PANDOC_STATE",
-- Globals that can be used to create filter elements
-- - top level
"Inlines", "Inline", "Blocks", "Block", "Meta", "Pandoc",
-- - inline
"Cite", "Code", "Emph", "Image", "LineBreak", "Link", "Math", "Note", "Quoted", "RawInline", "SmallCaps",
"SoftBreak", "Space", "Span", "Str", "Strikeout", "Strong", "Subscript", "Superscript", "Underline",
-- - block
"BlockQuote", "BulletList", "CodeBlock", "DefinitionList", "Div", "Figure", "Header", "HorizontalRule",
"LineBlock", "OrderedList", "Para", "Plain", "RawBlock", "Table",
}
}
builtin_standards.pandoc = pandoc.pandoc
builtin_standards.pandoc_filter = pandoc.filter
builtin_standards.pandoc_reader = pandoc.reader
builtin_standards.pandoc_writer = pandoc.writer

builtin_standards.none = {}

Expand Down
58 changes: 58 additions & 0 deletions src/luacheck/builtin_standards/pandoc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
local add_std_table = require "luacheck.standards".add_std_table

local function combine(...)
local res = {}
for _, def in ipairs({...}) do
add_std_table(res, def)
end
return res.fields
end

local common = {
read_globals = {
"pandoc", "lpeg", "re",
},
}

-- https://pandoc.org/lua-filters.html
local filter = {
read_globals = {
"FORMAT", "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_VERSION", "PANDOC_API_VERSION",
"PANDOC_SCRIPT_FILE", "PANDOC_STATE",
},
globals = {
-- - top level
"Inlines", "Inline", "Blocks", "Block", "Meta", "Pandoc",
-- - inline
"Cite", "Code", "Emph", "Image", "LineBreak", "Link", "Math", "Note", "Quoted", "RawInline", "SmallCaps",
"SoftBreak", "Space", "Span", "Str", "Strikeout", "Strong", "Subscript", "Superscript", "Underline",
-- - block
"BlockQuote", "BulletList", "CodeBlock", "DefinitionList", "Div", "Figure", "Header", "HorizontalRule",
"LineBlock", "OrderedList", "Para", "Plain", "RawBlock", "Table",
},
}

-- https://pandoc.org/custom-readers.html
local reader = {
globals = {
"Reader", "Extensions",
"ByteStringReader"
},
}

-- https://pandoc.org/custom-writers.html
local writer = {
globals = {
"PANDOC_DOCUMENT", "Writer", "Extensions", "Doc", "Template",
"Blocksep", "ByteStringWriter", "CaptionedImage", "DisplayMath", "DoubleQuoted", "InlineMath", "SingleQuoted",
},
}

local variants = {
pandoc = { globals = combine(common, filter, reader, writer) },
filter = { globals = combine(common, filter) },
reader = { globals = combine(common, reader) },
writer = { globals = combine(common, writer) },
}

return variants

0 comments on commit 25021e0

Please sign in to comment.