Skip to content

Commit

Permalink
Remove parens in markdown-unicode-data.lua, replace lpeg.S with P
Browse files Browse the repository at this point in the history
This change was inspired by changes from
<Witiko/expltools#21>.
  • Loading branch information
Witiko committed Jan 13, 2025
1 parent 152b504 commit 3eabc67
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -27528,17 +27528,17 @@ parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
end

print("M.punctuation = {}")
print("local S = lpeg.S")
print("local P = lpeg.P")
print("-- luacheck: push no max line length")
for length, prefix_tree in pairs(prefix_trees) do
local subparsers = {}
depth_first_search(prefix_tree, "", function(node, path)
if type(node) == "string" then
local suffix
if node == "]" then
suffix = "S('" .. node .. "')"
suffix = "P('" .. node .. "')"
else
suffix = "S([[" .. node .. "]])"
suffix = "P([[" .. node .. "]])"
end
if subparsers[path] ~= nil then
subparsers[path] = subparsers[path] .. " + " .. suffix
Expand All @@ -27550,20 +27550,23 @@ parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
if #path > 0 then
local byte = path:sub(#path, #path)
local parent_path = path:sub(1, #path-1)
if subparsers[path] ~= nil then
local suffix
if byte == "]" then
suffix = "S('" .. byte .. "')"
else
suffix = "S([[" .. byte .. "]])"
end
suffix = suffix .. " * (" .. subparsers[path] .. ")"
if subparsers[parent_path] ~= nil then
subparsers[parent_path] = subparsers[parent_path]
.. " + " .. suffix
else
subparsers[parent_path] = suffix
end
local prefix
if byte == "]" then
prefix = "P('" .. byte .. "')"
else
prefix = "P([[" .. byte .. "]])"
end
local suffix
if subparsers[path]:find(" %+ ") then
suffix = prefix .. " * (" .. subparsers[path] .. ")"
else
suffix = prefix .. " * " .. subparsers[path]
end
if subparsers[parent_path] ~= nil then
subparsers[parent_path] = subparsers[parent_path]
.. " + " .. suffix
else
subparsers[parent_path] = suffix
end
else
print("M.punctuation[" .. length .. "] = " .. subparsers[path])
Expand Down

0 comments on commit 3eabc67

Please sign in to comment.