mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Tweaked string quotes
This commit is contained in:
@@ -14,14 +14,14 @@ void initCompiler(Compiler* compiler) {
|
|||||||
compiler->capacity = 0;
|
compiler->capacity = 0;
|
||||||
compiler->count = 0;
|
compiler->count = 0;
|
||||||
|
|
||||||
//default atomic literals
|
//default atomic literals (commented out, because not needed atm - might need them later)
|
||||||
Literal n = TO_NULL_LITERAL;
|
// Literal n = TO_NULL_LITERAL;
|
||||||
Literal t = TO_BOOLEAN_LITERAL(true);
|
// Literal t = TO_BOOLEAN_LITERAL(true);
|
||||||
Literal f = TO_BOOLEAN_LITERAL(false);
|
// Literal f = TO_BOOLEAN_LITERAL(false);
|
||||||
|
|
||||||
pushLiteralArray(&compiler->literalCache, n);
|
// pushLiteralArray(&compiler->literalCache, n);
|
||||||
pushLiteralArray(&compiler->literalCache, t);
|
// pushLiteralArray(&compiler->literalCache, t);
|
||||||
pushLiteralArray(&compiler->literalCache, f);
|
// pushLiteralArray(&compiler->literalCache, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//separated out, so it can be recursive
|
//separated out, so it can be recursive
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ static char* globalPrintBuffer = NULL;
|
|||||||
static size_t globalPrintCapacity = 0;
|
static size_t globalPrintCapacity = 0;
|
||||||
static size_t globalPrintCount = 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) {
|
static void printToBuffer(const char* str) {
|
||||||
while (strlen(str) + globalPrintCount > globalPrintCapacity) {
|
while (strlen(str) + globalPrintCount > globalPrintCapacity) {
|
||||||
int oldCapacity = globalPrintCapacity;
|
int oldCapacity = globalPrintCapacity;
|
||||||
@@ -60,7 +63,12 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) {
|
|||||||
|
|
||||||
case LITERAL_STRING: {
|
case LITERAL_STRING: {
|
||||||
char buffer[4096];
|
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);
|
printFn(buffer);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -79,6 +87,7 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) {
|
|||||||
//print the contents to the global buffer
|
//print the contents to the global buffer
|
||||||
printToBuffer("[");
|
printToBuffer("[");
|
||||||
for (int i = 0; i < ptr->count; i++) {
|
for (int i = 0; i < ptr->count; i++) {
|
||||||
|
quotes = '"';
|
||||||
printLiteralCustom(ptr->literals[i], printToBuffer);
|
printLiteralCustom(ptr->literals[i], printToBuffer);
|
||||||
|
|
||||||
if (i + 1 < ptr->count) {
|
if (i + 1 < ptr->count) {
|
||||||
@@ -99,6 +108,7 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) {
|
|||||||
//finally, output and cleanup
|
//finally, output and cleanup
|
||||||
printFn(printBuffer);
|
printFn(printBuffer);
|
||||||
FREE_ARRAY(char, printBuffer, printCapacity);
|
FREE_ARRAY(char, printBuffer, printCapacity);
|
||||||
|
quotes = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -125,8 +135,10 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) {
|
|||||||
printToBuffer(",");
|
printToBuffer(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quotes = '"';
|
||||||
printLiteralCustom(ptr->entries[i].key, printToBuffer);
|
printLiteralCustom(ptr->entries[i].key, printToBuffer);
|
||||||
printToBuffer(":");
|
printToBuffer(":");
|
||||||
|
quotes = '"';
|
||||||
printLiteralCustom(ptr->entries[i].value, printToBuffer);
|
printLiteralCustom(ptr->entries[i].value, printToBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +161,7 @@ void printLiteralCustom(Literal literal, void (printFn)(const char*)) {
|
|||||||
//finally, output and cleanup
|
//finally, output and cleanup
|
||||||
printFn(printBuffer);
|
printFn(printBuffer);
|
||||||
FREE_ARRAY(char, printBuffer, printCapacity);
|
FREE_ARRAY(char, printBuffer, printCapacity);
|
||||||
|
quotes = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "literal.h"
|
#include "literal.h"
|
||||||
|
|
||||||
//TODO: benchmark this
|
//TODO: benchmark this
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
#include "literal_dictionary.h"
|
#include "literal_dictionary.h"
|
||||||
|
|
||||||
typedef struct Scope {
|
typedef struct Scope {
|
||||||
|
|||||||
Reference in New Issue
Block a user