From 6158168a97226b21187e98fb457ee88b1d5d1be3 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Tue, 29 Mar 2016 21:35:07 -0700 Subject: [PATCH] Grammar support for priorities --- userspace/digwatch/lua/compiler.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/userspace/digwatch/lua/compiler.lua b/userspace/digwatch/lua/compiler.lua index f2cc3555..7ba40ed3 100644 --- a/userspace/digwatch/lua/compiler.lua +++ b/userspace/digwatch/lua/compiler.lua @@ -155,6 +155,18 @@ end -- grammar +local function normalize_level(level) + valid_levels = {"emergency", "alert", "critical", "error", "warning", "notice", "informational", "debug"} + level = string.lower(level) + for i,v in ipairs(valid_levels) do + if (string.find(v, "^"..level)) then + return v + end + end + error("Invalid severity level: "..level) +end + + local function filter(e) return {type = "Filter", value=e} end @@ -163,12 +175,12 @@ local function macro (name, filter) return {type = "MacroDef", name = name, value = filter} end -local function outputformat (format) - return {type = "OutputFormat", value = format} +local function outputformat (level, format) + return {type = "OutputFormat", level = normalize_level(level), value = format} end -local function functioncall (str, mname, fname, args) - return {type = "FunctionCall", mname = mname, fname = fname, arguments = args, source = str} +local function functioncall (level, str, mname, fname, args) + return {type = "FunctionCall", level = normalize_level(level), mname = mname, fname = fname, arguments = args, source = str} end local function rule(filter, output) @@ -217,7 +229,7 @@ local G = { MacroDef = (C(V"Macro") * V"Skip" * V"Colon" * (V"Filter")); FuncArgs = symb("(") * list(V"Value", symb(",")) * symb(")"); - Output = (C(V"Name" * P(".") * V"Name" * V"FuncArgs") / functioncall) + P(1)^0 / outputformat; + Output = (C(V"Identifier") * V"Skip" * C(V"Name" * P(".") * V"Name" * V"FuncArgs") / functioncall) + (C(V"Identifier") * V"Skip" * C(P(1)^0) / outputformat); -- Terminals Value = terminal "Number" + terminal "String" + terminal "BareString";