Generic-Syntax

After twenty years of good and loyal service,
it's time to find a successor to XML, HTML and JSON,
erase their many flaws and offer new syntactic possibilities...

{
  title="GS for JSON"
  primitives= [
  	true
  	<#"Hey, we can add comments!">
  	false
  	<#'or comment fragment ✌'[
  	12
  	null
  	]>
  ]
}

GS for JSON

JSON can be written in Generic-Syntax.

GS is more optimized and allows new features like comments.

<html lang=en[
  <head[
    <meta charset=UTF-8>
    <title"GS for HTML">
  ]>
  <body[
    <h1`Title`>
    <p`Paragraph with <em`inline tag`>.`>
    <textarea disabled !"A "bounded escape"
      mechanism allow to never have any
      character escaped, <cool!>!">
    <p ~`The formattable flag <code`~`> explicitly indicates to editors this text can be formatted and indented.`>
  ]>
]>

GS for HTML and XML

Generic-Syntax is a great replacement for HTML and XML.

GS resolves many flaws of these two ancestors and is more optimized.

GS is generic and simple to parse and serialize in any language (unlike HTML).

<Article identifier='5Pl8d4' {
  author= "Author name"
  datePublished= "2020-1-1"
  image= <imageObject {
  	url= "http://example.com/image.png"
  	height=600
  	width=800
  	}>
  publisher= <Organization {
    name="Publisher name"
  	logo=<imageObject url='http://example.com/logo.png'>
  }>
}>

GS for object mapping and graph

Neither JSON nor XML are well suited for object mapping.

Generic-syntax combines map properties of JSON and named nodes of XML and offers a new and efficient syntax for specific purpose like serializing typed object graphs.

GS principles

In GS everything is a node:

node = '<' specialType? name? attribute* body? attribute* '>'

All node parts are optional, when a node has only a body, it can be simplified:

simpleNode = body | rawCharacters

A body can be a terminal text "", a list of nodes [], a map of properties {}, or a mixed content for paragraph and inline tags ``.

rawCharacters is the limited characters set for names, values and body text usable without delimiters:

rawCharacters = [a-zA-Z0-9_:\-./]+
const obj = GSON.parse(`{a=1 b="ok"}`);
console.log(GSON.stringify(obj)); //minified
console.log(GSON.stringify(obj, {serialize:{
  method: 'pretty'
}
}));

const domFragment = GSML.parse('xml', `<node att=value>`);
console.log(GSML.stringify('xml', domFragment)); //minified
console.log(GSML.stringify('xml', domFragment, {serialize:{
  method: 'indented',
  unformat: true,
  indent: '\t'
}
}));

GS API

A high level API provides simple parsing and serialization methods.

A low level API based on a logical and a physical event-driven process provides many more options and extendability.

A first implementation is available in Typescript/Javascript for tests. Generic-Syntax is not ready for production.