From dea718317d3b9fe30ae8fc6fbf2d768d8015fa49 Mon Sep 17 00:00:00 2001
From: "Sup#2.0"
Date: Thu, 22 Feb 2024 21:12:17 +0000
Subject: [PATCH] provisionally implement Novox syntax highlighting engine
---
.gitignore | 1 +
resources/Nova/novox/code.txt | 84 +++++++++++++
resources/Nova/novox/colours.json | 74 ++++++------
resources/Nova/novox/export.html | 180 ++++++++++++++++++++++++++++
resources/Nova/novox/highlighter.py | 66 ++++++----
resources/Nova/novox/novox.json | 74 ++++++------
resources/Nova/novox/render.py | 9 ++
resources/Nova/novox/semantics.json | 3 +
resources/Nova/novox/style.css | 6 +
resources/Nova/novox/tokens.json | 1 +
10 files changed, 401 insertions(+), 97 deletions(-)
create mode 100644 .gitignore
create mode 100644 resources/Nova/novox/code.txt
create mode 100644 resources/Nova/novox/export.html
create mode 100644 resources/Nova/novox/render.py
create mode 100644 resources/Nova/novox/semantics.json
create mode 100644 resources/Nova/novox/style.css
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^
+\\
+
+
+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
+ }
+}
+
+
+
+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()
+}
+
+
+\ how’d you like that?
+
diff --git a/resources/Nova/novox/colours.json b/resources/Nova/novox/colours.json
index 6d96c5d..917ebdf 100644
--- a/resources/Nova/novox/colours.json
+++ b/resources/Nova/novox/colours.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", // TODO
- "logic": "orange.solar",
- "function": "pink.electric",
- "struct": "lilac.nova",
- "shard": "#fff", // TODO
- "string": "#fff", // TODO
- "number": "blue.crescent",
- "bool": "lilac.crescent",
- "none": "lilac.crescent",
- "class": "lilac.nova", // TODO
- "object": "#fff",
- "object.constant": "#fff", // TODO
- "object.ephemeral": ["#fff", "italic"], // TODO
- "object.argument": "pink.spirit",
- "object.parameter": "pink.spirit",
- "object.special": ["lilac.crescent", "italic"],
- "extension": "teal.electric",
- "ixtension": "teal.electric",
- "particle": "#fff", // TODO
- "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",
+ "blue-nova": "#4090f1",
+ "blue-crescent": "#c0f0ff",
+ "blue-spirit": "#70c7ff",
+ "blue-sky": "#45c7f1",
+ "blue-ocean": "#2070c1",
+ "blue-deep": "#145090",
+ "blue-electric": "#40e0ff",
+ "blue-accent": "#0064f1",
+ "blue-midnight": "#00172a",
+ "grey-nova": "#a9b0b8",
+ "grey-swallow": "#dfe7f1",
+ "grey-spirit": "#c7d0d9",
+ "grey-ocean": "#90969e",
+ "grey-storm": "#70767c",
+ "lilac-nova": "#9090f1",
+ "lilac-crescent": "#c7c7ff",
+ "pink-electric": "#ff0090",
+ "pink-spirit": "#f190f1",
+ "purple-spirit": "#9040f1",
+ "purple-nova": "#6040f1",
+ "purple-accent": "#7000ff",
+ "red-nova": "#ff0040",
+ "red-spirit": "#ff2000",
+ "red-crescent": "#ffc0a9",
+ "orange-spirit": "#ff7000",
+ "orange-solar": "#ff9020",
+ "yellow-solar": "#ffa920",
+ "yellow-nova": "#ffc720",
+ "mellow-crescent": "#fff0c0",
+ "green-solar": "#70c720",
+ "green-spirit": "#40c740",
+ "green-nova": "#00c745",
+ "aquamarine-accent": "#33c070",
+ "teal-electric": "#40f190",
+ "teal-lightning": "#c1fff1",
+ "teal-spirit": "#60c7c7",
+ "teal-nova": "#409090"
}
+
\ No newline at end of file
diff --git a/resources/Nova/novox/export.html b/resources/Nova/novox/export.html
new file mode 100644
index 0000000..85c518f
--- /dev/null
+++ b/resources/Nova/novox/export.html
@@ -0,0 +1,180 @@
+
+
+
+ supcode Render
+
+
+
+
+
+ <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"