From 2c384182be8ab7143b0a0f69e981f1ce529c18c3 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 27 Aug 2024 23:18:47 +0300 Subject: [PATCH 1/7] feat: Add builtin standarts for Pandoc filter globals --- src/luacheck/builtin_standards/init.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index 097fee2d..2771d48e 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -344,6 +344,14 @@ builtin_standards.sile = { } } +-- https://pandoc.org/lua-filters.html#global-variables +builtin_standards.pandoc = { + globals = { + "pandoc", "lpeg", "re", + "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_VERSION", "PANDOC_API_VERSION", "PANDOC_SCRIPT_FILE", "PANDOC_STATE", + } +} + builtin_standards.none = {} return builtin_standards From 7e4f22e697efc23fc0c08b97730a84c9e3529415 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 27 Aug 2024 23:27:49 +0300 Subject: [PATCH 2/7] docs: Note introduction of Pandoc builtin --- docsrc/cli.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docsrc/cli.rst b/docsrc/cli.rst index be222004..628ee290 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -87,6 +87,7 @@ Option Meaning * ``rockspec`` - globals allowed in rockspecs, by default added for files ending with ``.rockspec``; * ``luacheckrc`` - globals allowed in Luacheck configs, by default added for files ending with ``.luacheckrc``; * ``ldoc`` - globals allowed in LDoc config, by default added for files named ``config.ld``; + * ``pandoc`` - globals allowed in Pandoc Lua filters; * ``sile`` - globals allowed in The SILE Typesetter and its package ecosystem; * ``none`` - no standard globals. From edd945647aaf9c05dae7ca11757d6cad4bc50d7c Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 27 Aug 2024 23:45:40 +0300 Subject: [PATCH 3/7] feat: Extend pandoc builtins with globals used to create filters --- src/luacheck/builtin_standards/init.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index 2771d48e..d0068f9e 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -347,8 +347,20 @@ builtin_standards.sile = { -- https://pandoc.org/lua-filters.html#global-variables builtin_standards.pandoc = { globals = { + -- Global modules "pandoc", "lpeg", "re", - "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_VERSION", "PANDOC_API_VERSION", "PANDOC_SCRIPT_FILE", "PANDOC_STATE", + -- 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", } } From a9accd6604709c21b7556cf6b99943410a16ff1c Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 28 Aug 2024 00:49:59 +0300 Subject: [PATCH 4/7] feat: Move pandoc builtins to their own module and split filters, readers, and writers --- luacheck-dev-1.rockspec | 1 + src/luacheck/builtin_standards/init.lua | 24 ++-------- src/luacheck/builtin_standards/pandoc.lua | 57 +++++++++++++++++++++++ 3 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 src/luacheck/builtin_standards/pandoc.lua diff --git a/luacheck-dev-1.rockspec b/luacheck-dev-1.rockspec index 0389dd14..6506e1a1 100644 --- a/luacheck-dev-1.rockspec +++ b/luacheck-dev-1.rockspec @@ -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", diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index d0068f9e..159f766f 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -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" @@ -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 = {} diff --git a/src/luacheck/builtin_standards/pandoc.lua b/src/luacheck/builtin_standards/pandoc.lua new file mode 100644 index 00000000..e03cffaa --- /dev/null +++ b/src/luacheck/builtin_standards/pandoc.lua @@ -0,0 +1,57 @@ +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 = { + -- document types + "Inlines", "Inline", "Blocks", "Block", "Meta", "Pandoc", + -- inline types + "Cite", "Code", "Emph", "Image", "LineBreak", "Link", "Math", "Note", "Quoted", "RawInline", "SmallCaps", + "SoftBreak", "Space", "Span", "Str", "Strikeout", "Strong", "Subscript", "Superscript", "Underline", + -- block types + "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 From d46bd3c2763cb8683e6f0dfd4d725c9e4300a40f Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 28 Aug 2024 17:23:30 +0300 Subject: [PATCH 5/7] chore: Combine Pandoc reader/writer bultins into custom --- docsrc/cli.rst | 4 +++- src/luacheck/builtin_standards/init.lua | 3 +-- src/luacheck/builtin_standards/pandoc.lua | 20 ++++++++------------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/docsrc/cli.rst b/docsrc/cli.rst index 628ee290..f8e6685a 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -87,7 +87,9 @@ Option Meaning * ``rockspec`` - globals allowed in rockspecs, by default added for files ending with ``.rockspec``; * ``luacheckrc`` - globals allowed in Luacheck configs, by default added for files ending with ``.luacheckrc``; * ``ldoc`` - globals allowed in LDoc config, by default added for files named ``config.ld``; - * ``pandoc`` - globals allowed in Pandoc Lua filters; + * ``pandoc`` - globals allowed in Pandoc Lua; + * ``pandoc_filters`` - globals allowed in Pandoc Lua, subset specific to filters; + * ``pandoc_custom`` - globals allowed in Pandoc Lua, subset specific to custom reader/writers; * ``sile`` - globals allowed in The SILE Typesetter and its package ecosystem; * ``none`` - no standard globals. diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index 159f766f..377d88d4 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -347,8 +347,7 @@ builtin_standards.sile = { 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.pandoc_custom = pandoc.custom builtin_standards.none = {} diff --git a/src/luacheck/builtin_standards/pandoc.lua b/src/luacheck/builtin_standards/pandoc.lua index e03cffaa..d7b062f3 100644 --- a/src/luacheck/builtin_standards/pandoc.lua +++ b/src/luacheck/builtin_standards/pandoc.lua @@ -33,25 +33,21 @@ local filter = { } -- https://pandoc.org/custom-readers.html -local reader = { - globals = { - "Reader", "Extensions", "ByteStringReader" - }, -} - -- https://pandoc.org/custom-writers.html -local writer = { +local custom = { globals = { - "PANDOC_DOCUMENT", "Writer", "Extensions", "Doc", "Template", - "Blocksep", "ByteStringWriter", "CaptionedImage", "DisplayMath", "DoubleQuoted", "InlineMath", "SingleQuoted", + -- custom scope + "PANDOC_DOCUMENT", + "ByteStringReader", "ByteStringWriter", "Doc", "Extensions", "Reader", "Template", "Writer", + -- extra types applicable to readers/writers + "Blocksep", "CaptionedImage", "DisplayMath", "DoubleQuoted", "InlineMath", "SingleQuoted", }, } local variants = { - pandoc = { globals = combine(common, filter, reader, writer) }, + pandoc = { globals = combine(common, filter, custom) }, filter = { globals = combine(common, filter) }, - reader = { globals = combine(common, reader) }, - writer = { globals = combine(common, writer) }, + custom = { globals = combine(common, custom) }, } return variants From 680f2360c8bc318322c7f4ce991fa7fdd0a0ed0c Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 28 Aug 2024 17:38:02 +0300 Subject: [PATCH 6/7] chore: Split out builtins for Pandoc scripts --- docsrc/cli.rst | 5 +++-- src/luacheck/builtin_standards/init.lua | 1 + src/luacheck/builtin_standards/pandoc.lua | 24 ++++++++++++++--------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docsrc/cli.rst b/docsrc/cli.rst index f8e6685a..93e1d3b2 100644 --- a/docsrc/cli.rst +++ b/docsrc/cli.rst @@ -87,9 +87,10 @@ Option Meaning * ``rockspec`` - globals allowed in rockspecs, by default added for files ending with ``.rockspec``; * ``luacheckrc`` - globals allowed in Luacheck configs, by default added for files ending with ``.luacheckrc``; * ``ldoc`` - globals allowed in LDoc config, by default added for files named ``config.ld``; - * ``pandoc`` - globals allowed in Pandoc Lua; - * ``pandoc_filters`` - globals allowed in Pandoc Lua, subset specific to filters; + * ``pandoc`` - globals allowed in Pandoc Lua in any context; + * ``pandoc_filter`` - globals allowed in Pandoc Lua, subset specific to filters; * ``pandoc_custom`` - globals allowed in Pandoc Lua, subset specific to custom reader/writers; + * ``pandoc_script`` - globals allowed in Pandoc Lua, subset specific to scripts; * ``sile`` - globals allowed in The SILE Typesetter and its package ecosystem; * ``none`` - no standard globals. diff --git a/src/luacheck/builtin_standards/init.lua b/src/luacheck/builtin_standards/init.lua index 377d88d4..4aa202f5 100644 --- a/src/luacheck/builtin_standards/init.lua +++ b/src/luacheck/builtin_standards/init.lua @@ -348,6 +348,7 @@ builtin_standards.sile = { builtin_standards.pandoc = pandoc.pandoc builtin_standards.pandoc_filter = pandoc.filter builtin_standards.pandoc_custom = pandoc.custom +builtin_standards.pandoc_script = pandoc.script builtin_standards.none = {} diff --git a/src/luacheck/builtin_standards/pandoc.lua b/src/luacheck/builtin_standards/pandoc.lua index d7b062f3..097010af 100644 --- a/src/luacheck/builtin_standards/pandoc.lua +++ b/src/luacheck/builtin_standards/pandoc.lua @@ -10,16 +10,9 @@ end local common = { read_globals = { + "PANDOC_VERSION", "PANDOC_API_VERSION", "PANDOC_STATE", "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 = { -- document types "Inlines", "Inline", "Blocks", "Block", "Meta", "Pandoc", @@ -32,6 +25,13 @@ local filter = { }, } +-- https://pandoc.org/lua-filters.html +local filter = { + read_globals = { + "FORMAT", "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_SCRIPT_FILE" + }, +} + -- https://pandoc.org/custom-readers.html -- https://pandoc.org/custom-writers.html local custom = { @@ -44,10 +44,16 @@ local custom = { }, } +local script = { + globals = { + } +} + local variants = { - pandoc = { globals = combine(common, filter, custom) }, + pandoc = { globals = combine(common, filter, custom, script) }, filter = { globals = combine(common, filter) }, custom = { globals = combine(common, custom) }, + script = { globals = combine(common, script) }, } return variants From 745a7bbae2bf4c1102014d4fc75174824d43ad9f Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 28 Aug 2024 18:54:14 +0300 Subject: [PATCH 7/7] chore: Correct availability of clobals in reader/writers --- src/luacheck/builtin_standards/pandoc.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/luacheck/builtin_standards/pandoc.lua b/src/luacheck/builtin_standards/pandoc.lua index 097010af..f640ea3e 100644 --- a/src/luacheck/builtin_standards/pandoc.lua +++ b/src/luacheck/builtin_standards/pandoc.lua @@ -28,7 +28,8 @@ local common = { -- https://pandoc.org/lua-filters.html local filter = { read_globals = { - "FORMAT", "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_SCRIPT_FILE" + "FORMAT", + "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_SCRIPT_FILE", }, } @@ -38,6 +39,7 @@ local custom = { globals = { -- custom scope "PANDOC_DOCUMENT", + "PANDOC_READER_OPTIONS", "PANDOC_WRITER_OPTIONS", "PANDOC_SCRIPT_FILE", "ByteStringReader", "ByteStringWriter", "Doc", "Extensions", "Reader", "Template", "Writer", -- extra types applicable to readers/writers "Blocksep", "CaptionedImage", "DisplayMath", "DoubleQuoted", "InlineMath", "SingleQuoted",