Starting to checkcode
This commit is contained in:
parent
1d6918d927
commit
016f57ef1c
|
@ -6577,6 +6577,9 @@ lit.status = true
|
||||||
-- Grammars
|
-- Grammars
|
||||||
function lit.g(name)
|
function lit.g(name)
|
||||||
|
|
||||||
|
-- Variable for grammars collection
|
||||||
|
local grammars = {}
|
||||||
|
|
||||||
-- Lexical elements
|
-- Lexical elements
|
||||||
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
||||||
local space = lpeg.S" \t"
|
local space = lpeg.S" \t"
|
||||||
|
@ -6586,20 +6589,24 @@ function lit.g(name)
|
||||||
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
||||||
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
||||||
local yamlbody = -yamlfooter * any^0 * newline
|
local yamlbody = -yamlfooter * any^0 * newline
|
||||||
-- Still not used
|
|
||||||
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
||||||
local ref = lpeg.P"#" * id
|
local ref = -lpeg.B"\\" * lpeg.P"#" * lpeg.C(id)
|
||||||
|
local notref = (1 - ref)^0
|
||||||
|
|
||||||
local grammars = {
|
-- Declaration grammar
|
||||||
-- Block grammar
|
grammars["declaration"] = lpeg.P {
|
||||||
["block"] = lpeg.P {
|
"Declaration";
|
||||||
"Block";
|
Declaration = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
||||||
Block = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
||||||
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
Code = lpeg.C((any + newline)^0);
|
||||||
Code = lpeg.C((any + newline)^0);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- References grammar
|
||||||
|
grammars["references"] = notref * lpeg.P {
|
||||||
|
"References";
|
||||||
|
References = lpeg.Ct((ref * notref)^0);
|
||||||
|
} * -1
|
||||||
|
|
||||||
return grammars[name]
|
return grammars[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6684,7 +6691,7 @@ end
|
||||||
-- Examinates (parses and evaluates) document
|
-- Examinates (parses and evaluates) document
|
||||||
function lit.exam(doc)
|
function lit.exam(doc)
|
||||||
|
|
||||||
-- Evaluates code block
|
-- Evaluates code declaration
|
||||||
-- Evals Lisp code
|
-- Evals Lisp code
|
||||||
--[[
|
--[[
|
||||||
local function eval(code)
|
local function eval(code)
|
||||||
|
@ -6702,10 +6709,10 @@ function lit.exam(doc)
|
||||||
end
|
end
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- Parses code block
|
-- Parses code declaration
|
||||||
local function parse(codeblock)
|
local function parse(codeblock)
|
||||||
|
|
||||||
-- Checks code block
|
-- Checks code declarations
|
||||||
local function check(parsed)
|
local function check(parsed)
|
||||||
|
|
||||||
-- Indicates if checks passes
|
-- Indicates if checks passes
|
||||||
|
@ -6737,13 +6744,13 @@ function lit.exam(doc)
|
||||||
|
|
||||||
-- Language commands
|
-- Language commands
|
||||||
local langcmds = {
|
local langcmds = {
|
||||||
["lua"] = {["int"] = "TODO"},
|
["lua"] = {["int_eval"] = { "CMD1", "CMD2", } },
|
||||||
["fennel"] = {["int"] = "TODO"},
|
["fennel"] = {["int_eval"] = { "CMD1", "CMD2", } },
|
||||||
["python"] = {["ext"] = "TODO"},
|
["python"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["js"] = {["ext"] = "TODO"},
|
["js"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["ruby"] = {["ext"] = "TODO"},
|
["ruby"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["lisp"] = {["ext"] = "TODO"},
|
["lisp"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["graphviz"] = {["ext"] = "TODO"},
|
["graphviz"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Prints error and does not pass the check
|
-- Prints error and does not pass the check
|
||||||
|
@ -6759,14 +6766,14 @@ function lit.exam(doc)
|
||||||
if ispass then
|
if ispass then
|
||||||
if meta["lang"] and meta["cmd"] then
|
if meta["lang"] and meta["cmd"] then
|
||||||
lit.puts("ignore_lang", meta["cmd"], meta["lang"])
|
lit.puts("ignore_lang", meta["cmd"], meta["lang"])
|
||||||
meta["eval"] = {["ext"] = meta["cmd"]}
|
meta["eval"] = {["ext_eval"] = { meta["cmd"] } }
|
||||||
elseif not(meta["lang"]) and not(meta["cmd"])then
|
elseif not(meta["lang"]) and not(meta["cmd"])then
|
||||||
meta["lang"] = "lua"
|
meta["lang"] = "lua"
|
||||||
meta["eval"] = langcmds["lua"]
|
meta["eval"] = langcmds["lua"]
|
||||||
elseif meta["lang"] and not(meta["cmd"]) then
|
elseif meta["lang"] and not(meta["cmd"]) then
|
||||||
meta["eval"] = langcmds[meta["lang"]]
|
meta["eval"] = langcmds[meta["lang"]]
|
||||||
elseif not(meta["lang"]) and meta["cmd"] then
|
elseif not(meta["lang"]) and meta["cmd"] then
|
||||||
meta["eval"] = {["ext"] = meta["cmd"]}
|
meta["eval"] = {["ext_eval"] = { meta["cmd"] } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return meta
|
return meta
|
||||||
|
@ -6860,15 +6867,28 @@ function lit.exam(doc)
|
||||||
return addeval(meta)
|
return addeval(meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
-- NOTE: if not valid code, return meta["eval"] = {}
|
||||||
|
local function checkcode(code, meta)
|
||||||
|
references = lpeg.match(lit.g("references"), code)
|
||||||
|
if references then
|
||||||
|
for _, ref in ipairs(references) do
|
||||||
|
print("reference:", ref)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "TODO"
|
||||||
|
end
|
||||||
|
|
||||||
lit.puts("checking", table.concat(parsed, ""):indent())
|
lit.puts("checking", table.concat(parsed, ""):indent())
|
||||||
local meta = parsemeta(parsed[1])
|
local meta = parsemeta(parsed[1])
|
||||||
-- TODO:
|
-- TODO
|
||||||
-- meta["code"] = checkcode(parsed[2], meta)
|
-- Add each meta to a variable
|
||||||
-- NOTE: if not valid code, return meta["eval"] = {}
|
-- Remove meta if doesn't pass checkcode
|
||||||
|
meta["code"] = checkcode(parsed[2], meta)
|
||||||
return meta
|
return meta
|
||||||
end
|
end
|
||||||
|
|
||||||
local parsed = lpeg.match(lit.g("block"), codeblock.text)
|
local parsed = lpeg.match(lit.g("declaration"), codeblock.text)
|
||||||
local checked = (parsed ~= nil and check(parsed) or parsed)
|
local checked = (parsed ~= nil and check(parsed) or parsed)
|
||||||
-- TODO:
|
-- TODO:
|
||||||
-- evaluated = eval(checked)
|
-- evaluated = eval(checked)
|
||||||
|
|
|
@ -20,6 +20,9 @@ lit.status = true
|
||||||
-- Grammars
|
-- Grammars
|
||||||
function lit.g(name)
|
function lit.g(name)
|
||||||
|
|
||||||
|
-- Variable for grammars collection
|
||||||
|
local grammars = {}
|
||||||
|
|
||||||
-- Lexical elements
|
-- Lexical elements
|
||||||
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
||||||
local space = lpeg.S" \t"
|
local space = lpeg.S" \t"
|
||||||
|
@ -29,20 +32,24 @@ function lit.g(name)
|
||||||
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
||||||
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
||||||
local yamlbody = -yamlfooter * any^0 * newline
|
local yamlbody = -yamlfooter * any^0 * newline
|
||||||
-- Still not used
|
|
||||||
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
||||||
local ref = lpeg.P"#" * id
|
local ref = -lpeg.B"\\" * lpeg.P"#" * lpeg.C(id)
|
||||||
|
local notref = (1 - ref)^0
|
||||||
|
|
||||||
local grammars = {
|
-- Declaration grammar
|
||||||
-- Block grammar
|
grammars["declaration"] = lpeg.P {
|
||||||
["block"] = lpeg.P {
|
"Declaration";
|
||||||
"Block";
|
Declaration = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
||||||
Block = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
||||||
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
Code = lpeg.C((any + newline)^0);
|
||||||
Code = lpeg.C((any + newline)^0);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- References grammar
|
||||||
|
grammars["references"] = notref * lpeg.P {
|
||||||
|
"References";
|
||||||
|
References = lpeg.Ct((ref * notref)^0);
|
||||||
|
} * -1
|
||||||
|
|
||||||
return grammars[name]
|
return grammars[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -127,7 +134,7 @@ end
|
||||||
-- Examinates (parses and evaluates) document
|
-- Examinates (parses and evaluates) document
|
||||||
function lit.exam(doc)
|
function lit.exam(doc)
|
||||||
|
|
||||||
-- Evaluates code block
|
-- Evaluates code declaration
|
||||||
-- Evals Lisp code
|
-- Evals Lisp code
|
||||||
--[[
|
--[[
|
||||||
local function eval(code)
|
local function eval(code)
|
||||||
|
@ -145,10 +152,10 @@ function lit.exam(doc)
|
||||||
end
|
end
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- Parses code block
|
-- Parses code declaration
|
||||||
local function parse(codeblock)
|
local function parse(codeblock)
|
||||||
|
|
||||||
-- Checks code block
|
-- Checks code declarations
|
||||||
local function check(parsed)
|
local function check(parsed)
|
||||||
|
|
||||||
-- Indicates if checks passes
|
-- Indicates if checks passes
|
||||||
|
@ -180,13 +187,13 @@ function lit.exam(doc)
|
||||||
|
|
||||||
-- Language commands
|
-- Language commands
|
||||||
local langcmds = {
|
local langcmds = {
|
||||||
["lua"] = {["int"] = "TODO"},
|
["lua"] = {["int_eval"] = { "CMD1", "CMD2", } },
|
||||||
["fennel"] = {["int"] = "TODO"},
|
["fennel"] = {["int_eval"] = { "CMD1", "CMD2", } },
|
||||||
["python"] = {["ext"] = "TODO"},
|
["python"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["js"] = {["ext"] = "TODO"},
|
["js"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["ruby"] = {["ext"] = "TODO"},
|
["ruby"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["lisp"] = {["ext"] = "TODO"},
|
["lisp"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["graphviz"] = {["ext"] = "TODO"},
|
["graphviz"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Prints error and does not pass the check
|
-- Prints error and does not pass the check
|
||||||
|
@ -202,14 +209,14 @@ function lit.exam(doc)
|
||||||
if ispass then
|
if ispass then
|
||||||
if meta["lang"] and meta["cmd"] then
|
if meta["lang"] and meta["cmd"] then
|
||||||
lit.puts("ignore_lang", meta["cmd"], meta["lang"])
|
lit.puts("ignore_lang", meta["cmd"], meta["lang"])
|
||||||
meta["eval"] = {["ext"] = meta["cmd"]}
|
meta["eval"] = {["ext_eval"] = { meta["cmd"] } }
|
||||||
elseif not(meta["lang"]) and not(meta["cmd"])then
|
elseif not(meta["lang"]) and not(meta["cmd"])then
|
||||||
meta["lang"] = "lua"
|
meta["lang"] = "lua"
|
||||||
meta["eval"] = langcmds["lua"]
|
meta["eval"] = langcmds["lua"]
|
||||||
elseif meta["lang"] and not(meta["cmd"]) then
|
elseif meta["lang"] and not(meta["cmd"]) then
|
||||||
meta["eval"] = langcmds[meta["lang"]]
|
meta["eval"] = langcmds[meta["lang"]]
|
||||||
elseif not(meta["lang"]) and meta["cmd"] then
|
elseif not(meta["lang"]) and meta["cmd"] then
|
||||||
meta["eval"] = {["ext"] = meta["cmd"]}
|
meta["eval"] = {["ext_eval"] = { meta["cmd"] } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return meta
|
return meta
|
||||||
|
@ -303,15 +310,28 @@ function lit.exam(doc)
|
||||||
return addeval(meta)
|
return addeval(meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
-- NOTE: if not valid code, return meta["eval"] = {}
|
||||||
|
local function checkcode(code, meta)
|
||||||
|
references = lpeg.match(lit.g("references"), code)
|
||||||
|
if references then
|
||||||
|
for _, ref in ipairs(references) do
|
||||||
|
print("reference:", ref)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "TODO"
|
||||||
|
end
|
||||||
|
|
||||||
lit.puts("checking", table.concat(parsed, ""):indent())
|
lit.puts("checking", table.concat(parsed, ""):indent())
|
||||||
local meta = parsemeta(parsed[1])
|
local meta = parsemeta(parsed[1])
|
||||||
-- TODO:
|
-- TODO
|
||||||
-- meta["code"] = checkcode(parsed[2], meta)
|
-- Add each meta to a variable
|
||||||
-- NOTE: if not valid code, return meta["eval"] = {}
|
-- Remove meta if doesn't pass checkcode
|
||||||
|
meta["code"] = checkcode(parsed[2], meta)
|
||||||
return meta
|
return meta
|
||||||
end
|
end
|
||||||
|
|
||||||
local parsed = lpeg.match(lit.g("block"), codeblock.text)
|
local parsed = lpeg.match(lit.g("declaration"), codeblock.text)
|
||||||
local checked = (parsed ~= nil and check(parsed) or parsed)
|
local checked = (parsed ~= nil and check(parsed) or parsed)
|
||||||
-- TODO:
|
-- TODO:
|
||||||
-- evaluated = eval(checked)
|
-- evaluated = eval(checked)
|
||||||
|
|
|
@ -9,6 +9,9 @@ lit.status = true
|
||||||
-- Grammars
|
-- Grammars
|
||||||
function lit.g(name)
|
function lit.g(name)
|
||||||
|
|
||||||
|
-- Variable for grammars collection
|
||||||
|
local grammars = {}
|
||||||
|
|
||||||
-- Lexical elements
|
-- Lexical elements
|
||||||
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
local newline = lpeg.P"\r"^-1 * lpeg.P"\n"
|
||||||
local space = lpeg.S" \t"
|
local space = lpeg.S" \t"
|
||||||
|
@ -18,20 +21,24 @@ function lit.g(name)
|
||||||
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
local yamlheader = space^0 * lpeg.P"---" * space^0 * newline
|
||||||
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1
|
||||||
local yamlbody = -yamlfooter * any^0 * newline
|
local yamlbody = -yamlfooter * any^0 * newline
|
||||||
-- Still not used
|
|
||||||
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
local id = lpeg.R("az", "AZ") * lpeg.R("az", "AZ", "09")^0
|
||||||
local ref = lpeg.P"#" * id
|
local ref = -lpeg.B"\\" * lpeg.P"#" * lpeg.C(id)
|
||||||
|
local notref = (1 - ref)^0
|
||||||
|
|
||||||
local grammars = {
|
-- Declaration grammar
|
||||||
-- Block grammar
|
grammars["declaration"] = lpeg.P {
|
||||||
["block"] = lpeg.P {
|
"Declaration";
|
||||||
"Block";
|
Declaration = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
||||||
Block = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name");
|
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
||||||
YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter);
|
Code = lpeg.C((any + newline)^0);
|
||||||
Code = lpeg.C((any + newline)^0);
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- References grammar
|
||||||
|
grammars["references"] = notref * lpeg.P {
|
||||||
|
"References";
|
||||||
|
References = lpeg.Ct((ref * notref)^0);
|
||||||
|
} * -1
|
||||||
|
|
||||||
return grammars[name]
|
return grammars[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,7 +82,7 @@ end
|
||||||
-- Examinates (parses and evaluates) document
|
-- Examinates (parses and evaluates) document
|
||||||
function lit.exam(doc)
|
function lit.exam(doc)
|
||||||
|
|
||||||
-- Evaluates code block
|
-- Evaluates code declaration
|
||||||
-- Evals Lisp code
|
-- Evals Lisp code
|
||||||
--[[
|
--[[
|
||||||
local function eval(code)
|
local function eval(code)
|
||||||
|
@ -93,10 +100,10 @@ function lit.exam(doc)
|
||||||
end
|
end
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- Parses code block
|
-- Parses code declaration
|
||||||
local function parse(codeblock)
|
local function parse(codeblock)
|
||||||
|
|
||||||
-- Checks code block
|
-- Checks code declarations
|
||||||
local function check(parsed)
|
local function check(parsed)
|
||||||
|
|
||||||
-- Indicates if checks passes
|
-- Indicates if checks passes
|
||||||
|
@ -128,13 +135,13 @@ function lit.exam(doc)
|
||||||
|
|
||||||
-- Language commands
|
-- Language commands
|
||||||
local langcmds = {
|
local langcmds = {
|
||||||
["lua"] = {["int"] = "TODO"},
|
["lua"] = {["int_eval"] = { "CMD1", "CMD2", } },
|
||||||
["fennel"] = {["int"] = "TODO"},
|
["fennel"] = {["int_eval"] = { "CMD1", "CMD2", } },
|
||||||
["python"] = {["ext"] = "TODO"},
|
["python"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["js"] = {["ext"] = "TODO"},
|
["js"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["ruby"] = {["ext"] = "TODO"},
|
["ruby"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["lisp"] = {["ext"] = "TODO"},
|
["lisp"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
["graphviz"] = {["ext"] = "TODO"},
|
["graphviz"] = {["ext_eval"] = { "CMD1", "CMD2", } },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Prints error and does not pass the check
|
-- Prints error and does not pass the check
|
||||||
|
@ -150,14 +157,14 @@ function lit.exam(doc)
|
||||||
if ispass then
|
if ispass then
|
||||||
if meta["lang"] and meta["cmd"] then
|
if meta["lang"] and meta["cmd"] then
|
||||||
lit.puts("ignore_lang", meta["cmd"], meta["lang"])
|
lit.puts("ignore_lang", meta["cmd"], meta["lang"])
|
||||||
meta["eval"] = {["ext"] = meta["cmd"]}
|
meta["eval"] = {["ext_eval"] = { meta["cmd"] } }
|
||||||
elseif not(meta["lang"]) and not(meta["cmd"])then
|
elseif not(meta["lang"]) and not(meta["cmd"])then
|
||||||
meta["lang"] = "lua"
|
meta["lang"] = "lua"
|
||||||
meta["eval"] = langcmds["lua"]
|
meta["eval"] = langcmds["lua"]
|
||||||
elseif meta["lang"] and not(meta["cmd"]) then
|
elseif meta["lang"] and not(meta["cmd"]) then
|
||||||
meta["eval"] = langcmds[meta["lang"]]
|
meta["eval"] = langcmds[meta["lang"]]
|
||||||
elseif not(meta["lang"]) and meta["cmd"] then
|
elseif not(meta["lang"]) and meta["cmd"] then
|
||||||
meta["eval"] = {["ext"] = meta["cmd"]}
|
meta["eval"] = {["ext_eval"] = { meta["cmd"] } }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return meta
|
return meta
|
||||||
|
@ -251,15 +258,28 @@ function lit.exam(doc)
|
||||||
return addeval(meta)
|
return addeval(meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO
|
||||||
|
-- NOTE: if not valid code, return meta["eval"] = {}
|
||||||
|
local function checkcode(code, meta)
|
||||||
|
references = lpeg.match(lit.g("references"), code)
|
||||||
|
if references then
|
||||||
|
for _, ref in ipairs(references) do
|
||||||
|
print("reference:", ref)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "TODO"
|
||||||
|
end
|
||||||
|
|
||||||
lit.puts("checking", table.concat(parsed, ""):indent())
|
lit.puts("checking", table.concat(parsed, ""):indent())
|
||||||
local meta = parsemeta(parsed[1])
|
local meta = parsemeta(parsed[1])
|
||||||
-- TODO:
|
-- TODO
|
||||||
-- meta["code"] = checkcode(parsed[2], meta)
|
-- Add each meta to a variable
|
||||||
-- NOTE: if not valid code, return meta["eval"] = {}
|
-- Remove meta if doesn't pass checkcode
|
||||||
|
meta["code"] = checkcode(parsed[2], meta)
|
||||||
return meta
|
return meta
|
||||||
end
|
end
|
||||||
|
|
||||||
local parsed = lpeg.match(lit.g("block"), codeblock.text)
|
local parsed = lpeg.match(lit.g("declaration"), codeblock.text)
|
||||||
local checked = (parsed ~= nil and check(parsed) or parsed)
|
local checked = (parsed ~= nil and check(parsed) or parsed)
|
||||||
-- TODO:
|
-- TODO:
|
||||||
-- evaluated = eval(checked)
|
-- evaluated = eval(checked)
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
{"pandoc-api-version":[1,23],"meta":{},"blocks":[{"t":"Header","c":[1,["block-override",[],[]],[{"t":"Str","c":"Block"},{"t":"Space"},{"t":"Str","c":"Override"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn1\n...\n1 + 1"]},{"t":"Para","c":[{"t":"Str","c":"Override:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn1\n...\n1 + 2"]},{"t":"Header","c":[1,["block-with-language-and-command",[],[]],[{"t":"Str","c":"Block"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"Language"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"Command"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn4\nlang: python\ncmd: python -E -X utf8\n...\n1 + 1"]},{"t":"Header","c":[1,["block-with-unused-argument",[],[]],[{"t":"Str","c":"Block"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"Unused"},{"t":"Space"},{"t":"Str","c":"Argument"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn3\nargs:\n a: 1\n...\n1 + 1"]}]}
|
{"pandoc-api-version":[1,23],"meta":{},"blocks":[{"t":"Header","c":[1,["declaration-override",[],[]],[{"t":"Str","c":"Declaration"},{"t":"Space"},{"t":"Str","c":"Override"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn1\n...\n1 + 1"]},{"t":"Para","c":[{"t":"Str","c":"Override:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn1\n...\n1 + 2"]},{"t":"Header","c":[1,["declaration-with-language-and-command",[],[]],[{"t":"Str","c":"Declaration"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"Language"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"Command"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn4\nlang: python\ncmd: python -E -X utf8\n...\n1 + 1"]},{"t":"Header","c":[1,["declaration-with-unused-argument",[],[]],[{"t":"Str","c":"Declaration"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"Unused"},{"t":"Space"},{"t":"Str","c":"Argument"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn3\nargs:\n a: 1\n...\n1 + 1"]}]}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Invalid Blocks
|
# Invalid Declarations
|
||||||
|
|
||||||
All errors should be collected, printed and exit with 1.
|
All errors should be collected, printed and exit with 1.
|
||||||
|
|
||||||
|
@ -102,13 +102,6 @@ Misses arg:
|
||||||
...
|
...
|
||||||
#a + #b
|
#a + #b
|
||||||
|
|
||||||
Invalid code:
|
|
||||||
|
|
||||||
---
|
|
||||||
id: fn1
|
|
||||||
...
|
|
||||||
false + false
|
|
||||||
|
|
||||||
Infinite loop:
|
Infinite loop:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -118,7 +111,14 @@ Infinite loop:
|
||||||
...
|
...
|
||||||
#fn1(2) * #x
|
#fn1(2) * #x
|
||||||
|
|
||||||
# Blocks for Invalid Inserts:
|
Invalid code:
|
||||||
|
|
||||||
|
---
|
||||||
|
id: fn1
|
||||||
|
...
|
||||||
|
false + false
|
||||||
|
|
||||||
|
# Declarations With Invalid Calls:
|
||||||
|
|
||||||
---
|
---
|
||||||
id: fn1
|
id: fn1
|
||||||
|
@ -129,7 +129,7 @@ Infinite loop:
|
||||||
...
|
...
|
||||||
#a * #b
|
#a * #b
|
||||||
|
|
||||||
# Invalid Inserts
|
# Invalid Calls
|
||||||
|
|
||||||
- `fn1(` never end
|
- `fn1(` never end
|
||||||
- `fn1(invalid arg)`
|
- `fn1(invalid arg)`
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Inserts Before Blocks
|
# Calls Before Declarations
|
||||||
|
|
||||||
- `fn1()``fn2()`
|
- `fn1()``fn2()`
|
||||||
- `fn3(true)`
|
- `fn3(true)`
|
||||||
|
@ -6,9 +6,10 @@
|
||||||
- `fn3(n: false)`
|
- `fn3(n: false)`
|
||||||
- `fn4(b: 4, a: 5)`
|
- `fn4(b: 4, a: 5)`
|
||||||
|
|
||||||
# Literate Blocks
|
# Declarations
|
||||||
|
|
||||||
All literate blocks should be print on `--verbose`.
|
All literate declarations goes in code blocks that should be printed on
|
||||||
|
`--verbose`.
|
||||||
|
|
||||||
Minimal (Lua by default):
|
Minimal (Lua by default):
|
||||||
|
|
||||||
|
@ -147,14 +148,14 @@ With inner inner function:
|
||||||
...
|
...
|
||||||
#a + #fn4(#a, #fn1())
|
#a + #fn4(#a, #fn1())
|
||||||
|
|
||||||
# Code Blocks
|
# Code Blocks That Are Not Declarations
|
||||||
|
|
||||||
Always ignored:
|
Always ignored:
|
||||||
|
|
||||||
---
|
---
|
||||||
echo "Ignore me!"
|
echo "Ignore me!"
|
||||||
|
|
||||||
# Inserts and Data Types
|
# Calls and Data Types
|
||||||
|
|
||||||
- `fn3(true)`
|
- `fn3(true)`
|
||||||
- `fn3(false)`
|
- `fn3(false)`
|
||||||
|
@ -166,7 +167,7 @@ Always ignored:
|
||||||
- `fn5(1.0)`
|
- `fn5(1.0)`
|
||||||
- `fn5("str")`
|
- `fn5("str")`
|
||||||
|
|
||||||
# Messy Inserts
|
# Messy Calls
|
||||||
|
|
||||||
- `fn1( )`
|
- `fn1( )`
|
||||||
- `fn3("\"str\"")`
|
- `fn3("\"str\"")`
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Block Override
|
# Declaration Override
|
||||||
|
|
||||||
---
|
---
|
||||||
id: fn1
|
id: fn1
|
||||||
|
@ -12,7 +12,7 @@ Override:
|
||||||
...
|
...
|
||||||
1 + 2
|
1 + 2
|
||||||
|
|
||||||
# Block with Language and Command
|
# Declaration with Language and Command
|
||||||
|
|
||||||
---
|
---
|
||||||
id: fn4
|
id: fn4
|
||||||
|
@ -21,7 +21,7 @@ Override:
|
||||||
...
|
...
|
||||||
1 + 1
|
1 + 1
|
||||||
|
|
||||||
# Block with Unused Argument
|
# Declaration with Unused Argument
|
||||||
|
|
||||||
---
|
---
|
||||||
id: fn3
|
id: fn3
|
||||||
|
|
Loading…
Reference in New Issue