From 5c93bf663a7d836cb5147e7d0a7c415e1eb15fe2 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 11 Aug 2022 13:45:13 +0100 Subject: [PATCH] Tweaked string quotes --- source/compiler.c | 14 +++++++------- source/literal.c | 15 ++++++++++++++- source/literal_dictionary.h | 1 - source/scope.h | 1 - 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/source/compiler.c b/source/compiler.c index db5b07b..9b7f793 100644 --- a/source/compiler.c +++ b/source/compiler.c @@ -14,14 +14,14 @@ void initCompiler(Compiler* compiler) { compiler->capacity = 0; compiler->count = 0; - //default atomic literals - Literal n = TO_NULL_LITERAL; - Literal t = TO_BOOLEAN_LITERAL(true); - Literal f = TO_BOOLEAN_LITERAL(false); + //default atomic literals (commented out, because not needed atm - might need them later) + // Literal n = TO_NULL_LITERAL; + // Literal t = TO_BOOLEAN_LITERAL(true); + // Literal f = TO_BOOLEAN_LITERAL(false); - pushLiteralArray(&compiler->literalCache, n); - pushLiteralArray(&compiler->literalCache, t); - pushLiteralArray(&compiler->literalCache, f); + // pushLiteralArray(&compiler->literalCache, n); + // pushLiteralArray(&compiler->literalCache, t); + // pushLiteralArray(&compiler->literalCache, f); } //separated out, so it can be recursive diff --git a/source/literal.c b/source/literal.c index 595b7cf..2217dc2 100644 --- a/source/literal.c +++ b/source/literal.c @@ -17,6 +17,9 @@ static char* globalPrintBuffer = NULL; static size_t globalPrintCapacity = 0; static size_t globalPrintCount = 0; +//BUGFIX: string quotes shouldn't show when just printing strings, but should show when printing them as members of something else +static char quotes = 0; //set to 0 to not show string quotes + static void printToBuffer(const char* str) { while (strlen(str) + globalPrintCount > globalPrintCapacity) { int oldCapacity = globalPrintCapacity; @@ -60,7 +63,12 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) { case LITERAL_STRING: { char buffer[4096]; - snprintf(buffer, 4096, "\"%.*s\"", STRLEN(literal), AS_STRING(literal)); + if (!quotes) { + snprintf(buffer, 4096, "%.*s", STRLEN(literal), AS_STRING(literal)); + } + else { + snprintf(buffer, 4096, "%c%.*s%c", quotes, STRLEN(literal), AS_STRING(literal), quotes); + } printFn(buffer); } break; @@ -79,6 +87,7 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) { //print the contents to the global buffer printToBuffer("["); for (int i = 0; i < ptr->count; i++) { + quotes = '"'; printLiteralCustom(ptr->literals[i], printToBuffer); if (i + 1 < ptr->count) { @@ -99,6 +108,7 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) { //finally, output and cleanup printFn(printBuffer); FREE_ARRAY(char, printBuffer, printCapacity); + quotes = 0; } break; @@ -125,8 +135,10 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) { printToBuffer(","); } + quotes = '"'; printLiteralCustom(ptr->entries[i].key, printToBuffer); printToBuffer(":"); + quotes = '"'; printLiteralCustom(ptr->entries[i].value, printToBuffer); } @@ -149,6 +161,7 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) { //finally, output and cleanup printFn(printBuffer); FREE_ARRAY(char, printBuffer, printCapacity); + quotes = 0; } break; diff --git a/source/literal_dictionary.h b/source/literal_dictionary.h index 0523be9..cfe02e9 100644 --- a/source/literal_dictionary.h +++ b/source/literal_dictionary.h @@ -1,6 +1,5 @@ #pragma once -#include "common.h" #include "literal.h" //TODO: benchmark this diff --git a/source/scope.h b/source/scope.h index e449a35..7ee7d3c 100644 --- a/source/scope.h +++ b/source/scope.h @@ -1,6 +1,5 @@ #pragma once -#include "common.h" #include "literal_dictionary.h" typedef struct Scope {