-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_lambda.py
29 lines (23 loc) · 1.02 KB
/
make_lambda.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# This script will strip out any comments, spaces or newline characters from a file
# It acts a compiler for Excel LAMBDA functions, allowing us to write more structured functions
#
# Usage is of the form
# python make_lambda.py < WIBBLE.lambda > WIBBLE.min.lambda
import sys
def clean_function(input_text):
lines = input_text.split("\n")
processed_lines = []
for line in lines:
# Remove comments (lines starting with "//")
if "//" in line:
line = line[:line.index("//")]
line = line.replace(" ", "") # Remove spaces
processed_lines.append(line)
return "".join(processed_lines) + "\n"
if __name__ == "__main__":
try:
input_text = sys.stdin.read() # Read from STDIN until EOF is encountered
processed_text = clean_function(input_text) # Remove spaces, newlines, and comments
sys.stdout.write(processed_text) # Write the processed text to STDOUT
except KeyboardInterrupt:
sys.exit(0) # In case of KeyboardInterrupt (e.g., Ctrl+C), gracefully exit without errors