Re: JSON-LD grammar

* Markus Lanthaler <markus.lanthaler@gmx.net> [2013-01-04 18:51+0100]
> As announced in the last mail, I've just fixed the last remaining issues in
> the JSON-LD Grammar section. It definitely does the job, I was just
> wondering whether we should also include a more formal, ABNF-like grammar
> (or maybe even replace the prose). Unfortunately it seems that currently
> there's no accepted way or best-practice to specify JSON "grammars" (the
> JSON Schema Internet Draft expired two years ago [1]).
> 
> So I tried to come up with something ABNF-like (it's not valid ABNF) and
> would be interested in hearing your opinions. I'm not sure myself yet
> whether that helps or confuses people.
> 
> graph = node-obj / node-obj[]
> 
> node-obj =
>     {
>         "@context": context-def       (0..1)
>         "@id": string                 (0..1)
>         "@type": iri / iri[]          (0..1)
>         "@graph": graph               (0..1)
>         "@annotation": string         (0..1)
>         property-key: property-value / property-value[] /
>                       language-map / annotation-map  (*)
>     }
> 
> value-obj =
>     {
>         "@context": context-def    (0..1)
>         "@value": scalar           (0..1)
>         "@language": bcp47-tag / "@type": iri    (0..1)
>         "@annotation": string
>      }
> 
> list-obj =
>     {
>         "@context": context-def       (0..1)
>         "@list": list-set-value / list-set-value[]  (1)
>         "@annotation": string         (0..1)
>     }
> 
> set-obj =
>     {
>         "@context": context-def       (0..1)
>         "@set": list-set-value / list-set-value[]  (1)
>         "@annotation": string         (0..1)
>     }
> 
> language-map =
>     {
>         "@context": context-def       (0..1)
>         bcp47-tag: string / string[]  (*)
>     }
> 
> annotation-map =
>     {
>         "@context": context-def       (0..1)
>         string: property-value / property-value[]   (*)
>     }
> 
> list-set-value = scalar / node-obj / value-obj
> 
> property-value = list-set-value / list-obj / set-obj
> 
> context-def = null / iri / context-def-obj /
>               (null / iri / context-def-obj)[]
> 
> context-def-obj =
>     {
>         property-key: null / iri / term-def-obj   (*)
>         "@language": bcp47-tag      (0..1)
>         "@vocab": iri               (0..1)
>     }
> 
> term-def-obj =
>     {
>         "@id": iri    (0..1)
>         "@language": bcp47-tag / "@type": iri    (0..1)
>         "@container": ( "@list" / "@set" / 
>                         "@language" / "@annotation" )   (0..1)
>     }
> 
> bcp47-tag = string   ; should this be more explicit?
> 
> iri = string         ; should this be more explicit?
> 
> property-key = string - keyword  ; any string except a keyword
> 
> keyword = @context / @id / @value / @language / @type /
>           @container / @list / @set / @annotation / @vocab / @graph
> 
> scalar = null / string / number / true / false


I like it! It reminds me of RNC (my favorite schema language).
You could change "(0..1)" to "?".

It should be pretty easy to compile that into an actual yacc parser à la
http://www.w3.org/2005/01/yacker/uploads/results_JSON?lang=perl&markup=html
to verify and to have a speedy parser.


> [1] http://tools.ietf.org/html/draft-zyp-json-schema-03
> 
> 
> Cheers,
> Markus
> 
> 
> 
> --
> Markus Lanthaler
> @markuslanthaler
> 
> 

-- 
-ericP

Received on Saturday, 5 January 2013 23:07:11 UTC