compiler.lua: Move macro checking into own file

This commit is contained in:
Henri DF
2016-02-24 09:03:55 -08:00
parent a2ec9870de
commit 5f43446bfa
2 changed files with 22 additions and 16 deletions

View File

@@ -420,6 +420,23 @@ function get_macros(ast, set)
return set
end
function check_macros(ast)
local macros
if (ast.type == "Rule") then
macros = get_macros(ast.filter, {})
elseif (ast.type == "MacroDef") then
macros = get_macros(ast.value, {})
else
error ("Unexpected type: "..t)
end
for m, _ in pairs(macros) do
if macros[m] == nil then
error ("Undefined macro '"..m.."' used in '"..line.."'")
end
end
end
function print_ast(ast, level)
local t = ast.type
level = level or 0
@@ -491,20 +508,8 @@ function compiler.compile_line(line, macro_defs)
return {}
end
local macros
if (ast.type == "Rule") then
macros = get_macros(ast.filter, {})
elseif (ast.type == "MacroDef") then
macros = get_macros(ast.value, {})
else
error ("Unexpected type: "..t)
end
for m, _ in pairs(macros) do
if macros[m] == nil then
error ("Undefined macro '"..m.."' used in '"..line.."'")
end
end
-- check that any macros used have already been defined
check_macros(ast)
if (ast.type == "MacroDef") then
-- Parsed line is a macro definition, so update our dictionary of macros and

View File

@@ -2,13 +2,13 @@
function error_exit_good
{
echo "Error: '$1' did not parse" 1>&2
echo "Error: '$1' did not compiler" 1>&2
exit 1
}
function error_exit_bad
{
echo "Error: incorrect filter '$1' parsed ok" 1>&2
echo "Error: incorrect filter '$1' compiler ok" 1>&2
exit 1
}
@@ -72,6 +72,7 @@ good "a : evt.dir=>"
good "inbound: (syscall.type=listen and evt.dir='>') or (syscall.type=accept and evt.dir='<')"
bad "a:"
bad "a : b | bla"
bad "b and d"
echo