mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-05 19:06:44 +00:00
Scaffold basic line-oriented compiler API
This commit is contained in:
parent
0d10a3f39c
commit
aeba0760db
@ -13,7 +13,8 @@
|
||||
|
||||
--]]
|
||||
|
||||
local parser = {}
|
||||
local compiler = {}
|
||||
compiler.parser = {}
|
||||
|
||||
local lpeg = require "lpeg"
|
||||
|
||||
@ -340,15 +341,44 @@ end
|
||||
|
||||
|
||||
|
||||
function parser.parse (subject)
|
||||
--[[
|
||||
Parses a single line (which should be either a macro definition or a filter) and returns the AST.
|
||||
--]]
|
||||
function compiler.parser.parseline (subject)
|
||||
local errorinfo = { subject = subject }
|
||||
lpeg.setmaxstack(1000)
|
||||
local ast, error_msg = lpeg.match(G, subject, nil, errorinfo)
|
||||
if (error_msg) then
|
||||
return ast, error_msg
|
||||
end
|
||||
expand_in(ast)
|
||||
return ast, error_msg
|
||||
end
|
||||
|
||||
return parser
|
||||
|
||||
--[[
|
||||
Sets up compiler state and returns it.
|
||||
|
||||
This is an opaque blob that is passed into subsequent compiler calls and
|
||||
should not be modified by the client.
|
||||
|
||||
It holds state such as macro definitions that must be kept across calls
|
||||
to the line-oriented compiler.
|
||||
--]]
|
||||
function compiler.init()
|
||||
return {}
|
||||
end
|
||||
|
||||
--[[
|
||||
Compiles a digwatch filter or macro
|
||||
--]]
|
||||
function compiler.compile_line(line, state)
|
||||
ast, error_message = compiler.parser.parseline(line)
|
||||
|
||||
if (error_msg) then
|
||||
return {}, state, error_msg
|
||||
end
|
||||
expand_in(ast)
|
||||
-- extract_macros(ast, state)
|
||||
-- expand_macros(ast, state)
|
||||
return ast, state, error_msg
|
||||
end
|
||||
|
||||
|
||||
return compiler
|
||||
|
@ -1,11 +1,13 @@
|
||||
local parser = require "sysdig-parser"
|
||||
local compiler = require "sysdig-parser"
|
||||
|
||||
if #arg ~= 1 then
|
||||
print("Usage: test.lua <string>")
|
||||
os.exit(1)
|
||||
end
|
||||
|
||||
local ast, error_msg = parser.parse(arg[1])
|
||||
local state = compiler.init()
|
||||
|
||||
local ast, state, error_msg = compiler.compile_line(arg[1], state)
|
||||
if not ast then
|
||||
os.exit(1)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user