CampSmalltalk / Cypress

A cross Smalltalk dialect, disk-based package import/export format, inspired by the https://github.com/dalehenrich/filetree project.
MIT License
28 stars 1 forks source link

stupid JSON tricks:) #3

Open dalehenrich opened 12 years ago

dalehenrich commented 12 years ago

It turns out that for supporting Cypress in Amber, it is necessary to create a JSON form of the package structure like the following:

{ "Cypress-Mocks.package" :  {
    "CypressMockBasic.class" : {
        "class" :  {
            "current.json" : { "category" : "accessing" },
            "current.st" : "current
        ^current",
            "current..json" : { "category" : "accessing" } ,
         "current..st" : "current: anObject
        current := anObject",
            "initialize.json" : { "category" : "initialization"},
            "initialize.st" : "initialize
        self current: self new"
        },
        "instance" : {
            "extra.json" : { "category" : "accessing" } ,
            "extra.st" : "extra
        ",
            "initialize.json" : { "category" : "initialization" } ,
            "initialize.st" : "initialize
        super initialize.
        self name: 'Unknown'",
            "name.json" : { "category" : "accessing" } ,
            "name.st" : "name
        ^name",
            "name..json" : { "category" : "accessing" } ,
            "name..st" : "name: aString
        name := aString"
        },
        "properties.json" : {
            "instvars" : [ "name" ],
            "classinstvars" : [ "current" ],
            "name" : "CypressMockBasic",
            "super" : "Object" }
        }
    }
}

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

dalehenrich commented 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" : {
  }
}
dalehenrich commented 12 years ago

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 ...