Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stupid JSON tricks:) #3

Open
dalehenrich opened this issue Mar 30, 2012 · 2 comments
Open

stupid JSON tricks:) #3

dalehenrich opened this issue Mar 30, 2012 · 2 comments

Comments

@dalehenrich
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant