diff --git a/README.md b/README.md new file mode 100644 index 0000000..6632289 --- /dev/null +++ b/README.md @@ -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. \ No newline at end of file diff --git a/main.py b/main.py index c88bb80..e392aa4 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,8 @@ -def split_by_space(line): +def split_by_space(line: str): token: str = "" tokens: list[str] = [] isString = False + isComment = False for char in line: if isString: if char == "\"": @@ -9,7 +10,13 @@ def split_by_space(line): continue token += char continue + if isComment: + token += char + continue match char: + case "#": + isComment = True + token += char case "\"" | "\'": token = "?" isString = True @@ -23,7 +30,7 @@ def split_by_space(line): case _: token += char - if tokens != "": + if token != "": tokens.append(token) return tokens @@ -38,6 +45,8 @@ def get_color(arg: str): return f"\033[33m{arg[0]}\033[0m{arg[1:]}" case '@': return f"\033[33m{arg}\033[0m" + case '#': + return f"\033[30m{arg}\033[0m" case _: return f"\033[35m{arg}\033[0m" @@ -53,5 +62,21 @@ def highlight_text(code: str): print(get_color(arg), end=" ") print() print("```") - -highlight_text("@label\n\n set &str \"Hello, world!\"\n println $str\n jump %label") \ No newline at end of file + +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""") \ No newline at end of file