From a33a4e8718b58780b96046b827978258a5fe24d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20W=C5=82odarczyk?= Date: Fri, 4 Jan 2019 18:02:27 +0100 Subject: [PATCH 1/5] merged with class loader --- loaders/classes/process_content.lua | 4 ---- loaders/classes/process_files.lua | 4 ---- 2 files changed, 8 deletions(-) diff --git a/loaders/classes/process_content.lua b/loaders/classes/process_content.lua index 2734cae..74bdb3e 100644 --- a/loaders/classes/process_content.lua +++ b/loaders/classes/process_content.lua @@ -1,8 +1,4 @@ -<<<<<<< HEAD function classes_loader.process_content(theme, filename, elem, classes) -======= -function classes_loader.process_content(theme, filename) ->>>>>>> 810b3c992a10cd1fabd90152238beace02937a30 local content = theme.files[filename] -- Execute the sustitution diff --git a/loaders/classes/process_files.lua b/loaders/classes/process_files.lua index 29f71ce..cfdb8ee 100644 --- a/loaders/classes/process_files.lua +++ b/loaders/classes/process_files.lua @@ -9,11 +9,7 @@ function classes_loader.process_files(theme) local dir, basename, elem = matches:get(1), matches:get(2), matches:get(3) local filename = classes_loader.get_filename(dir, basename) -<<<<<<< HEAD classes_loader.process_content(theme, filename, elem, classes) -======= - classes_loader.process_content(theme, filename) ->>>>>>> 810b3c992a10cd1fabd90152238beace02937a30 end end From 7ede6175351a513e0baccb25b32146bf2c7b374e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20W=C5=82odarczyk?= Date: Fri, 18 Jan 2019 23:38:40 +0100 Subject: [PATCH 2/5] unified preprocessing functions parameters --- loaders/actions.lua | 4 +++- loaders/actions/custom_require.lua | 8 ++++---- loaders/actions/set_priority.lua | 2 +- loaders/actions/write_events.lua | 2 +- loaders/actions/write_input_parameters.lua | 2 +- loaders/actions/write_return.lua | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/loaders/actions.lua b/loaders/actions.lua index 38637df..8e774e0 100644 --- a/loaders/actions.lua +++ b/loaders/actions.lua @@ -1,4 +1,6 @@ -actions_loader = { } +actions_loader = { + preprocessors = {} +} require("loaders.actions.mod") diff --git a/loaders/actions/custom_require.lua b/loaders/actions/custom_require.lua index a9807d5..347967e 100644 --- a/loaders/actions/custom_require.lua +++ b/loaders/actions/custom_require.lua @@ -9,11 +9,11 @@ function actions_loader.custom_require(name) if file then local header = actions_loader.extract_header(modulepath) - actions_loader.write_events(created_file, header) - actions_loader.set_priority(created_file, header) - actions_loader.write_input_parameters(created_file, header) + actions_loader.write_events(created_file, header, modulepath) + actions_loader.set_priority(created_file, header, modulepath) + actions_loader.write_input_parameters(created_file, header, modulepath) actions_loader.write_function(created_file, header, modulepath) - actions_loader.write_return(created_file, header) + actions_loader.write_return(created_file, header, modulepath) created_file:close() -- Compile and return the module diff --git a/loaders/actions/set_priority.lua b/loaders/actions/set_priority.lua index 708d305..b37d00a 100644 --- a/loaders/actions/set_priority.lua +++ b/loaders/actions/set_priority.lua @@ -1,3 +1,3 @@ -function actions_loader.set_priority (created_file, header) +function actions_loader.set_priority (created_file, header, modulepath) created_file:write("\nlocal priority = " .. header.priority .. " \n\n") end diff --git a/loaders/actions/write_events.lua b/loaders/actions/write_events.lua index ed95638..713a5bf 100644 --- a/loaders/actions/write_events.lua +++ b/loaders/actions/write_events.lua @@ -1,4 +1,4 @@ -function actions_loader.write_events (created_file, header) +function actions_loader.write_events (created_file, header, modulepath) created_file:write("local event = { \"" .. header.event[1] .. "\"") -- put values from yaml in lua form for _, yaml_event in ipairs(header.event) do if yaml_event ~= header.event[1] then diff --git a/loaders/actions/write_input_parameters.lua b/loaders/actions/write_input_parameters.lua index 2963951..ee1e551 100644 --- a/loaders/actions/write_input_parameters.lua +++ b/loaders/actions/write_input_parameters.lua @@ -1,4 +1,4 @@ -function actions_loader.write_input_parameters (created_file, header) +function actions_loader.write_input_parameters (created_file, header, modulepath) if header.input_parameters[1] then created_file:write("local input_parameters = { " .. "\"" .. header.input_parameters[1] .. "\"") for k, v in pairs(header.input_parameters) do diff --git a/loaders/actions/write_return.lua b/loaders/actions/write_return.lua index 1da1169..993e3d0 100644 --- a/loaders/actions/write_return.lua +++ b/loaders/actions/write_return.lua @@ -1,3 +1,3 @@ -function actions_loader.write_return (created_file, header) +function actions_loader.write_return (created_file, header, modulepath) created_file:write("\n\nreturn{\n\tevent = event,\n\taction = action,\n\tpriority = priority,\n\tinput_parameters = input_parameters\n}") -- ending return end From 9e5cf15c0c2d940472dbf67b6b3ac5fa795ab646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20W=C5=82odarczyk?= Date: Fri, 18 Jan 2019 23:49:15 +0100 Subject: [PATCH 3/5] created preprocessors table for actions and added functions --- loaders/actions/add_preprocessor.lua | 3 +++ loaders/actions/mod.lua | 1 + loaders/actions/set_priority.lua | 2 ++ loaders/actions/write_events.lua | 2 ++ loaders/actions/write_function.lua | 2 ++ loaders/actions/write_input_parameters.lua | 2 ++ loaders/actions/write_return.lua | 2 ++ 7 files changed, 14 insertions(+) create mode 100644 loaders/actions/add_preprocessor.lua diff --git a/loaders/actions/add_preprocessor.lua b/loaders/actions/add_preprocessor.lua new file mode 100644 index 0000000..84a7ef2 --- /dev/null +++ b/loaders/actions/add_preprocessor.lua @@ -0,0 +1,3 @@ +function actions_loader.add_preprocessor(fn) + table.insert(actions_loader.preprocessors, fn) +end \ No newline at end of file diff --git a/loaders/actions/mod.lua b/loaders/actions/mod.lua index 17d1238..2c20ea8 100644 --- a/loaders/actions/mod.lua +++ b/loaders/actions/mod.lua @@ -1,4 +1,5 @@ require("loaders.actions.custom_require") +require("loaders.actions.add_preprocessor") require("loaders.actions.extract_header") require("loaders.actions.write_events") require("loaders.actions.set_priority") diff --git a/loaders/actions/set_priority.lua b/loaders/actions/set_priority.lua index b37d00a..fc4902e 100644 --- a/loaders/actions/set_priority.lua +++ b/loaders/actions/set_priority.lua @@ -1,3 +1,5 @@ function actions_loader.set_priority (created_file, header, modulepath) created_file:write("\nlocal priority = " .. header.priority .. " \n\n") end + +actions_loader.add_preprocessor(actions_loader.set_priority) \ No newline at end of file diff --git a/loaders/actions/write_events.lua b/loaders/actions/write_events.lua index 713a5bf..fbc4864 100644 --- a/loaders/actions/write_events.lua +++ b/loaders/actions/write_events.lua @@ -7,3 +7,5 @@ function actions_loader.write_events (created_file, header, modulepath) end created_file:write(" }") end + +actions_loader.add_preprocessor(actions_loader.write_events) \ No newline at end of file diff --git a/loaders/actions/write_function.lua b/loaders/actions/write_function.lua index def378d..132d7aa 100644 --- a/loaders/actions/write_function.lua +++ b/loaders/actions/write_function.lua @@ -12,3 +12,5 @@ function actions_loader.write_function (created_file, header, modulepath) end created_file:write("\nend") end + +actions_loader.add_preprocessor(actions_loader.write_function) \ No newline at end of file diff --git a/loaders/actions/write_input_parameters.lua b/loaders/actions/write_input_parameters.lua index ee1e551..3843554 100644 --- a/loaders/actions/write_input_parameters.lua +++ b/loaders/actions/write_input_parameters.lua @@ -10,3 +10,5 @@ function actions_loader.write_input_parameters (created_file, header, modulepath created_file:write("}\n") end end + +actions_loader.add_preprocessor(actions_loader.write_input_parameters) \ No newline at end of file diff --git a/loaders/actions/write_return.lua b/loaders/actions/write_return.lua index 993e3d0..0917db7 100644 --- a/loaders/actions/write_return.lua +++ b/loaders/actions/write_return.lua @@ -1,3 +1,5 @@ function actions_loader.write_return (created_file, header, modulepath) created_file:write("\n\nreturn{\n\tevent = event,\n\taction = action,\n\tpriority = priority,\n\tinput_parameters = input_parameters\n}") -- ending return end + +actions_loader.add_preprocessor(action.write_return) \ No newline at end of file From dc11e74e95487ab1288f5d9e00175e2b49cf6949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20W=C5=82odarczyk?= Date: Fri, 18 Jan 2019 23:54:47 +0100 Subject: [PATCH 4/5] added add_preprocessor function and preprocessors table for rules loader / unified parameters for preprocessors --- loaders/actions/custom_require.lua | 10 ++++------ loaders/actions/write_return.lua | 2 +- loaders/rules.lua | 4 +++- loaders/rules/add_preprocessor.lua | 3 +++ loaders/rules/custom_require.lua | 10 +++++----- loaders/rules/mod.lua | 1 + loaders/rules/write_events_table.lua | 2 +- loaders/rules/write_get_events_parameters.lua | 2 +- loaders/rules/write_input_parameter.lua | 2 +- loaders/rules/write_priority.lua | 2 +- loaders/rules/write_return.lua | 2 +- 11 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 loaders/rules/add_preprocessor.lua diff --git a/loaders/actions/custom_require.lua b/loaders/actions/custom_require.lua index 347967e..4452fdf 100644 --- a/loaders/actions/custom_require.lua +++ b/loaders/actions/custom_require.lua @@ -8,12 +8,10 @@ function actions_loader.custom_require(name) local file = io.open(filename, "rb") if file then local header = actions_loader.extract_header(modulepath) - - actions_loader.write_events(created_file, header, modulepath) - actions_loader.set_priority(created_file, header, modulepath) - actions_loader.write_input_parameters(created_file, header, modulepath) - actions_loader.write_function(created_file, header, modulepath) - actions_loader.write_return(created_file, header, modulepath) + + for _, fn in ipairs(actions_loader.preprocessors) do + fn(created_file, header, modulepath) + end created_file:close() -- Compile and return the module diff --git a/loaders/actions/write_return.lua b/loaders/actions/write_return.lua index 0917db7..44e045a 100644 --- a/loaders/actions/write_return.lua +++ b/loaders/actions/write_return.lua @@ -2,4 +2,4 @@ function actions_loader.write_return (created_file, header, modulepath) created_file:write("\n\nreturn{\n\tevent = event,\n\taction = action,\n\tpriority = priority,\n\tinput_parameters = input_parameters\n}") -- ending return end -actions_loader.add_preprocessor(action.write_return) \ No newline at end of file +actions_loader.add_preprocessor(actions_loader.write_return) \ No newline at end of file diff --git a/loaders/rules.lua b/loaders/rules.lua index cece8bb..12600c8 100644 --- a/loaders/rules.lua +++ b/loaders/rules.lua @@ -1,4 +1,6 @@ -rules_loader = { } +rules_loader = { + preprocessors = {} +} require("loaders.rules.mod") diff --git a/loaders/rules/add_preprocessor.lua b/loaders/rules/add_preprocessor.lua new file mode 100644 index 0000000..64d8f03 --- /dev/null +++ b/loaders/rules/add_preprocessor.lua @@ -0,0 +1,3 @@ +function rules_loader.add_preprocessor(fn) + table.insert(rules_loader.preprocessors, fn) +end \ No newline at end of file diff --git a/loaders/rules/custom_require.lua b/loaders/rules/custom_require.lua index 3750148..75fda22 100644 --- a/loaders/rules/custom_require.lua +++ b/loaders/rules/custom_require.lua @@ -10,12 +10,12 @@ function rules_loader.custom_require(name) local header = rules_loader.extract_header(modulepath) local priority = header.priority or 1 - rules_loader.write_priority(created_file, header, priority) - rules_loader.write_events_table(created_file, header) - rules_loader.write_input_parameter(created_file, header) + rules_loader.write_priority(created_file, header, modulename, priority, modulepath) + rules_loader.write_events_table(created_file, header, modulename, priority, modulepath) + rules_loader.write_input_parameter(created_file, header, modulename, priority, modulepath) rules_loader.write_rule_function(created_file, header, modulename, priority, modulepath) - rules_loader.write_get_events_parameters(created_file, header) - rules_loader.write_return(created_file, header) + rules_loader.write_get_events_parameters(created_file, header, modulename, priority, modulepath) + rules_loader.write_return(created_file, header, modulename, priority, modulepath) created_file:close() local to_compile = io.open("module.lua", "rb") diff --git a/loaders/rules/mod.lua b/loaders/rules/mod.lua index 80aaa02..fb7f298 100644 --- a/loaders/rules/mod.lua +++ b/loaders/rules/mod.lua @@ -1,4 +1,5 @@ require("loaders.rules.custom_require") +require("loaders.rules.add_preprocessor") require("loaders.rules.extract_header") require("loaders.rules.write_events_table") require("loaders.rules.write_priority") diff --git a/loaders/rules/write_events_table.lua b/loaders/rules/write_events_table.lua index 5eecf7b..176a613 100644 --- a/loaders/rules/write_events_table.lua +++ b/loaders/rules/write_events_table.lua @@ -1,4 +1,4 @@ -function rules_loader.write_events_table (created_file, header) +function rules_loader.write_events_table (created_file, header, modulename, priority, modulepath) created_file:write("\nlocal events_table = { " .. "\"" .. header.events_table[1] .. "\"") for k, v in pairs(header.events_table) do if k ~= 1 then diff --git a/loaders/rules/write_get_events_parameters.lua b/loaders/rules/write_get_events_parameters.lua index 5779c6c..2c313fd 100644 --- a/loaders/rules/write_get_events_parameters.lua +++ b/loaders/rules/write_get_events_parameters.lua @@ -1,4 +1,4 @@ -function rules_loader.write_get_events_parameters (created_file, header) +function rules_loader.write_get_events_parameters (created_file, header, modulename, priority, modulepath) created_file:write("\nlocal function get_events_parameters(events_actions)") created_file:write("\n\tfor k, v in pairs(events_table) do") created_file:write("\n\t\tfor k1, v1 in pairs(events_actions[v]) do") diff --git a/loaders/rules/write_input_parameter.lua b/loaders/rules/write_input_parameter.lua index 50b1f18..e37e0cd 100644 --- a/loaders/rules/write_input_parameter.lua +++ b/loaders/rules/write_input_parameter.lua @@ -1,3 +1,3 @@ -function rules_loader.write_input_parameter (created_file, header) +function rules_loader.write_input_parameter (created_file, header, modulename, priority, modulepath) created_file:write("\nlocal input_parameter = \"" .. header.input_parameter .. "\"") end diff --git a/loaders/rules/write_priority.lua b/loaders/rules/write_priority.lua index 177fd03..212e71a 100644 --- a/loaders/rules/write_priority.lua +++ b/loaders/rules/write_priority.lua @@ -1,4 +1,4 @@ -function rules_loader.write_priority (created_file, header, priority) +function rules_loader.write_priority (created_file, header, modulename, priority, modulepath) if priority > 100 then priority = 100 end created_file:write("local priority = " .. priority) diff --git a/loaders/rules/write_return.lua b/loaders/rules/write_return.lua index 5cc2af5..24f5276 100644 --- a/loaders/rules/write_return.lua +++ b/loaders/rules/write_return.lua @@ -1,3 +1,3 @@ -function rules_loader.write_return (created_file, header) +function rules_loader.write_return (created_file, header, modulename, priority, modulepath) created_file:write("\nreturn{\n\trule = rule,\n\tpriority = priority,\n\tget_events_parameters = get_events_parameters\n}") end From 7dd8685d023da6cf26e118c384d4072ef73cc4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20W=C5=82odarczyk?= Date: Sat, 19 Jan 2019 00:06:25 +0100 Subject: [PATCH 5/5] added preprocessors to table and added loop to require for rules --- loaders/rules/custom_require.lua | 16 ++++++++++------ loaders/rules/write_events_table.lua | 2 ++ loaders/rules/write_get_events_parameters.lua | 2 ++ loaders/rules/write_input_parameter.lua | 2 ++ loaders/rules/write_priority.lua | 2 ++ loaders/rules/write_return.lua | 2 ++ loaders/rules/write_rule_function.lua | 2 ++ 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/loaders/rules/custom_require.lua b/loaders/rules/custom_require.lua index 75fda22..0e6952d 100644 --- a/loaders/rules/custom_require.lua +++ b/loaders/rules/custom_require.lua @@ -10,12 +10,16 @@ function rules_loader.custom_require(name) local header = rules_loader.extract_header(modulepath) local priority = header.priority or 1 - rules_loader.write_priority(created_file, header, modulename, priority, modulepath) - rules_loader.write_events_table(created_file, header, modulename, priority, modulepath) - rules_loader.write_input_parameter(created_file, header, modulename, priority, modulepath) - rules_loader.write_rule_function(created_file, header, modulename, priority, modulepath) - rules_loader.write_get_events_parameters(created_file, header, modulename, priority, modulepath) - rules_loader.write_return(created_file, header, modulename, priority, modulepath) + -- rules_loader.write_priority(created_file, header, modulename, priority, modulepath) + -- rules_loader.write_events_table(created_file, header, modulename, priority, modulepath) + -- rules_loader.write_input_parameter(created_file, header, modulename, priority, modulepath) + -- rules_loader.write_rule_function(created_file, header, modulename, priority, modulepath) + -- rules_loader.write_get_events_parameters(created_file, header, modulename, priority, modulepath) + -- rules_loader.write_return(created_file, header, modulename, priority, modulepath) + + for _, fn in ipairs(rules_loader.preprocessors) do + fn(created_file, header, modulename, priority, modulepath) + end created_file:close() local to_compile = io.open("module.lua", "rb") diff --git a/loaders/rules/write_events_table.lua b/loaders/rules/write_events_table.lua index 176a613..487b7b0 100644 --- a/loaders/rules/write_events_table.lua +++ b/loaders/rules/write_events_table.lua @@ -7,3 +7,5 @@ function rules_loader.write_events_table (created_file, header, modulename, prio end created_file:write("}") end + +rules_loader.add_preprocessor(rules_loader.write_events_table) \ No newline at end of file diff --git a/loaders/rules/write_get_events_parameters.lua b/loaders/rules/write_get_events_parameters.lua index 2c313fd..1ff69a0 100644 --- a/loaders/rules/write_get_events_parameters.lua +++ b/loaders/rules/write_get_events_parameters.lua @@ -11,3 +11,5 @@ function rules_loader.write_get_events_parameters (created_file, header, modulen created_file:write("\n\tend") created_file:write("\nend") end + +rules_loader.add_preprocessor(rules_loader.write_get_events_parameters) \ No newline at end of file diff --git a/loaders/rules/write_input_parameter.lua b/loaders/rules/write_input_parameter.lua index e37e0cd..74c5ebb 100644 --- a/loaders/rules/write_input_parameter.lua +++ b/loaders/rules/write_input_parameter.lua @@ -1,3 +1,5 @@ function rules_loader.write_input_parameter (created_file, header, modulename, priority, modulepath) created_file:write("\nlocal input_parameter = \"" .. header.input_parameter .. "\"") end + +rules_loader.add_preprocessor(rules_loader.write_input_parameter) \ No newline at end of file diff --git a/loaders/rules/write_priority.lua b/loaders/rules/write_priority.lua index 212e71a..2e5cc46 100644 --- a/loaders/rules/write_priority.lua +++ b/loaders/rules/write_priority.lua @@ -3,3 +3,5 @@ function rules_loader.write_priority (created_file, header, modulename, priority created_file:write("local priority = " .. priority) end + +rules_loader.add_preprocessor(rules_loader.write_priority) \ No newline at end of file diff --git a/loaders/rules/write_return.lua b/loaders/rules/write_return.lua index 24f5276..c456ee0 100644 --- a/loaders/rules/write_return.lua +++ b/loaders/rules/write_return.lua @@ -1,3 +1,5 @@ function rules_loader.write_return (created_file, header, modulename, priority, modulepath) created_file:write("\nreturn{\n\trule = rule,\n\tpriority = priority,\n\tget_events_parameters = get_events_parameters\n}") end + +rules_loader.add_preprocessor(rules_loader.write_return) \ No newline at end of file diff --git a/loaders/rules/write_rule_function.lua b/loaders/rules/write_rule_function.lua index d96cd98..8876bb1 100644 --- a/loaders/rules/write_rule_function.lua +++ b/loaders/rules/write_rule_function.lua @@ -40,3 +40,5 @@ function rules_loader.write_rule_function (created_file, header, modulename, pri created_file:write("\n\tend") created_file:write("\nend\n") -- bottom rule function wrapper end + +rules_loader.add_preprocessor(rules_loader.write_rule_function) \ No newline at end of file