Files
ground_fork/docs/highlight.py

70 lines
2.1 KiB
Python
Raw Normal View History

import sys
if len(sys.argv) < 2:
exit(1)
fileName = sys.argv[1]
thefile = open(fileName).readlines()
2025-08-31 19:04:20 +10:00
def isnumber(num):
try:
float(num)
return True
except ValueError:
return False
allstr = ""
color = ""
2025-09-12 11:57:45 +10:00
keywords = ["if", "jump", "end", "stdin", "stdout", "stdlnout", "set", "gettype", "exists", "setlist", "setlistat", "getlistat", "getlistsize", "listappend", "getstrsize", "getstrcharat", "add", "subtract", "multiply", "divide", "equal", "inequal", "not", "greater", "lesser", "stoi", "stod", "tostring", "fun", "return", "endfun", "pusharg", "call", "use", "extern", "error"]
2025-08-31 19:04:20 +10:00
for line in thefile:
allstr += line + " <br> "
lines = len(allstr.split("<br>"))-1
2025-08-31 19:04:20 +10:00
a = allstr.split()
for i in range(lines):
instr = False
incom = False
2025-08-31 19:04:20 +10:00
words = len(allstr.split("<br>")[i].split())
for j in range(words):
tempword = allstr.split("<br>")[i].split()[j]
if allstr.split("<br>")[i].split()[0][0] == "#":
color = "\033[37m"
elif allstr.split("<br>")[i].split()[0][0] == "@":
color = "\033[32m"
elif tempword in keywords:
color = "\033[95m"
elif isnumber(tempword) or tempword == "true" or tempword == "false":
color = "\033[96m"
elif tempword[0] == "#":
incom = True
color = "\033[37m"
2025-08-31 19:04:20 +10:00
elif tempword[0] == "&":
color = "\033[93m"
elif tempword[0] == "$":
color = "\033[33m"
elif tempword[0] == "%":
color = "\033[32m"
elif tempword[0] == "-":
color = "\033[34m"
elif tempword[0] == "!":
color = "\033[94m"
elif tempword[0] == "*":
color = "\033[93m"
elif tempword[0] == "\"":
2025-08-31 19:04:20 +10:00
color = "\033[92m"
instr = not instr
2025-08-31 19:04:20 +10:00
elif tempword[0] == "\'" and tempword[len(tempword)-1] == "\'":
color = "\033[92m"
elif instr:
color = "\033[92m"
elif incom:
color = "\033[37m"
2025-08-31 19:04:20 +10:00
else:
color = "\033[91m"
print(f'{color}{tempword}', end=" ")
print()
print("\033[00m", end="")