From 016f57ef1c7e31ed1aa8ae308f1c84bac50be6d6 Mon Sep 17 00:00:00 2001 From: perro Date: Thu, 15 Jun 2023 17:42:23 -0700 Subject: [PATCH] Starting to checkcode --- dist/lin.bundle.lua | 72 ++++++++++++++++++++----------- dist/lin.min.lua | 72 ++++++++++++++++++++----------- src/literate.lua | 72 ++++++++++++++++++++----------- tests/asts/pass.lit.infos.md.json | 2 +- tests/asts/pass.lit.warns.md.json | 2 +- tests/fail.lit.errors.md | 20 ++++----- tests/pass.lit.infos.md | 13 +++--- tests/pass.lit.warns.md | 6 +-- 8 files changed, 160 insertions(+), 99 deletions(-) diff --git a/dist/lin.bundle.lua b/dist/lin.bundle.lua index 5b7a4f0..6477963 100644 --- a/dist/lin.bundle.lua +++ b/dist/lin.bundle.lua @@ -6577,6 +6577,9 @@ lit.status = true -- Grammars function lit.g(name) + -- Variable for grammars collection + local grammars = {} + -- Lexical elements local newline = lpeg.P"\r"^-1 * lpeg.P"\n" local space = lpeg.S" \t" @@ -6586,20 +6589,24 @@ function lit.g(name) local yamlheader = space^0 * lpeg.P"---" * space^0 * newline local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1 local yamlbody = -yamlfooter * any^0 * newline - -- Still not used 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 = { - -- Block grammar - ["block"] = lpeg.P { - "Block"; - Block = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name"); - YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter); - Code = lpeg.C((any + newline)^0); - }, + -- Declaration grammar + grammars["declaration"] = lpeg.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); } + -- References grammar + grammars["references"] = notref * lpeg.P { + "References"; + References = lpeg.Ct((ref * notref)^0); + } * -1 + return grammars[name] end @@ -6684,7 +6691,7 @@ end -- Examinates (parses and evaluates) document function lit.exam(doc) - -- Evaluates code block + -- Evaluates code declaration -- Evals Lisp code --[[ local function eval(code) @@ -6702,10 +6709,10 @@ function lit.exam(doc) end ]]-- - -- Parses code block + -- Parses code declaration local function parse(codeblock) - -- Checks code block + -- Checks code declarations local function check(parsed) -- Indicates if checks passes @@ -6737,13 +6744,13 @@ function lit.exam(doc) -- Language commands local langcmds = { - ["lua"] = {["int"] = "TODO"}, - ["fennel"] = {["int"] = "TODO"}, - ["python"] = {["ext"] = "TODO"}, - ["js"] = {["ext"] = "TODO"}, - ["ruby"] = {["ext"] = "TODO"}, - ["lisp"] = {["ext"] = "TODO"}, - ["graphviz"] = {["ext"] = "TODO"}, + ["lua"] = {["int_eval"] = { "CMD1", "CMD2", } }, + ["fennel"] = {["int_eval"] = { "CMD1", "CMD2", } }, + ["python"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["js"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["ruby"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["lisp"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["graphviz"] = {["ext_eval"] = { "CMD1", "CMD2", } }, } -- Prints error and does not pass the check @@ -6759,14 +6766,14 @@ function lit.exam(doc) if ispass then if meta["lang"] and meta["cmd"] then 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 meta["lang"] = "lua" meta["eval"] = langcmds["lua"] elseif meta["lang"] and not(meta["cmd"]) then meta["eval"] = langcmds[meta["lang"]] elseif not(meta["lang"]) and meta["cmd"] then - meta["eval"] = {["ext"] = meta["cmd"]} + meta["eval"] = {["ext_eval"] = { meta["cmd"] } } end end return meta @@ -6860,15 +6867,28 @@ function lit.exam(doc) return addeval(meta) 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()) local meta = parsemeta(parsed[1]) - -- TODO: - -- meta["code"] = checkcode(parsed[2], meta) - -- NOTE: if not valid code, return meta["eval"] = {} + -- TODO + -- Add each meta to a variable + -- Remove meta if doesn't pass checkcode + meta["code"] = checkcode(parsed[2], meta) return meta 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) -- TODO: -- evaluated = eval(checked) diff --git a/dist/lin.min.lua b/dist/lin.min.lua index 7237b8e..3d9dd10 100644 --- a/dist/lin.min.lua +++ b/dist/lin.min.lua @@ -20,6 +20,9 @@ lit.status = true -- Grammars function lit.g(name) + -- Variable for grammars collection + local grammars = {} + -- Lexical elements local newline = lpeg.P"\r"^-1 * lpeg.P"\n" local space = lpeg.S" \t" @@ -29,20 +32,24 @@ function lit.g(name) local yamlheader = space^0 * lpeg.P"---" * space^0 * newline local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1 local yamlbody = -yamlfooter * any^0 * newline - -- Still not used 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 = { - -- Block grammar - ["block"] = lpeg.P { - "Block"; - Block = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name"); - YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter); - Code = lpeg.C((any + newline)^0); - }, + -- Declaration grammar + grammars["declaration"] = lpeg.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); } + -- References grammar + grammars["references"] = notref * lpeg.P { + "References"; + References = lpeg.Ct((ref * notref)^0); + } * -1 + return grammars[name] end @@ -127,7 +134,7 @@ end -- Examinates (parses and evaluates) document function lit.exam(doc) - -- Evaluates code block + -- Evaluates code declaration -- Evals Lisp code --[[ local function eval(code) @@ -145,10 +152,10 @@ function lit.exam(doc) end ]]-- - -- Parses code block + -- Parses code declaration local function parse(codeblock) - -- Checks code block + -- Checks code declarations local function check(parsed) -- Indicates if checks passes @@ -180,13 +187,13 @@ function lit.exam(doc) -- Language commands local langcmds = { - ["lua"] = {["int"] = "TODO"}, - ["fennel"] = {["int"] = "TODO"}, - ["python"] = {["ext"] = "TODO"}, - ["js"] = {["ext"] = "TODO"}, - ["ruby"] = {["ext"] = "TODO"}, - ["lisp"] = {["ext"] = "TODO"}, - ["graphviz"] = {["ext"] = "TODO"}, + ["lua"] = {["int_eval"] = { "CMD1", "CMD2", } }, + ["fennel"] = {["int_eval"] = { "CMD1", "CMD2", } }, + ["python"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["js"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["ruby"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["lisp"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["graphviz"] = {["ext_eval"] = { "CMD1", "CMD2", } }, } -- Prints error and does not pass the check @@ -202,14 +209,14 @@ function lit.exam(doc) if ispass then if meta["lang"] and meta["cmd"] then 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 meta["lang"] = "lua" meta["eval"] = langcmds["lua"] elseif meta["lang"] and not(meta["cmd"]) then meta["eval"] = langcmds[meta["lang"]] elseif not(meta["lang"]) and meta["cmd"] then - meta["eval"] = {["ext"] = meta["cmd"]} + meta["eval"] = {["ext_eval"] = { meta["cmd"] } } end end return meta @@ -303,15 +310,28 @@ function lit.exam(doc) return addeval(meta) 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()) local meta = parsemeta(parsed[1]) - -- TODO: - -- meta["code"] = checkcode(parsed[2], meta) - -- NOTE: if not valid code, return meta["eval"] = {} + -- TODO + -- Add each meta to a variable + -- Remove meta if doesn't pass checkcode + meta["code"] = checkcode(parsed[2], meta) return meta 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) -- TODO: -- evaluated = eval(checked) diff --git a/src/literate.lua b/src/literate.lua index 94fb9a2..61894d3 100644 --- a/src/literate.lua +++ b/src/literate.lua @@ -9,6 +9,9 @@ lit.status = true -- Grammars function lit.g(name) + -- Variable for grammars collection + local grammars = {} + -- Lexical elements local newline = lpeg.P"\r"^-1 * lpeg.P"\n" local space = lpeg.S" \t" @@ -18,20 +21,24 @@ function lit.g(name) local yamlheader = space^0 * lpeg.P"---" * space^0 * newline local yamlfooter = space^0 * lpeg.P"..." * space^0 * newline^-1 local yamlbody = -yamlfooter * any^0 * newline - -- Still not used 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 = { - -- Block grammar - ["block"] = lpeg.P { - "Block"; - Block = lpeg.Ct(lpeg.V"YAML" * lpeg.V"Code", "name"); - YAML = lpeg.C(yamlheader * yamlbody^0 * yamlfooter); - Code = lpeg.C((any + newline)^0); - }, + -- Declaration grammar + grammars["declaration"] = lpeg.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); } + -- References grammar + grammars["references"] = notref * lpeg.P { + "References"; + References = lpeg.Ct((ref * notref)^0); + } * -1 + return grammars[name] end @@ -75,7 +82,7 @@ end -- Examinates (parses and evaluates) document function lit.exam(doc) - -- Evaluates code block + -- Evaluates code declaration -- Evals Lisp code --[[ local function eval(code) @@ -93,10 +100,10 @@ function lit.exam(doc) end ]]-- - -- Parses code block + -- Parses code declaration local function parse(codeblock) - -- Checks code block + -- Checks code declarations local function check(parsed) -- Indicates if checks passes @@ -128,13 +135,13 @@ function lit.exam(doc) -- Language commands local langcmds = { - ["lua"] = {["int"] = "TODO"}, - ["fennel"] = {["int"] = "TODO"}, - ["python"] = {["ext"] = "TODO"}, - ["js"] = {["ext"] = "TODO"}, - ["ruby"] = {["ext"] = "TODO"}, - ["lisp"] = {["ext"] = "TODO"}, - ["graphviz"] = {["ext"] = "TODO"}, + ["lua"] = {["int_eval"] = { "CMD1", "CMD2", } }, + ["fennel"] = {["int_eval"] = { "CMD1", "CMD2", } }, + ["python"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["js"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["ruby"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["lisp"] = {["ext_eval"] = { "CMD1", "CMD2", } }, + ["graphviz"] = {["ext_eval"] = { "CMD1", "CMD2", } }, } -- Prints error and does not pass the check @@ -150,14 +157,14 @@ function lit.exam(doc) if ispass then if meta["lang"] and meta["cmd"] then 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 meta["lang"] = "lua" meta["eval"] = langcmds["lua"] elseif meta["lang"] and not(meta["cmd"]) then meta["eval"] = langcmds[meta["lang"]] elseif not(meta["lang"]) and meta["cmd"] then - meta["eval"] = {["ext"] = meta["cmd"]} + meta["eval"] = {["ext_eval"] = { meta["cmd"] } } end end return meta @@ -251,15 +258,28 @@ function lit.exam(doc) return addeval(meta) 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()) local meta = parsemeta(parsed[1]) - -- TODO: - -- meta["code"] = checkcode(parsed[2], meta) - -- NOTE: if not valid code, return meta["eval"] = {} + -- TODO + -- Add each meta to a variable + -- Remove meta if doesn't pass checkcode + meta["code"] = checkcode(parsed[2], meta) return meta 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) -- TODO: -- evaluated = eval(checked) diff --git a/tests/asts/pass.lit.infos.md.json b/tests/asts/pass.lit.infos.md.json index f2cea78..bfb020d 100644 --- a/tests/asts/pass.lit.infos.md.json +++ b/tests/asts/pass.lit.infos.md.json @@ -1 +1 @@ -{"pandoc-api-version":[1,23],"meta":{},"blocks":[{"t":"Header","c":[1,["inserts-before-blocks",[],[]],[{"t":"Str","c":"Inserts"},{"t":"Space"},{"t":"Str","c":"Before"},{"t":"Space"},{"t":"Str","c":"Blocks"}]]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn1()``fn2()"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(true)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4(2.0, 3.1)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(n: false)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4(b: 4, a: 5)"]}]}]]},{"t":"Header","c":[1,["literate-blocks",[],[]],[{"t":"Str","c":"Literate"},{"t":"Space"},{"t":"Str","c":"Blocks"}]]},{"t":"Para","c":[{"t":"Str","c":"All"},{"t":"Space"},{"t":"Str","c":"literate"},{"t":"Space"},{"t":"Str","c":"blocks"},{"t":"Space"},{"t":"Str","c":"should"},{"t":"Space"},{"t":"Str","c":"be"},{"t":"Space"},{"t":"Str","c":"print"},{"t":"Space"},{"t":"Str","c":"on"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"--verbose"]},{"t":"Str","c":"."}]},{"t":"Para","c":[{"t":"Str","c":"Minimal"},{"t":"Space"},{"t":"Str","c":"(Lua"},{"t":"Space"},{"t":"Str","c":"by"},{"t":"Space"},{"t":"Str","c":"default):"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn1\n...\n1 + 2 + 3"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"scape:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn2\n...\n\"\\#x\""]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"arg:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn3\nargs:\n n: str\n...\n#n == #n"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"lang"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"args:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn4\nlang: fennel\nargs:\n a: 1\n b: 2\n...\n(* #a #b)"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"cmd"},{"t":"Space"},{"t":"Str","c":"(ignores"},{"t":"Space"},{"t":"Str","c":"lang):"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn5\ncmd: python -E -X utf8\nargs:\n n: 2\n...\n#n + #n"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"shift:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn6\nshift: true\n...\n\"The literate block is shifted by its eval result.\""]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"wipe:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn7\nwipe: true\n...\n\"This evals but it is wipe from doc.\""]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"typed:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn4\ntyped: true\nargs:\n a: 1\n b: 2\n...\n#a * #b"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"link"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"alt:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn8\nlang: graphviz\nlink: ./graph.png\nalt: A graph. \n...\ndigraph G {\n a -> b;\n b -> c\n c -> a;\n}"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"img"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"alt:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn9\nlang: graphviz\nimg: ./graph.png\nalt: A graph. \n...\ndigraph G {\n a -> b;\n b -> c\n c -> a;\n}"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"dump"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"quote:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn10\ndump: ./dump.txt\nquote: true\n...\nThis code is saved into './dump.txt' because of 'dump'.\nThis code is not evaluated because 'quote' is true."]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"inner"},{"t":"Space"},{"t":"Str","c":"function:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn11\nargs:\n x: 2 \n...\n#fn1() * x"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"inner"},{"t":"Space"},{"t":"Str","c":"function"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"args:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn12\nargs: \n y: 1\n z: 2\n...\n#y + #fn4(3, 4) + #z"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"inner"},{"t":"Space"},{"t":"Str","c":"inner"},{"t":"Space"},{"t":"Str","c":"function:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn13\nargs:\n a: 1\n...\n#a + #fn4(#a, #fn1())"]},{"t":"Header","c":[1,["code-blocks",[],[]],[{"t":"Str","c":"Code"},{"t":"Space"},{"t":"Str","c":"Blocks"}]]},{"t":"Para","c":[{"t":"Str","c":"Always"},{"t":"Space"},{"t":"Str","c":"ignored:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\necho \"Ignore me!\""]},{"t":"Header","c":[1,["inserts-and-data-types",[],[]],[{"t":"Str","c":"Inserts"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"Types"}]]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(true)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(false)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3([])"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3([0, 1])"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3({})"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3({\"k1\": 1, \"k2\": 2})"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4(3)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn5(1.0)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn5(\"str\")"]}]}]]},{"t":"Header","c":[1,["messy-inserts",[],[]],[{"t":"Str","c":"Messy"},{"t":"Space"},{"t":"Str","c":"Inserts"}]]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn1( )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(\"\\\"str\\\"\")"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3( 4)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(5 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3( 6 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3( n: 7)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(n: 8 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3( n: 9 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(n:10)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 6, b: 7)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 8 , b: 9)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 10 , b: 11)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 12 , b: 13)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 14 , b: 15 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4(a:16,b:17)"]}]}]]}]} +{"pandoc-api-version":[1,23],"meta":{},"blocks":[{"t":"Header","c":[1,["calls-before-declarations",[],[]],[{"t":"Str","c":"Calls"},{"t":"Space"},{"t":"Str","c":"Before"},{"t":"Space"},{"t":"Str","c":"Declarations"}]]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn1()``fn2()"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(true)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4(2.0, 3.1)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(n: false)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4(b: 4, a: 5)"]}]}]]},{"t":"Header","c":[1,["declarations",[],[]],[{"t":"Str","c":"Declarations"}]]},{"t":"Para","c":[{"t":"Str","c":"All"},{"t":"Space"},{"t":"Str","c":"literate"},{"t":"Space"},{"t":"Str","c":"declarations"},{"t":"Space"},{"t":"Str","c":"goes"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"code"},{"t":"Space"},{"t":"Str","c":"blocks"},{"t":"Space"},{"t":"Str","c":"that"},{"t":"Space"},{"t":"Str","c":"should"},{"t":"Space"},{"t":"Str","c":"be"},{"t":"Space"},{"t":"Str","c":"printed"},{"t":"Space"},{"t":"Str","c":"on"},{"t":"SoftBreak"},{"t":"Code","c":[["",[],[]],"--verbose"]},{"t":"Str","c":"."}]},{"t":"Para","c":[{"t":"Str","c":"Minimal"},{"t":"Space"},{"t":"Str","c":"(Lua"},{"t":"Space"},{"t":"Str","c":"by"},{"t":"Space"},{"t":"Str","c":"default):"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn1\n...\n1 + 2 + 3"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"scape:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn2\n...\n\"\\#x\""]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"arg:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn3\nargs:\n n: str\n...\n#n == #n"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"lang"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"args:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn4\nlang: fennel\nargs:\n a: 1\n b: 2\n...\n(* #a #b)"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"cmd"},{"t":"Space"},{"t":"Str","c":"(ignores"},{"t":"Space"},{"t":"Str","c":"lang):"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn5\ncmd: python -E -X utf8\nargs:\n n: 2\n...\n#n + #n"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"shift:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn6\nshift: true\n...\n\"The literate block is shifted by its eval result.\""]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"wipe:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn7\nwipe: true\n...\n\"This evals but it is wipe from doc.\""]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"typed:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn4\ntyped: true\nargs:\n a: 1\n b: 2\n...\n#a * #b"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"link"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"alt:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn8\nlang: graphviz\nlink: ./graph.png\nalt: A graph. \n...\ndigraph G {\n a -> b;\n b -> c\n c -> a;\n}"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"img"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"alt:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn9\nlang: graphviz\nimg: ./graph.png\nalt: A graph. \n...\ndigraph G {\n a -> b;\n b -> c\n c -> a;\n}"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"dump"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"quote:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn10\ndump: ./dump.txt\nquote: true\n...\nThis code is saved into './dump.txt' because of 'dump'.\nThis code is not evaluated because 'quote' is true."]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"inner"},{"t":"Space"},{"t":"Str","c":"function:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn11\nargs:\n x: 2 \n...\n#fn1() * x"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"inner"},{"t":"Space"},{"t":"Str","c":"function"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"args:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn12\nargs: \n y: 1\n z: 2\n...\n#y + #fn4(3, 4) + #z"]},{"t":"Para","c":[{"t":"Str","c":"With"},{"t":"Space"},{"t":"Str","c":"inner"},{"t":"Space"},{"t":"Str","c":"inner"},{"t":"Space"},{"t":"Str","c":"function:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn13\nargs:\n a: 1\n...\n#a + #fn4(#a, #fn1())"]},{"t":"Header","c":[1,["code-blocks-that-are-not-declarations",[],[]],[{"t":"Str","c":"Code"},{"t":"Space"},{"t":"Str","c":"Blocks"},{"t":"Space"},{"t":"Str","c":"That"},{"t":"Space"},{"t":"Str","c":"Are"},{"t":"Space"},{"t":"Str","c":"Not"},{"t":"Space"},{"t":"Str","c":"Declarations"}]]},{"t":"Para","c":[{"t":"Str","c":"Always"},{"t":"Space"},{"t":"Str","c":"ignored:"}]},{"t":"CodeBlock","c":[["",[],[]],"---\necho \"Ignore me!\""]},{"t":"Header","c":[1,["calls-and-data-types",[],[]],[{"t":"Str","c":"Calls"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"Types"}]]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(true)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(false)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3([])"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3([0, 1])"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3({})"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3({\"k1\": 1, \"k2\": 2})"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4(3)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn5(1.0)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn5(\"str\")"]}]}]]},{"t":"Header","c":[1,["messy-calls",[],[]],[{"t":"Str","c":"Messy"},{"t":"Space"},{"t":"Str","c":"Calls"}]]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn1( )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(\"\\\"str\\\"\")"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3( 4)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(5 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3( 6 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3( n: 7)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(n: 8 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3( n: 9 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn3(n:10)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 6, b: 7)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 8 , b: 9)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 10 , b: 11)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 12 , b: 13)"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4( a: 14 , b: 15 )"]}]}],[{"t":"Plain","c":[{"t":"Code","c":[["",[],[]],"fn4(a:16,b:17)"]}]}]]}]} diff --git a/tests/asts/pass.lit.warns.md.json b/tests/asts/pass.lit.warns.md.json index 3dd3446..e16d7ef 100644 --- a/tests/asts/pass.lit.warns.md.json +++ b/tests/asts/pass.lit.warns.md.json @@ -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"]}]} diff --git a/tests/fail.lit.errors.md b/tests/fail.lit.errors.md index f0512ed..01031f4 100644 --- a/tests/fail.lit.errors.md +++ b/tests/fail.lit.errors.md @@ -1,4 +1,4 @@ -# Invalid Blocks +# Invalid Declarations All errors should be collected, printed and exit with 1. @@ -102,13 +102,6 @@ Misses arg: ... #a + #b -Invalid code: - - --- - id: fn1 - ... - false + false - Infinite loop: --- @@ -118,7 +111,14 @@ Infinite loop: ... #fn1(2) * #x -# Blocks for Invalid Inserts: +Invalid code: + + --- + id: fn1 + ... + false + false + +# Declarations With Invalid Calls: --- id: fn1 @@ -129,7 +129,7 @@ Infinite loop: ... #a * #b -# Invalid Inserts +# Invalid Calls - `fn1(` never end - `fn1(invalid arg)` diff --git a/tests/pass.lit.infos.md b/tests/pass.lit.infos.md index 8abcf56..1e026b3 100644 --- a/tests/pass.lit.infos.md +++ b/tests/pass.lit.infos.md @@ -1,4 +1,4 @@ -# Inserts Before Blocks +# Calls Before Declarations - `fn1()``fn2()` - `fn3(true)` @@ -6,9 +6,10 @@ - `fn3(n: false)` - `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): @@ -147,14 +148,14 @@ With inner inner function: ... #a + #fn4(#a, #fn1()) -# Code Blocks +# Code Blocks That Are Not Declarations Always ignored: --- echo "Ignore me!" -# Inserts and Data Types +# Calls and Data Types - `fn3(true)` - `fn3(false)` @@ -166,7 +167,7 @@ Always ignored: - `fn5(1.0)` - `fn5("str")` -# Messy Inserts +# Messy Calls - `fn1( )` - `fn3("\"str\"")` diff --git a/tests/pass.lit.warns.md b/tests/pass.lit.warns.md index 1a12330..c30b96b 100644 --- a/tests/pass.lit.warns.md +++ b/tests/pass.lit.warns.md @@ -1,4 +1,4 @@ -# Block Override +# Declaration Override --- id: fn1 @@ -12,7 +12,7 @@ Override: ... 1 + 2 -# Block with Language and Command +# Declaration with Language and Command --- id: fn4 @@ -21,7 +21,7 @@ Override: ... 1 + 1 -# Block with Unused Argument +# Declaration with Unused Argument --- id: fn3