Comments + Test case
This commit is contained in:
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Discord Syntax Highlighter
|
||||||
|
Provides Syntax Highlighting for Ground. Simply run this python script (or add to a bot!)
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
Call the `highlight_program()` function, with the ground program as the argument. This returns text which can be
|
||||||
|
directly copy-pasted into discord.
|
||||||
31
main.py
31
main.py
@@ -1,7 +1,8 @@
|
|||||||
def split_by_space(line):
|
def split_by_space(line: str):
|
||||||
token: str = ""
|
token: str = ""
|
||||||
tokens: list[str] = []
|
tokens: list[str] = []
|
||||||
isString = False
|
isString = False
|
||||||
|
isComment = False
|
||||||
for char in line:
|
for char in line:
|
||||||
if isString:
|
if isString:
|
||||||
if char == "\"":
|
if char == "\"":
|
||||||
@@ -9,7 +10,13 @@ def split_by_space(line):
|
|||||||
continue
|
continue
|
||||||
token += char
|
token += char
|
||||||
continue
|
continue
|
||||||
|
if isComment:
|
||||||
|
token += char
|
||||||
|
continue
|
||||||
match char:
|
match char:
|
||||||
|
case "#":
|
||||||
|
isComment = True
|
||||||
|
token += char
|
||||||
case "\"" | "\'":
|
case "\"" | "\'":
|
||||||
token = "?"
|
token = "?"
|
||||||
isString = True
|
isString = True
|
||||||
@@ -23,7 +30,7 @@ def split_by_space(line):
|
|||||||
case _:
|
case _:
|
||||||
token += char
|
token += char
|
||||||
|
|
||||||
if tokens != "":
|
if token != "":
|
||||||
tokens.append(token)
|
tokens.append(token)
|
||||||
return tokens
|
return tokens
|
||||||
|
|
||||||
@@ -38,6 +45,8 @@ def get_color(arg: str):
|
|||||||
return f"\033[33m{arg[0]}\033[0m{arg[1:]}"
|
return f"\033[33m{arg[0]}\033[0m{arg[1:]}"
|
||||||
case '@':
|
case '@':
|
||||||
return f"\033[33m{arg}\033[0m"
|
return f"\033[33m{arg}\033[0m"
|
||||||
|
case '#':
|
||||||
|
return f"\033[30m{arg}\033[0m"
|
||||||
case _:
|
case _:
|
||||||
return f"\033[35m{arg}\033[0m"
|
return f"\033[35m{arg}\033[0m"
|
||||||
|
|
||||||
@@ -54,4 +63,20 @@ def highlight_text(code: str):
|
|||||||
print()
|
print()
|
||||||
print("```")
|
print("```")
|
||||||
|
|
||||||
highlight_text("@label\n\n set &str \"Hello, world!\"\n println $str\n jump %label")
|
if __name__ == "__main__":
|
||||||
|
highlight_text(
|
||||||
|
"""# A cool list
|
||||||
|
setlist &favWords "hello" "there" "general"
|
||||||
|
listappend &favWords "kenobi"
|
||||||
|
println $favWords
|
||||||
|
|
||||||
|
set &count 0
|
||||||
|
set &passedThrough true
|
||||||
|
|
||||||
|
@jmpbck
|
||||||
|
getlistat &favWords $count &tmp
|
||||||
|
println $tmp
|
||||||
|
add $count 1 &count
|
||||||
|
getlistsize &favWords &tmp2
|
||||||
|
inequal $count $tmp2 &tmp3 #comment
|
||||||
|
if $tmp3 %jmpbck""")
|
||||||
Reference in New Issue
Block a user