shex icon indicating copy to clipboard operation
shex copied to clipboard

ShEx functions or macros

Open labra opened this issue 8 years ago • 6 comments

Any language will sooner or later need an abstraction mechanism where one can declare some common parts with some parameters that can be reused.

As an example, this ShEx file contains:

<OneOf> CLOSED {
  a [sx:OneOf] ;
  sx:min xsd:integer? ;
  sx:max xsd:integer OR ["*"]? ;
  sx:expressions @<tripleExpressionList2Plus> ;
  sx:semActs @<SemActList1Plus>? ;
  sx:annotation @<Annotation>*
}

<EachOf> CLOSED {
  a [sx:EachOf] ;
  sx:min xsd:integer? ;
  sx:max xsd:integer OR ["*"]? ;
  sx:expressions @<tripleExpressionList2Plus> ;
  sx:semActs @<SemActList1Plus>? ;
  sx:annotation @<Annotation>*
}

which looks very repetitive.

One possible syntax could be:

Let TripleExprComponent(?x) = CLOSED {
  a [?x] ;
  sx:min xsd:integer? ;
  sx:max xsd:integer OR ["*"]? ;
  sx:expressions @<tripleExpressionList2Plus> ;
  sx:semActs @<SemActList1Plus>? ;
  sx:annotation @<Annotation>*
}

<OneOf> TripleExprComponent(sx:OneOf)
<EachOf> TripleExprComponent(sx:EachOf)

labra avatar Jan 22 '17 07:01 labra

Why not just use ShapeAnd?:

<OneOf> @<TripleExprComponent> AND {
  a [sx:OneOf] ;
}

<EachOf> @<TripleExprComponent> AND {
  a [sx:EachOf] ;
}

<TripleExprComponent> CLOSED {
  a . ;
  sx:min xsd:integer? ;
  sx:max xsd:integer OR ["*"]? ;
  sx:expressions @<tripleExpressionList2Plus> ;
  sx:semActs @<SemActList1Plus>? ;
  sx:annotation @<Annotation>*
}

Of course, there may be other cases where parameterization would come in handy. I would think it would be more of a macro-feature in ShExC.

gkellogg avatar Jan 23 '17 18:01 gkellogg

That's a nice solution for that use case that I had not consider. Thanks.

Anyway, as you say, having some kind of macro facility is something that will be useful.

I don't suggest this feature for the next version of ShEx, although I wanted to record it as a feature to consider in the future.

labra avatar Jan 23 '17 21:01 labra

should we have a long-now milestone?

ericprud avatar Jan 23 '17 21:01 ericprud

ShEx 3.0 ?

labra avatar Jan 23 '17 22:01 labra

I suggest re-titling this issue to "ShEx functions or macros".

dbooth-boston avatar Nov 06 '17 16:11 dbooth-boston

Done

labra avatar Nov 06 '17 19:11 labra