summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-06-22 20:43:35 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-06-22 20:43:35 -0400
commitff77516d964d758e33218e03483484d2ef1adef9 (patch)
treefd1dc26fa39415397ebdf68aa77a707281da4b2c
parentf34116f1da8465851d684620b6b94e0a3f3c0fbc (diff)
Sort of handling comments in the transpiler
-rw-r--r--2d/rigidbody/rigidbody_1.html4
-rw-r--r--transpiler/replacer.cpp13
-rwxr-xr-xtranspiler/transpilerbin49640 -> 49688 bytes
3 files changed, 14 insertions, 3 deletions
diff --git a/2d/rigidbody/rigidbody_1.html b/2d/rigidbody/rigidbody_1.html
index bf703d2..ec7e028 100644
--- a/2d/rigidbody/rigidbody_1.html
+++ b/2d/rigidbody/rigidbody_1.html
@@ -172,7 +172,7 @@ const <span class="code_keyword">int32</span> NUM_IMPULSES = 4;
<span class="code_keyword">void</span> update(float32 deltaTimeSeconds) {
applyGravity(deltaTimeSeconds);
- // Add up all of the forces acting at this moment
+ <span class="code_comment">// Add up all of the forces acting at this moment</span>
<span class="code_keyword">Vector2</span> force;
for (int32 idx = 0; idx < numImpulses; idx++) {
Impulse& i = activeImpulses[idx];
@@ -192,7 +192,7 @@ const <span class="code_keyword">int32</span> NUM_IMPULSES = 4;
velocity += (acceleration * impulseDtSeconds);
position += (velocity * deltaTimeSeconds);
- // Cleanup any impulses that have expired in the mean time
+ <span class="code_comment">// Cleanup any impulses that have expired in the mean time</span>
for (int32 idx = 0; idx < numImpulses; idx++) {
if (activeImpulses[idx].isDead) {
for (int j = idx + 1; j < numImpulses; j++) {
diff --git a/transpiler/replacer.cpp b/transpiler/replacer.cpp
index 28c2e8e..0225f92 100644
--- a/transpiler/replacer.cpp
+++ b/transpiler/replacer.cpp
@@ -17,6 +17,8 @@ const char* types[] = {
"struct", "class"
};
+const char* commentType = "//";
+
bool isType(char* str, int size) {
if (size == 0) {
return false;
@@ -84,7 +86,16 @@ std::string insertCodeSnippets(char* workingDirectory, char* bodyContent) {
}
int tokenLength = (tokenEnd - tokenStart);
- if (isType(&snippetContent[tokenStart], tokenLength)) {
+
+ if (tokenLength == strlen(commentType) && strncmp(&snippetContent[tokenStart], commentType, tokenLength) == 0) {
+ // @NOTE: Assuming comments are always on a single line
+ s.append("<span class=\"code_comment\">");
+ while (snippetContent[tokenEnd] != '\n') {
+ tokenEnd++;
+ }
+ s.append(&snippetContent[tokenStart], tokenEnd - tokenStart);
+ s.append("</span>");
+ } else if (isType(&snippetContent[tokenStart], tokenLength)) {
s.append("<span class=\"code_keyword\">");
s.append(&snippetContent[tokenStart], tokenLength);
s.append("</span>");
diff --git a/transpiler/transpiler b/transpiler/transpiler
index 509db3e..896e778 100755
--- a/transpiler/transpiler
+++ b/transpiler/transpiler
Binary files differ