More JSON-y struct string representation
This commit is contained in:
parent
8120889bfd
commit
e97746ce07
|
@ -191,7 +191,12 @@ void stringStruct(struct string* s, const Object* obj)
|
||||||
|
|
||||||
struct StructDef* def = getStructAt(so->definition);
|
struct StructDef* def = getStructAt(so->definition);
|
||||||
for (int i = 0; i < def->fieldCount; i++) {
|
for (int i = 0; i < def->fieldCount; i++) {
|
||||||
appendf(s, " %s: ", def->names[i]);
|
appendf(s, " \"%s\": ", def->names[i]);
|
||||||
|
if (so->fields[i].type == TYPE_SYMBOL && so->fields[i].string == NULL) {
|
||||||
|
appendf(s, "null,");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int isString = so->fields[i].type == TYPE_STRING;
|
int isString = so->fields[i].type == TYPE_STRING;
|
||||||
if (isString) {
|
if (isString) {
|
||||||
appendf(s, "\"");
|
appendf(s, "\"");
|
||||||
|
|
|
@ -206,7 +206,7 @@ title "Structs"
|
||||||
check "Struct Definition" "(struct Post (title body))" "T"
|
check "Struct Definition" "(struct Post (title body))" "T"
|
||||||
check "Building a struct"\
|
check "Building a struct"\
|
||||||
'(struct Post (title body)) (Post "A title" "The Body")'\
|
'(struct Post (title body)) (Post "A title" "The Body")'\
|
||||||
'{ title: "A title", body: "The Body" }'
|
'{ "title": "A title", "body": "The Body" }'
|
||||||
check "Accessing struct fields"\
|
check "Accessing struct fields"\
|
||||||
"(struct Post (title body)) (def p (Post \"TITLE\" \"BODY\")) (p.title p.body)"\
|
"(struct Post (title body)) (def p (Post \"TITLE\" \"BODY\")) (p.title p.body)"\
|
||||||
"( TITLE BODY )"
|
"( TITLE BODY )"
|
||||||
|
|
Loading…
Reference in New Issue