data serialization format between JSON and BEndcode

  • 1 Replies
  • 2249 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 »

 


Will LLMs ever learn what is ... is?
by HS (Future of AI)
November 10, 2024, 06:28:10 pm
Who's the AI?
by frankinstien (Future of AI)
November 04, 2024, 05:45:05 am
Project Acuitas
by WriterOfMinds (General Project Discussion)
October 27, 2024, 09:17:10 pm
Ai improving AI
by infurl (AI Programming)
October 19, 2024, 03:43:29 am
Atronach's Eye
by WriterOfMinds (Home Made Robots)
October 13, 2024, 09:52:42 pm
Running local AI models
by spydaz (AI Programming)
October 07, 2024, 09:00:53 am
Hi IM BAA---AAACK!!
by MagnusWootton (Home Made Robots)
September 16, 2024, 09:49:10 pm
Attempting Hydraulics
by MagnusWootton (Home Made Robots)
August 19, 2024, 04:03:23 am
LLaMA2 Meta's chatbot released
by spydaz (AI News )
August 24, 2024, 02:58:36 pm
ollama and llama3
by spydaz (AI News )
August 24, 2024, 02:55:13 pm
AI controlled F-16, for real!
by frankinstien (AI News )
June 15, 2024, 05:40:28 am
Open AI GPT-4o - audio, vision, text combined reasoning
by MikeB (AI News )
May 14, 2024, 05:46:48 am
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

Users Online

287 Guests, 0 Users

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

Articles