+ JSG support for array cardinality

The JSON Grammar[1] description for ShExJ was underconstrained. If you
follow the parsing rules to transform ShExC to ShExJ, most of the
resulting JSON arrays may not be empty. Additionally, ShapeAnd and
ShapeOr need two or more elements.

I've updated JSG to support cardinality constraints within arrays.
By way of illustration,

  person { addrs:[addresss] }
  address { street:NAME }
  NAME : .*;

accepts an object 0 addrs:

  { "addrs":[] }

but if we require 1 or more:

  person { addrs:[addresss+] }
  address { street:NAME }
  NAME : .*;

it rejects anything without an Addr but accepts 1 or more:

  { "addrs":[{"street": "Elm"}] }

This accepts they usual [+*?] cardinalities, as well as ranges. These
are good for e.g. disjunctions which require 2 or more disjuncts:

  Expr = Or | ATOM ;
  Or { disjuncts:[Expr{2,}] }
  ATOM : [a-z] ;

will reject

  { "disjuncts": [ "a" ] }

but accept

  { "disjuncts": [ "b", "c" ] }
or
  { "disjuncts": [ "d", "f", "g" ] }

I haven't updated the ShEx spec's JSG[2], but I have updated the JSG
for ShExJ[3] and ShExR[4]. The new schema clarifies that e.g.
"startActs" is an optional list of 1 or more SemActs:

  Schema { ... startActs:[SemAct+]? ... }

(i.e. no empty lists like { "type":"Schema", "startActs":[] ... })

It also requires ShapeAnd, ShapeOr[6] to have two or more shapeExprs
and EachOf, OneOf[7] to have one or more tripleExprs.

Here are the deltas that need to go into the spec[8], in case someone
wants to do some edits.


[1] https://github.com/ericprud/jsg
[2] http://w3c.github.io/hcls-fhir-rdf/spec/
[3] https://github.com/shexSpec/shexTest/blob/master/doc/ShExJ.jsg
[4] https://github.com/shexSpec/shexTest/blob/master/doc/ShExJ.jsg
[5] https://github.com/shexSpec/shexTest/blob/master/doc/ShExJ.jsg#L13
[6] https://github.com/shexSpec/shexTest/blob/master/doc/ShExJ.jsg#L15
[7] https://github.com/shexSpec/shexTest/blob/master/doc/ShExJ.jsg#L23
[8] https://github.com/shexSpec/shexTest/commit/971da93a384231381b54bb9fa85a1c2804ffa44d
-- 
-ericP

office: +1.617.599.3509
mobile: +33.6.80.80.35.59

(eric@w3.org)
Feel free to forward this message to any list for any purpose other than
email address distribution.

There are subtle nuances encoded in font variation and clever layout
which can only be seen by printing this message on high-clay paper.

Received on Wednesday, 28 December 2016 15:32:23 UTC