Compare commits

...

3 Commits

Author SHA1 Message Date
2e1e2e727b Merge pull request 'Update docs/highlight.py' (#13) from DiamondNether90/ground_fork:master into master
Reviewed-on: https://git.maxwellj.xyz/max/ground/pulls/13
2025-09-01 08:32:08 +10:00
38681f72d7 Merge branch 'master' into master 2025-09-01 08:31:46 +10:00
9c8cd58449 Update docs/highlight.py
Added file support, added inline comment support, added true/false support, fixed strings.
2025-09-01 08:30:21 +10:00

View File

@@ -1,3 +1,11 @@
import sys
if len(sys.argv) < 2:
exit(1)
fileName = sys.argv[1]
thefile = open(fileName).readlines()
def isnumber(num): def isnumber(num):
try: try:
float(num) float(num)
@@ -5,18 +13,19 @@ def isnumber(num):
except ValueError: except ValueError:
return False return False
instr = 1
allstr = "" allstr = ""
color = "" color = ""
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"] 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"]
while instr != "":
instr = input("Code: ")
allstr += instr + " <br> "
lines = len(allstr.split("<br>"))-2 for line in thefile:
allstr += line + " <br> "
lines = len(allstr.split("<br>"))-1
a = allstr.split() a = allstr.split()
for i in range(lines): for i in range(lines):
instr = False
incom = False
words = len(allstr.split("<br>")[i].split()) words = len(allstr.split("<br>")[i].split())
for j in range(words): for j in range(words):
tempword = allstr.split("<br>")[i].split()[j] tempword = allstr.split("<br>")[i].split()[j]
@@ -26,6 +35,9 @@ for i in range(lines):
color = "\033[32m" color = "\033[32m"
elif tempword in keywords: elif tempword in keywords:
color = "\033[95m" color = "\033[95m"
elif tempword[0] == "#":
incom = True
color = "\033[37m"
elif tempword[0] == "&": elif tempword[0] == "&":
color = "\033[93m" color = "\033[93m"
elif tempword[0] == "$": elif tempword[0] == "$":
@@ -38,12 +50,17 @@ for i in range(lines):
color = "\033[94m" color = "\033[94m"
elif tempword[0] == "*": elif tempword[0] == "*":
color = "\033[93m" color = "\033[93m"
elif tempword[0] == "\"" and tempword[len(tempword)-1] == "\"": elif tempword[0] == "\"":
color = "\033[92m" color = "\033[92m"
instr = not instr
elif tempword[0] == "\'" and tempword[len(tempword)-1] == "\'": elif tempword[0] == "\'" and tempword[len(tempword)-1] == "\'":
color = "\033[92m" color = "\033[92m"
elif isnumber(tempword): elif isnumber(tempword) or tempword == "true" or tempword == "false":
color = "\033[96m" color = "\033[96m"
elif instr:
color = "\033[92m"
elif incom:
color = "\033[37m"
else: else:
color = "\033[91m" color = "\033[91m"