Some cleaning/linting
This commit is contained in:
parent
016f57ef1c
commit
7dc8d75b6c
|
@ -6580,38 +6580,42 @@ function lit.g(name)
|
|||
-- Variable for grammars collection
|
||||
local grammars = {}
|
||||
|
||||
local P, S, R, Cf, Cc, Ct, V, Cs, Cg, Cb, B, C, Cmt =
|
||||
lpeg.P, lpeg.S, lpeg.R, lpeg.Cf, lpeg.Cc, lpeg.Ct, lpeg.V,
|
||||
lpeg.Cs, lpeg.Cg, lpeg.Cb, lpeg.B, lpeg.C, lpeg.Cmt
|
||||
|
||||
-- Lexical elements
|
||||
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
||||
local space = lpeg.S" \t"
|
||||
local anyspace = lpeg.S" \t\r\n"
|
||||
local newline = P"\r"^-1 * P"\n"
|
||||
local space = S" \t"
|
||||
local anyspace = S" \t\r\n"
|
||||
local spot = (1 - anyspace)
|
||||
local any = (spot + space)
|
||||
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
||||
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
||||
local yamlheader = space^0 * P"---" * space^0 * newline
|
||||
local yamlfooter = space^0 * P"..." * space^0 * newline^-1
|
||||
local yamlbody = -yamlfooter * any^0 * newline
|
||||
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
||||
local ref = -lpeg.B"\\" * lpeg.P"#" * lpeg.C(id)
|
||||
local id = R("az", "AZ") * R("az", "AZ", "09")^0
|
||||
local ref = -B"\\" * P"#" * C(id)
|
||||
local notref = (1 - ref)^0
|
||||
|
||||
-- Declaration grammar
|
||||
grammars["declaration"] = lpeg.P {
|
||||
grammars["declaration"] = P {
|
||||
"Declaration";
|
||||
Declaration = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
||||
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
||||
Code = lpeg.C((any + newline)^0);
|
||||
Declaration = Ct(V"YAML" * V"Code", "name");
|
||||
YAML = C(yamlheader * yamlbody^0 * yamlfooter);
|
||||
Code = C((any + newline)^0);
|
||||
}
|
||||
|
||||
-- References grammar
|
||||
grammars["references"] = notref * lpeg.P {
|
||||
grammars["references"] = notref * P {
|
||||
"References";
|
||||
References = lpeg.Ct((ref * notref)^0);
|
||||
References = Ct((ref * notref)^0);
|
||||
} * -1
|
||||
|
||||
return grammars[name]
|
||||
end
|
||||
|
||||
-- Prints located messages
|
||||
function lit.puts(key, ...)
|
||||
function lit.puts(yaml_key, ...)
|
||||
|
||||
-- Returns debug level as number
|
||||
local function debuglevel(str)
|
||||
|
@ -6673,7 +6677,9 @@ ERROR:
|
|||
for mtype, msgs in pairs(msg) do
|
||||
if msgs[key] ~= nil then
|
||||
key = (msgs[key][lang] ~= nil and msgs[key][lang] or msgs[key]["en"])
|
||||
for i, str in ipairs({...}) do key = key:gsub("#" .. i, str) end
|
||||
for i, str in ipairs({...}) do
|
||||
key = key:gsub("#" .. i, str)
|
||||
end
|
||||
levelname, level = mtype, debuglevel(mtype)
|
||||
break
|
||||
end
|
||||
|
@ -6682,7 +6688,7 @@ ERROR:
|
|||
end
|
||||
|
||||
local verbosity = debuglevel(PANDOC_STATE.verbosity)
|
||||
local msg, levelname, level = getmsg(key, ...)
|
||||
local msg, levelname, level = getmsg(yaml_key, ...)
|
||||
if level >= verbosity then
|
||||
print("[" .. levelname .. "] [LIT] " .. msg)
|
||||
end
|
||||
|
@ -6782,9 +6788,9 @@ function lit.exam(doc)
|
|||
-- Checks for valid command
|
||||
local function checkcmd(meta)
|
||||
if meta["cmd"] then
|
||||
cmd = meta["cmd"]:split()[1]
|
||||
local cmd = meta["cmd"]:split()[1]
|
||||
if os.isunix() then
|
||||
status = io.try("type", cmd)
|
||||
local status = io.try("type", cmd)
|
||||
if not(status) then
|
||||
putserr("invalid_cmd", cmd)
|
||||
end
|
||||
|
@ -6796,7 +6802,7 @@ function lit.exam(doc)
|
|||
|
||||
-- Checks for extra and unwanted metadata
|
||||
local function checkextra(meta)
|
||||
for key, val in pairs(meta) do
|
||||
for key, _ in pairs(meta) do
|
||||
local missing1 = metastruct["mandatory"][key] == nil
|
||||
local missing2 = metastruct["optional"][key] == nil
|
||||
if missing1 and missing2 then
|
||||
|
@ -6806,7 +6812,7 @@ function lit.exam(doc)
|
|||
end
|
||||
|
||||
-- Checks for valid metadata
|
||||
local function checkmeta(meta, kind)
|
||||
local function checkmeta(metadata, kind)
|
||||
|
||||
-- Checks for valid metadata type
|
||||
local function checktype(type1, meta, key)
|
||||
|
@ -6839,12 +6845,12 @@ function lit.exam(doc)
|
|||
end
|
||||
|
||||
for key, val in pairs(metastruct[kind]) do
|
||||
if meta[key] == nil and kind == "mandatory" then
|
||||
if metadata[key] == nil and kind == "mandatory" then
|
||||
putserr("no_key", key)
|
||||
elseif meta[key] and type(val) == "table" then
|
||||
checkpattern(val, meta, key)
|
||||
elseif meta[key] then
|
||||
checktype(val, meta, key)
|
||||
elseif metadata[key] and type(val) == "table" then
|
||||
checkpattern(val, metadata, key)
|
||||
elseif metadata[key] then
|
||||
checktype(val, metadata, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -6870,7 +6876,7 @@ function lit.exam(doc)
|
|||
-- TODO
|
||||
-- NOTE: if not valid code, return meta["eval"] = {}
|
||||
local function checkcode(code, meta)
|
||||
references = lpeg.match(lit.g("references"), code)
|
||||
local references = lpeg.match(lit.g("references"), code)
|
||||
if references then
|
||||
for _, ref in ipairs(references) do
|
||||
print("reference:", ref)
|
||||
|
@ -6920,14 +6926,7 @@ end
|
|||
|
||||
return {
|
||||
-- Parses and evals literate programming
|
||||
{ Pandoc = function(doc) return lit.exam(doc) end },
|
||||
{
|
||||
-- Parses and evals natural programming
|
||||
-- TODO
|
||||
Inlines = function(inlines)
|
||||
md = pandoc.utils.stringify(inlines)
|
||||
md = nat.get(md)
|
||||
return inlines
|
||||
end,
|
||||
}
|
||||
{ Pandoc = function(e) return lit.exam(e) end },
|
||||
-- TODO Parses and evals natural programming
|
||||
-- { Inlines = function(e) return nat.get(pandoc.utils.stringify(e)) end },
|
||||
}
|
||||
|
|
|
@ -23,38 +23,42 @@ function lit.g(name)
|
|||
-- Variable for grammars collection
|
||||
local grammars = {}
|
||||
|
||||
local P, S, R, Cf, Cc, Ct, V, Cs, Cg, Cb, B, C, Cmt =
|
||||
lpeg.P, lpeg.S, lpeg.R, lpeg.Cf, lpeg.Cc, lpeg.Ct, lpeg.V,
|
||||
lpeg.Cs, lpeg.Cg, lpeg.Cb, lpeg.B, lpeg.C, lpeg.Cmt
|
||||
|
||||
-- Lexical elements
|
||||
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
||||
local space = lpeg.S" \t"
|
||||
local anyspace = lpeg.S" \t\r\n"
|
||||
local newline = P"\r"^-1 * P"\n"
|
||||
local space = S" \t"
|
||||
local anyspace = S" \t\r\n"
|
||||
local spot = (1 - anyspace)
|
||||
local any = (spot + space)
|
||||
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
||||
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
||||
local yamlheader = space^0 * P"---" * space^0 * newline
|
||||
local yamlfooter = space^0 * P"..." * space^0 * newline^-1
|
||||
local yamlbody = -yamlfooter * any^0 * newline
|
||||
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
||||
local ref = -lpeg.B"\\" * lpeg.P"#" * lpeg.C(id)
|
||||
local id = R("az", "AZ") * R("az", "AZ", "09")^0
|
||||
local ref = -B"\\" * P"#" * C(id)
|
||||
local notref = (1 - ref)^0
|
||||
|
||||
-- Declaration grammar
|
||||
grammars["declaration"] = lpeg.P {
|
||||
grammars["declaration"] = P {
|
||||
"Declaration";
|
||||
Declaration = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
||||
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
||||
Code = lpeg.C((any + newline)^0);
|
||||
Declaration = Ct(V"YAML" * V"Code", "name");
|
||||
YAML = C(yamlheader * yamlbody^0 * yamlfooter);
|
||||
Code = C((any + newline)^0);
|
||||
}
|
||||
|
||||
-- References grammar
|
||||
grammars["references"] = notref * lpeg.P {
|
||||
grammars["references"] = notref * P {
|
||||
"References";
|
||||
References = lpeg.Ct((ref * notref)^0);
|
||||
References = Ct((ref * notref)^0);
|
||||
} * -1
|
||||
|
||||
return grammars[name]
|
||||
end
|
||||
|
||||
-- Prints located messages
|
||||
function lit.puts(key, ...)
|
||||
function lit.puts(yaml_key, ...)
|
||||
|
||||
-- Returns debug level as number
|
||||
local function debuglevel(str)
|
||||
|
@ -116,7 +120,9 @@ ERROR:
|
|||
for mtype, msgs in pairs(msg) do
|
||||
if msgs[key] ~= nil then
|
||||
key = (msgs[key][lang] ~= nil and msgs[key][lang] or msgs[key]["en"])
|
||||
for i, str in ipairs({...}) do key = key:gsub("#" .. i, str) end
|
||||
for i, str in ipairs({...}) do
|
||||
key = key:gsub("#" .. i, str)
|
||||
end
|
||||
levelname, level = mtype, debuglevel(mtype)
|
||||
break
|
||||
end
|
||||
|
@ -125,7 +131,7 @@ ERROR:
|
|||
end
|
||||
|
||||
local verbosity = debuglevel(PANDOC_STATE.verbosity)
|
||||
local msg, levelname, level = getmsg(key, ...)
|
||||
local msg, levelname, level = getmsg(yaml_key, ...)
|
||||
if level >= verbosity then
|
||||
print("[" .. levelname .. "] [LIT] " .. msg)
|
||||
end
|
||||
|
@ -225,9 +231,9 @@ function lit.exam(doc)
|
|||
-- Checks for valid command
|
||||
local function checkcmd(meta)
|
||||
if meta["cmd"] then
|
||||
cmd = meta["cmd"]:split()[1]
|
||||
local cmd = meta["cmd"]:split()[1]
|
||||
if os.isunix() then
|
||||
status = io.try("type", cmd)
|
||||
local status = io.try("type", cmd)
|
||||
if not(status) then
|
||||
putserr("invalid_cmd", cmd)
|
||||
end
|
||||
|
@ -239,7 +245,7 @@ function lit.exam(doc)
|
|||
|
||||
-- Checks for extra and unwanted metadata
|
||||
local function checkextra(meta)
|
||||
for key, val in pairs(meta) do
|
||||
for key, _ in pairs(meta) do
|
||||
local missing1 = metastruct["mandatory"][key] == nil
|
||||
local missing2 = metastruct["optional"][key] == nil
|
||||
if missing1 and missing2 then
|
||||
|
@ -249,7 +255,7 @@ function lit.exam(doc)
|
|||
end
|
||||
|
||||
-- Checks for valid metadata
|
||||
local function checkmeta(meta, kind)
|
||||
local function checkmeta(metadata, kind)
|
||||
|
||||
-- Checks for valid metadata type
|
||||
local function checktype(type1, meta, key)
|
||||
|
@ -282,12 +288,12 @@ function lit.exam(doc)
|
|||
end
|
||||
|
||||
for key, val in pairs(metastruct[kind]) do
|
||||
if meta[key] == nil and kind == "mandatory" then
|
||||
if metadata[key] == nil and kind == "mandatory" then
|
||||
putserr("no_key", key)
|
||||
elseif meta[key] and type(val) == "table" then
|
||||
checkpattern(val, meta, key)
|
||||
elseif meta[key] then
|
||||
checktype(val, meta, key)
|
||||
elseif metadata[key] and type(val) == "table" then
|
||||
checkpattern(val, metadata, key)
|
||||
elseif metadata[key] then
|
||||
checktype(val, metadata, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -313,7 +319,7 @@ function lit.exam(doc)
|
|||
-- TODO
|
||||
-- NOTE: if not valid code, return meta["eval"] = {}
|
||||
local function checkcode(code, meta)
|
||||
references = lpeg.match(lit.g("references"), code)
|
||||
local references = lpeg.match(lit.g("references"), code)
|
||||
if references then
|
||||
for _, ref in ipairs(references) do
|
||||
print("reference:", ref)
|
||||
|
@ -363,14 +369,7 @@ end
|
|||
|
||||
return {
|
||||
-- Parses and evals literate programming
|
||||
{ Pandoc = function(doc) return lit.exam(doc) end },
|
||||
{
|
||||
-- Parses and evals natural programming
|
||||
-- TODO
|
||||
Inlines = function(inlines)
|
||||
md = pandoc.utils.stringify(inlines)
|
||||
md = nat.get(md)
|
||||
return inlines
|
||||
end,
|
||||
}
|
||||
{ Pandoc = function(e) return lit.exam(e) end },
|
||||
-- TODO Parses and evals natural programming
|
||||
-- { Inlines = function(e) return nat.get(pandoc.utils.stringify(e)) end },
|
||||
}
|
||||
|
|
|
@ -12,38 +12,42 @@ function lit.g(name)
|
|||
-- Variable for grammars collection
|
||||
local grammars = {}
|
||||
|
||||
local P, S, R, Cf, Cc, Ct, V, Cs, Cg, Cb, B, C, Cmt =
|
||||
lpeg.P, lpeg.S, lpeg.R, lpeg.Cf, lpeg.Cc, lpeg.Ct, lpeg.V,
|
||||
lpeg.Cs, lpeg.Cg, lpeg.Cb, lpeg.B, lpeg.C, lpeg.Cmt
|
||||
|
||||
-- Lexical elements
|
||||
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
||||
local space = lpeg.S" \t"
|
||||
local anyspace = lpeg.S" \t\r\n"
|
||||
local newline = P"\r"^-1 * P"\n"
|
||||
local space = S" \t"
|
||||
local anyspace = S" \t\r\n"
|
||||
local spot = (1 - anyspace)
|
||||
local any = (spot + space)
|
||||
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
||||
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
||||
local yamlheader = space^0 * P"---" * space^0 * newline
|
||||
local yamlfooter = space^0 * P"..." * space^0 * newline^-1
|
||||
local yamlbody = -yamlfooter * any^0 * newline
|
||||
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
||||
local ref = -lpeg.B"\\" * lpeg.P"#" * lpeg.C(id)
|
||||
local id = R("az", "AZ") * R("az", "AZ", "09")^0
|
||||
local ref = -B"\\" * P"#" * C(id)
|
||||
local notref = (1 - ref)^0
|
||||
|
||||
-- Declaration grammar
|
||||
grammars["declaration"] = lpeg.P {
|
||||
grammars["declaration"] = P {
|
||||
"Declaration";
|
||||
Declaration = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
||||
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
||||
Code = lpeg.C((any + newline)^0);
|
||||
Declaration = Ct(V"YAML" * V"Code", "name");
|
||||
YAML = C(yamlheader * yamlbody^0 * yamlfooter);
|
||||
Code = C((any + newline)^0);
|
||||
}
|
||||
|
||||
-- References grammar
|
||||
grammars["references"] = notref * lpeg.P {
|
||||
grammars["references"] = notref * P {
|
||||
"References";
|
||||
References = lpeg.Ct((ref * notref)^0);
|
||||
References = Ct((ref * notref)^0);
|
||||
} * -1
|
||||
|
||||
return grammars[name]
|
||||
end
|
||||
|
||||
-- Prints located messages
|
||||
function lit.puts(key, ...)
|
||||
function lit.puts(yaml_key, ...)
|
||||
|
||||
-- Returns debug level as number
|
||||
local function debuglevel(str)
|
||||
|
@ -64,7 +68,9 @@ function lit.puts(key, ...)
|
|||
for mtype, msgs in pairs(msg) do
|
||||
if msgs[key] ~= nil then
|
||||
key = (msgs[key][lang] ~= nil and msgs[key][lang] or msgs[key]["en"])
|
||||
for i, str in ipairs({...}) do key = key:gsub("#" .. i, str) end
|
||||
for i, str in ipairs({...}) do
|
||||
key = key:gsub("#" .. i, str)
|
||||
end
|
||||
levelname, level = mtype, debuglevel(mtype)
|
||||
break
|
||||
end
|
||||
|
@ -73,7 +79,7 @@ function lit.puts(key, ...)
|
|||
end
|
||||
|
||||
local verbosity = debuglevel(PANDOC_STATE.verbosity)
|
||||
local msg, levelname, level = getmsg(key, ...)
|
||||
local msg, levelname, level = getmsg(yaml_key, ...)
|
||||
if level >= verbosity then
|
||||
print("[" .. levelname .. "] [LIT] " .. msg)
|
||||
end
|
||||
|
@ -173,9 +179,9 @@ function lit.exam(doc)
|
|||
-- Checks for valid command
|
||||
local function checkcmd(meta)
|
||||
if meta["cmd"] then
|
||||
cmd = meta["cmd"]:split()[1]
|
||||
local cmd = meta["cmd"]:split()[1]
|
||||
if os.isunix() then
|
||||
status = io.try("type", cmd)
|
||||
local status = io.try("type", cmd)
|
||||
if not(status) then
|
||||
putserr("invalid_cmd", cmd)
|
||||
end
|
||||
|
@ -187,7 +193,7 @@ function lit.exam(doc)
|
|||
|
||||
-- Checks for extra and unwanted metadata
|
||||
local function checkextra(meta)
|
||||
for key, val in pairs(meta) do
|
||||
for key, _ in pairs(meta) do
|
||||
local missing1 = metastruct["mandatory"][key] == nil
|
||||
local missing2 = metastruct["optional"][key] == nil
|
||||
if missing1 and missing2 then
|
||||
|
@ -197,7 +203,7 @@ function lit.exam(doc)
|
|||
end
|
||||
|
||||
-- Checks for valid metadata
|
||||
local function checkmeta(meta, kind)
|
||||
local function checkmeta(metadata, kind)
|
||||
|
||||
-- Checks for valid metadata type
|
||||
local function checktype(type1, meta, key)
|
||||
|
@ -230,12 +236,12 @@ function lit.exam(doc)
|
|||
end
|
||||
|
||||
for key, val in pairs(metastruct[kind]) do
|
||||
if meta[key] == nil and kind == "mandatory" then
|
||||
if metadata[key] == nil and kind == "mandatory" then
|
||||
putserr("no_key", key)
|
||||
elseif meta[key] and type(val) == "table" then
|
||||
checkpattern(val, meta, key)
|
||||
elseif meta[key] then
|
||||
checktype(val, meta, key)
|
||||
elseif metadata[key] and type(val) == "table" then
|
||||
checkpattern(val, metadata, key)
|
||||
elseif metadata[key] then
|
||||
checktype(val, metadata, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -261,7 +267,7 @@ function lit.exam(doc)
|
|||
-- TODO
|
||||
-- NOTE: if not valid code, return meta["eval"] = {}
|
||||
local function checkcode(code, meta)
|
||||
references = lpeg.match(lit.g("references"), code)
|
||||
local references = lpeg.match(lit.g("references"), code)
|
||||
if references then
|
||||
for _, ref in ipairs(references) do
|
||||
print("reference:", ref)
|
||||
|
|
|
@ -2,14 +2,7 @@
|
|||
|
||||
return {
|
||||
-- Parses and evals literate programming
|
||||
{ Pandoc = function(doc) return lit.exam(doc) end },
|
||||
{
|
||||
-- Parses and evals natural programming
|
||||
-- TODO
|
||||
Inlines = function(inlines)
|
||||
md = pandoc.utils.stringify(inlines)
|
||||
md = nat.get(md)
|
||||
return inlines
|
||||
end,
|
||||
}
|
||||
{ Pandoc = function(e) return lit.exam(e) end },
|
||||
-- TODO Parses and evals natural programming
|
||||
-- { Inlines = function(e) return nat.get(pandoc.utils.stringify(e)) end },
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue