data serialization format between JSON and BEndcode

  • 1 Replies
  • 2073 Views
*

Zero

  • Eve
  • ***********
  • 1287
data serialization format between JSON and BEndcode
« on: March 23, 2016, 04:29:29 pm »
Hi guys,

I made a little data serialization format.

Strings are between <>
Numbers are between ()
Lists are between []
Dicts are between {}

The following pegjs...
Code
{
  function flat(p){
var result = {};
for (var i = 0; i < p.length; i++) {
result[Object.keys(p[i])] = p[i][Object.keys(p[i])];
}
    return result
  }
}

entry
= _ v:val_ { return v }

_
= [ \n\t]*

val_
= v:value _ { return v }

value
= list / dict / num / text

list
= "[*]" { return "?L" }
/ "[" _ v:val_* "]" { return v }

dict
= "{*}" { return "?D" }
/ "{" _ p:pair* "}" { return flat(p) }

num
= "(*)" { return "?N" }
/ "(" _ d:digit* _ ")" { return parseFloat(d.join("")) }

text
= "<*>" { return "?T" }
/ "<" n:noqm c:char* ">" { return n+c.join("") }

pair
= k:val_ v:val_ { var res={}; res[k]=v; return res }

digit
= [0-9.e]

noqm
= [^<>~?]
/ "~~" { return "~" }
/ "~<" { return "<" }
/ "~>" { return ">" }
/ "~*" { return "~*" }

char
= "?" / noqm
...would turn this...
Code
{
  <A list> [*]
  <A dict> {*}
  <foo>    { <bar>(1) <ok><*> }
  <first>  [
    <one>
    <two>
    <three>
  ]
}
...into this...
Code
{
   "A list": "?L",
   "A dict": "?D",
   "foo": {
      "bar": 1,
      "ok": "?T"
   },
   "first": [
      "one",
      "two",
      "three"
   ]
}

Code
The first character of strings should not be "?".
[*] is a list-wildcard that's turned into "?L"
{*} is a dict-wildcard that's turned into "?D"
(*) is a num-wildcard that's turned into "?N"
<*> is a text-wildcard that's turned into "?T"
It doesn't have a name :)

*

Zero

  • Eve
  • ***********
  • 1287
Re: data serialization format between JSON and BEndcode
« Reply #1 on: March 26, 2016, 09:40:26 am »
There's a mistake in the previous pegjs syntax: numbers couldn't be negative. Here's a fix:
Code
{
  function flat(p){
var result = {};
for (var i = 0; i < p.length; i++) {
result[Object.keys(p[i])] = p[i][Object.keys(p[i])];
}
    return result
  }
}

entry
= _ v:val_ { return v }

_
= [ \n\t]*

val_
= v:value _ { return v }

value
= list / dict / num / text

list
= "[*]" { return "?L" }
/ "[" _ v:val_* "]" { return v }

dict
= "{*}" { return "?D" }
/ "{" _ p:pair* "}" { return flat(p) }

num
= "(*)" { return "?N" }
/ "(" _ d:digit* _ ")" { return parseFloat(d.join("")) }

text
= "<*>" { return "?T" }
/ "<" n:noqm c:char* ">" { return n+c.join("") }

pair
= k:val_ v:val_ { var res={}; res[k]=v; return res }

digit
= [\-0-9.e]

noqm
= [^<>~?]
/ "~~" { return "~" }
/ "~<" { return "<" }
/ "~>" { return ">" }
/ "~*" { return "~*" }

char
= "?" / noqm



Good thing with this syntax is that there's room to add tags or labels or names before elements. Like
Code
tag1<a string>tag2<another one>
Here tag1 and tag2 are not part of the data. They are external metadata, that can be used for any purpose.

Another good thing is, since we don't use quotes and double quotes, it is very easy to generate from casual programming languages.

Now I'd like to mix it with my coordination/subordination thing, but I still don't know how...

EDIT:
Still working on Noisett... forgetting the coordination/subordination thing, tags can be used in simple glob pattern matching, to select parts of a structured chunk of data, parts which are enclosed between specific metadata.

Code

Say, a Nut sends this to another one:
[
              <this is>
  interesting <a list>
              <of strings> part
]

This is a simple list of strings. Two of these strings are enclosed between "interesting" and "part". So we use this to extract what we want, like this:

IF: * interesting * part *
SHARE: got $2

This would extract our two strings: <a list><of strings>




« Last Edit: March 26, 2016, 02:07:13 pm by Zero »

 


OpenAI Speech-to-Speech Reasoning Demo
by MikeB (AI News )
March 31, 2024, 01:00:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am
Nvidia Hype
by 8pla.net (AI News )
December 06, 2023, 10:04:52 pm
How will the OpenAI CEO being Fired affect ChatGPT?
by 8pla.net (AI News )
December 06, 2023, 09:54:25 pm
Independent AI sovereignties
by WriterOfMinds (AI News )
November 08, 2023, 04:51:21 am
LLaMA2 Meta's chatbot released
by 8pla.net (AI News )
October 18, 2023, 11:41:21 pm

Users Online

271 Guests, 0 Users

Most Online Today: 296. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles