#150 Proposed serialization syntax

brian Wed 15 Aug 2007

Here is what I'm thinking for the grammar of the Fan serialization syntax:

doc     := usings | obj
obj     := complex | simple | literal
literal := bool | int | float | str | duration | uri | list | map | type // same as Fan source
simple  := type "(" str ")"
complex := type "{" fields "}"
fields  := field (eos field)*
eos     := ";" | newline
field   := id "=" obj
type    := // same as Fan

The using declarations work just like Fan to allow non-qualified type names. Both /* and // comments are supported.

Here is an example:

using user

fand::App
{
  user = user::UserService
  {
    enabled = true
    users = // list
    [
      user::User { name = "brian"; bday = sys::Time "1972-6-7" }
      User { name = "andy";  bday = Time("1980-10-22") }
    ]
  }

  web = web::WebService
  {
    port = 80
  }

  env = [ "a":"alpha", "b":"beta" ] // map
}

Semantically "type { f1 = obj1; f2 = obj2 } maps directly to:

x := type.make
x->f1 = obj1
x->f2 = obj2

And "type(str)" maps directly to:

x := type.parse (str)

Open Issues:

  1. Simples will be denoted by a mixin? Annotation?
  2. Complex fields are denoted by keyword? Annotation?
  3. How deep do complex's serialize? Notation of "extent"
  4. How are non-tree relationships/references serialized?
  5. Should facets be part of syntax?
  6. What is API look like? Is this just new methods on InStream and OutStream?
  7. Can this syntax be used directly in Fan source code?

Login or Signup to reply.