Open dalehenrich opened 12 years ago
another shot at the package structure JSON ... For those who are keeping score, some escaping and had to add named fields and arrays of objects in some places since even though in Smalltalk we think of JSON objects as dictionaries (at least with the parser that I've used) that's an implementation detail that doesn't hold when using the structure as javascript objects (in Amber):
{
"name" : "Cypress-Mocks.package",
"contents" : [
{ "name" : "CypressMockBasic.class",
"class" : [
{ "name" : "current.json",
"contents" : { "category" : "accessing" }},
{ "name" : "current.st",
"contents" : "current%0A%09^current" },
{ "name" : "current..json",
"contents" : { "category" : "accessing" }} ,
{ "name" : "current..st",
"contents" : "current: anObject%0A%09current := anObject"},
{ "name" : "initialize.json",
"contents" : { "category" : "initialization"}},
{ "name" : "initialize.st",
"contents" : "initialize%0A%09self current: self new"}
],
"instance" : [
{ "name" : "extra.json",
"contents" : { "category" : "accessing" } },
{ "name" : "extra.st",
"contents" : "extra%0A%09%22extra method%22"},
{ "name" : "initialize.json",
"contents" : { "category" : "initialization" } },
{ "name" : "initialize.st",
"contents" : "initialize%0A%09super initialize.%0A%09self name: 'Unknown'" },
{ "name" : "name.json",
"contents" : { "category" : "accessing" } } ,
{ "name" : "name.st",
"contents" : "name%0A%09^name" },
{ "name" : "name..json",
"contents" : { "category" : "accessing" } } ,
{ "name" : "name..st",
"contents" : "name: aString%0A%09name := aString" }
],
"properties.json" : {
"instvars" : [ "name" ],
"classinstvars" : [ "current" ],
"name" : "CypressMockBasic",
"super" : "Object"
}
}
],
"properties.json" : {
}
}
Yes ... with the escaping that is needed for newlines and other common characters in Smalltalk source ... it doesn't look like JSON will be a good disk-based, single file format ... unless we want to simulate a binary format in ascii ...
It turns out that for supporting Cypress in Amber, it is necessary to create a JSON form of the package structure like the following:
The mapping fits very well (of course), but it brings up a point that it might be convenient to support the JSON format as well as the disk structure as the JSON format is pretty convenient for bootstrapping purposes ...
I'll be writing code to handle JSON for Amber anyway