diff --git a/README.md b/README.md index bc7dd9a..f4b6854 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This project aims to overcome these issues by making it possible write a ruleset with comments and descriptive function and variables names, and then minifying it. This way it is still possible to maximize the number of rules on the HeishaMon. -_Note: The current minifier has been written to work with [this updated rule libaray version](https://github.com/IgorYbema/HeishaMon/pull/121)_ +_Note: The minifier should work for both the rule library used in version 3.2.3 and [this updated rule libaray version](https://github.com/IgorYbema/HeishaMon/pull/121). In the rule library from version 3.2.3, the elseif statement cannot be used_ ## Installation diff --git a/src/heishamon_rules_minify/minifier.py b/src/heishamon_rules_minify/minifier.py index afab88d..f45ca03 100644 --- a/src/heishamon_rules_minify/minifier.py +++ b/src/heishamon_rules_minify/minifier.py @@ -52,19 +52,20 @@ def minify(cls, input_text): text = re.sub(r"^[\t| ]+|[\t| ]+$", "", text, flags=re.MULTILINE) # Remove newline after line ending with 'then' or 'else' - text = re.sub(r"(?<=then|else)\r{0,1}\n{1}", " ", text, flags=re.MULTILINE) + text = re.sub(r"(?<=then|else)\r?\n", " ", text, flags=re.MULTILINE) # Remove newline after line ending with all possible operators - text = re.sub(r"(?<=[;=&|<>\-+%*\/^()])\r{0,1}\n{1}", "", text, flags=re.MULTILINE) + text = re.sub(r"(?<=[;=&|<>\-+%*\/^()])\r?\n", "", text, flags=re.MULTILINE) + + # Remove extra spaces that are present after removing newlines + text = re.sub(r"(?<=[;=&|<>\-+%*\/^()]) *(?=\S)(?!then)", "", text, flags=re.MULTILINE) # Remove newline after line ending with 'end', except for last end of function text = re.sub(r"(?<=end)\s*(?!\s*on |\Z)", " ", text, flags=re.MULTILINE) - # Correct spaces around equal signs - text = re.sub(r"(?]) *= *(?=-*\d;|[#$@%?].+;)", " = ", text, flags=re.MULTILINE) - - # Correct spaces around double equal signs - text = re.sub(r" *== *", " == ", text, flags=re.MULTILINE) + # Correct spaces around operators and functions + text = re.sub(r"(?=|<=|[=+\*\/%&|<>^]) *)(?=-?\d|\b|[(#$@%?].+(;|then|end))", r" \g<2> ", text, flags=re.MULTILINE) + text = re.sub(r"(?= $OTWW then #HWSTS = $WTWW;elseif @Outside_Temp <= $OTCW then #HWSTS = $WTCW;else #HWSTS = $WTWW +(($OTWW - @Outside_Temp) *($WTCW - $WTWW) /($OTWW - $OTCW));end end +on CWDC then $WTWW = 32;$OTWW = 14;$WTCW = 41;$OTCW = -4;#HWSTS = $WTWW;if @Outside_Temp >= $OTWW then #HWSTS = $WTWW;elseif @Outside_Temp <= $OTCW then #HWSTS = $WTCW;else #HWSTS = $WTWW + (($OTWW - @Outside_Temp) * ($WTCW - $WTWW) / ($OTWW - $OTCW));end end on ?roomTemp then CWDC();$M = 0.25;$S = ?roomTempSet;if ?roomTemp > ($S + $M) then if @Heatpump_State == 1 then @SetHeatpump = 0;end elseif ?roomTemp < ($S - $M) then if @Heatpump_State == 0 then @SetHeatpump = 1;end else @SetZ1HeatRequestTemperature = round(#HWSTS);end end on timer=3 then $S1 = 0;$SV = 1;$SV1 = 2;$SV3 = 3;$SV2 = 4;setTimer(3,60);end """