Fixed invocation function to canonicalize better and play nice with "'"
This commit is contained in:
parent
e8dd820b8c
commit
be55821244
14
core.nom
14
core.nom
@ -196,7 +196,7 @@ macro ["%item is in %list", "%list contains %item"]:
|
|||||||
".."|(\%list as lua expr\[\%index as lua expr\] ~= nil)
|
".."|(\%list as lua expr\[\%index as lua expr\] ~= nil)
|
||||||
|
|
||||||
macro ["length of %list", "size of %list", "number of %list"]:
|
macro ["length of %list", "size of %list", "number of %list"]:
|
||||||
".."|#(\list as lua expr\)
|
".."|#(\%list as lua expr\)
|
||||||
|
|
||||||
rule "dict %items":
|
rule "dict %items":
|
||||||
let "dict" = []
|
let "dict" = []
|
||||||
@ -206,8 +206,8 @@ rule "dict %items":
|
|||||||
|
|
||||||
rule "restrict %fn to within %whitelist":
|
rule "restrict %fn to within %whitelist":
|
||||||
lua block ".."
|
lua block ".."
|
||||||
|local fns = (type(vars.fn) == 'string') and {vars.fn} or vars.fn
|
|local fns = compiler:get_invocations(vars.fn)
|
||||||
|local whitelist = (type(vars.whitelist) == 'string') and {vars.whitelist} or vars.whitelist
|
|local whitelist = compiler:get_invocations(vars.whitelist)
|
||||||
|local whiteset = {}
|
|local whiteset = {}
|
||||||
|for _,w in ipairs(whitelist) do
|
|for _,w in ipairs(whitelist) do
|
||||||
| if not compiler.defs[w] then
|
| if not compiler.defs[w] then
|
||||||
@ -228,8 +228,8 @@ rule "restrict %fn to within %whitelist":
|
|||||||
|
|
||||||
rule "allow %whitelist to use %fn":
|
rule "allow %whitelist to use %fn":
|
||||||
lua block ".."
|
lua block ".."
|
||||||
|local fns = (type(vars.fn) == 'string') and {vars.fn} or vars.fn
|
|local fns = compiler:get_invocations(vars.fn)
|
||||||
|local whitelist = (type(vars.whitelist) == 'string') and {vars.whitelist} or vars.whitelist
|
|local whitelist = compiler:get_invocations(vars.whitelist)
|
||||||
|for _,w in ipairs(whitelist) do
|
|for _,w in ipairs(whitelist) do
|
||||||
| if not compiler.defs[w] then
|
| if not compiler.defs[w] then
|
||||||
| compiler:error("Undefined function: "..tostring(w))
|
| compiler:error("Undefined function: "..tostring(w))
|
||||||
@ -252,8 +252,8 @@ rule "allow %whitelist to use %fn":
|
|||||||
|
|
||||||
rule "forbid %blacklist to use %fn":
|
rule "forbid %blacklist to use %fn":
|
||||||
lua block ".."
|
lua block ".."
|
||||||
|local fns = (type(vars.fn) == 'string') and {vars.fn} or vars.fn
|
|local fns = compiler:get_invocations(vars.fn)
|
||||||
|local blacklist = (type(vars.blacklist) == 'string') and {vars.blacklist} or vars.blacklist
|
|local blacklist = compiler:get_invocations(vars.blacklist)
|
||||||
|for _,b in ipairs(blacklist) do
|
|for _,b in ipairs(blacklist) do
|
||||||
| if not compiler.defs[b] then
|
| if not compiler.defs[b] then
|
||||||
| compiler:error("Undefined function: "..tostring(b))
|
| compiler:error("Undefined function: "..tostring(b))
|
||||||
|
@ -208,12 +208,12 @@ do
|
|||||||
local arg_names
|
local arg_names
|
||||||
for _index_0 = 1, #text do
|
for _index_0 = 1, #text do
|
||||||
local _text = text[_index_0]
|
local _text = text[_index_0]
|
||||||
local invocation = _text:gsub("%%%S+", "%%")
|
local invocation = _text:gsub("'", " '"):gsub("%%%S+", "%%"):gsub("%s+", " ")
|
||||||
local _arg_names
|
local _arg_names
|
||||||
do
|
do
|
||||||
local _accum_0 = { }
|
local _accum_0 = { }
|
||||||
local _len_0 = 1
|
local _len_0 = 1
|
||||||
for arg in _text:gmatch("%%(%S+)") do
|
for arg in _text:gmatch("%%(%S[^%s']*)") do
|
||||||
_accum_0[_len_0] = arg
|
_accum_0[_len_0] = arg
|
||||||
_len_0 = _len_0 + 1
|
_len_0 = _len_0 + 1
|
||||||
end
|
end
|
||||||
|
@ -138,8 +138,8 @@ class NomsuCompiler
|
|||||||
invocations = {}
|
invocations = {}
|
||||||
local arg_names
|
local arg_names
|
||||||
for _text in *text
|
for _text in *text
|
||||||
invocation = _text\gsub("%%%S+","%%")
|
invocation = _text\gsub("'"," '")\gsub("%%%S+","%%")\gsub("%s+"," ")
|
||||||
_arg_names = [arg for arg in _text\gmatch("%%(%S+)")]
|
_arg_names = [arg for arg in _text\gmatch("%%(%S[^%s']*)")]
|
||||||
table.insert(invocations, invocation)
|
table.insert(invocations, invocation)
|
||||||
if arg_names
|
if arg_names
|
||||||
if not utils.equivalent(utils.set(arg_names), utils.set(_arg_names))
|
if not utils.equivalent(utils.set(arg_names), utils.set(_arg_names))
|
||||||
|
Loading…
Reference in New Issue
Block a user