diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ba0430d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+__pycache__/
\ No newline at end of file
diff --git a/resources/Nova/novox/code.txt b/resources/Nova/novox/code.txt
new file mode 100644
index 0000000..b28f737
--- /dev/null
+++ b/resources/Nova/novox/code.txt
@@ -0,0 +1,84 @@
+
+\\
+DISCLAIMER –
+This code is only a peek at what supcode can do.
+It is not by any means functional, optimised or perfect.
+Enjoy ^v^
+\\
+
+
<sup ver="6" sty="utinax-vis" ind=3> + +\\ + +DISCLAIMER – + +This code is only a peek at what supcode can do. + +It is not by any means functional, optimised or perfect. + +Enjoy ^v^ + +\\ + + + +<sec 'structs'> + +create struct 'profile' { + + \\ + + Represents a user profile. + + \\ + + + + evolve action create self(ctx) [ + + | int 'id' + + | str 'user', 'name' + + | str, list(str) 'alts' = none + + | list(str) 'langs' = list() + + | list(str) 'apts' = list() + + | (par)s 'pars' + + ] { + + \\ + + Creates a new profile. + + \\ + + + + auto set id, name, alt-name, langs, apts + + + + set self.'render-keywords' = dict( + + "id" = "User ID", + + "name" = "Username", + + "alts" = "Alternative Usernames", + + "langs" = "Programming Languages", + + "apts" = "Aptitudes", + + ) + + + + loop for key, val in pars { + + set self.(shard(key)) = val + + } + + } + + + + create func self.render-text() to str { + + set 'text' = "Profile[" + "\n" + + + + loop for 'var' in self._vars_ { + + if var in self.render-keywords { + + alt text + "`render-keywords # var`: " + + } else { + + alt text + str(var) + ": " + + } + + + + alt text + { if var is iterable then { + + str.join( + + { for each in var out str(each) } + + ) [sep = ", "] + + } else str(var) } + + } + + + + out text + + } + +} + +</sec> + + + +<sec "core"> + +evolve sys.run(ctx) [(par)s] + +{ + + set 'sup' = profile() [ + + | id = 2.0 + + | name = "Sup#2.0" + + | alt-name = "Sup2point0" + + | langs = "supcode", "Scratch", "Python", "C#", "HTML", "CSS", "JavaScript", + + | apts = ( + + "creating", "designing", "coding", "procrastinating", + + ) + + ] + + + + sys.out(sup.render-text()) + + sys.in() + + sys.quit() + +} + +</sec> + + + +\ how’d you like that? + +</sup> + ++ + \ No newline at end of file diff --git a/resources/Nova/novox/highlighter.py b/resources/Nova/novox/highlighter.py index 0bfb87e..0ec7f91 100644 --- a/resources/Nova/novox/highlighter.py +++ b/resources/Nova/novox/highlighter.py @@ -15,46 +15,54 @@ def render(file: str): '''Applies syntax highlighting to a .txt file and saves it as a .png file.''' with open(file) as f: - text = highlight(f) + text = highlight(f).getvalue() + style() export(text, "export.html") def highlight(source): '''Apply *supcode Nova* syntax highlighting to a source file.''' - with open("tokens.json") as f: + with open("tokens.json", "r") as f: tokens = json.load(f) + with open("semantics.json", "r") as f: + semantics = json.load(f) new = StringIO() context = [] ## contextual styles for line in source: + line = re.sub("=<", "≤", line) + line = re.sub(">=", "≥", line) + for each in re.split("(\W)", line): # test different tokens - for key, vals in tokens.items(): - - # pair tokens open a new context - if key == "pair": - for kind, matches in vals.items(): - break - - # lone tokens can be simply replaced - else: - if each in vals: - new.write(f'{each}') - break + for construct, token in tokens.items(): + if context: + continue + if each in token: + new.write(f'{repl(each)}') + break else: - new.write(each) + # for construct, token in semantics.items(): + # if each in token: + # if context: + # if context[-1] == construct: + # context.pop() + # new.write(f"{repl(each)}") + # else: + # context.append(construct) + # new.write(f'{repl(each)}') + + # else: + new.write(each) new.write("\n") ## character alterations - new = new.getvalue() - new = re.sub("=<", "≤", new) - new = re.sub(">=", "≥", new) ... # ligatures # dualshift @@ -65,15 +73,18 @@ def highlight(source): def repl(char): '''Replace a character.''' - ... + match char: + case "<": + return "<" + case ">": + return ">" + case _: + return char def export(content, file): '''Save a .html file as a .png image.''' - content = re.sub("<", "<", content) - content = re.sub(">", ">", content) - with open(file, "w") as f: text = f""" @@ -106,11 +117,16 @@ def export(content, file): def style(): with open("tokens.json", "r") as f: tokens = json.load(f) - with open("colours.json", "r") as f: colours = json.load(f) - - text = "\n".join(f".{token} \{color: {colours[token]}}" for token in tokens) + with open("novox.json", "r") as f: + novox = json.load(f) + + text = "\n".join( + f""".{token} {{color: {colours[novox["colours"][token]]}}}""" + for token in tokens + ) + text += f"\n* {{color: #fff; background-color: {colours['blue-midnight']}}}" with open("style.css", "w") as f: f.write(text) diff --git a/resources/Nova/novox/novox.json b/resources/Nova/novox/novox.json index 102d80b..ba0a40f 100644 --- a/resources/Nova/novox/novox.json +++ b/resources/Nova/novox/novox.json @@ -1,38 +1,40 @@ { - "comment": "grey.nova", - "comment-single": "grey.nova", - "comment-double": "grey.nova", - "comment-triple": "grey.nova", - "comment-single-bounded": "grey.nova", - "comment-double-bounded": "grey.nova", - "comment-triple-bounded": "grey.nova", - "keyword": "blue.nova", - "action": "blue.nova", - "logic": "orange.solar", - "function": "pink.electric", - "struct": "lilac.nova", - "shard": "#fff", - "string": "#fff", - "number": "blue.crescent", - "bool": "lilac.crescent", - "none": "lilac.crescent", - "class": "lilac.nova", - "object": "#fff", - "object-constant": "#fff", - "object-ephemeral": ["#fff", "italic"], - "object-argument": "pink.spirit", - "object-parameter": "pink.spirit", - "object-special": ["lilac.crescent", "italic"], - "extension": "teal.electric", - "ixtension": "teal.electric", - "particle": "#fff", - "secator": "purple.spirit", - "operator": "orange.solar", - "dot": "grey.nova", - "colon": "orange.spirit", - "semicolon": "blue.deep", - "pipe": "#fff", - "bracket-round": "#fff", - "bracket-square": "#fff", - "brace": "#fff", + "colours": { + "comment": "grey-nova", + "comment-single": "grey-nova", + "comment-double": "grey-nova", + "comment-triple": "grey-nova", + "comment-single-bounded": "grey-nova", + "comment-double-bounded": "grey-nova", + "comment-triple-bounded": "grey-nova", + "keyword": "blue-nova", + "action": "blue-nova", + "logic": "orange-solar", + "function": "pink-electric", + "struct": "lilac-nova", + "shard": "#fff", + "string": "#fff", + "number": "blue-crescent", + "bool": "lilac-crescent", + "none": "lilac-crescent", + "class": "lilac-nova", + "object": "#fff", + "object-constant": "#fff", + "object-ephemeral": ["#fff", "italic"], + "object-argument": "pink-spirit", + "object-parameter": "pink-spirit", + "object-special": ["lilac-crescent", "italic"], + "extension": "teal-electric", + "ixtension": "teal-electric", + "particle": "#fff", + "secator": "purple-spirit", + "operator": "orange-solar", + "dot": "grey-nova", + "colon": "orange-spirit", + "semicolon": "blue-deep", + "pipe": "#fff", + "bracket-round": "#fff", + "bracket-square": "#fff", + "brace": "#fff" + } } diff --git a/resources/Nova/novox/render.py b/resources/Nova/novox/render.py new file mode 100644 index 0000000..44493f6 --- /dev/null +++ b/resources/Nova/novox/render.py @@ -0,0 +1,9 @@ +''' +Renders supcode with syntax highlighting. +''' + +if __name__ == "__main__": + from highlighter import render + + render("code.txt") + print("DONE") \ No newline at end of file diff --git a/resources/Nova/novox/semantics.json b/resources/Nova/novox/semantics.json new file mode 100644 index 0000000..55864a0 --- /dev/null +++ b/resources/Nova/novox/semantics.json @@ -0,0 +1,3 @@ +{ + "string": """ +} \ No newline at end of file diff --git a/resources/Nova/novox/style.css b/resources/Nova/novox/style.css new file mode 100644 index 0000000..4669577 --- /dev/null +++ b/resources/Nova/novox/style.css @@ -0,0 +1,6 @@ +.keyword {color: #4090f1} +.action {color: #4090f1} +.logic {color: #ff9020} +.struct {color: #9090f1} +.operator {color: #ff9020} +* {color: #fff; background-color: #00172a} \ No newline at end of file diff --git a/resources/Nova/novox/tokens.json b/resources/Nova/novox/tokens.json index 8e1e40c..48602a8 100644 --- a/resources/Nova/novox/tokens.json +++ b/resources/Nova/novox/tokens.json @@ -13,6 +13,7 @@ "logic": ["not", "and", "or", "xor", "is", "in", "has"], "struct": [ "struct", "class", "func", "function", "act", "action", + "list", "dict", "str", "string", "num", "number", "int", "integer", "float", "frac", "fraction", "dec", "decimal", "bin", "binary", "hex", "hexadec"