shexSpec / shex

ShEx language issues, including new features for e.g. ShEx2.1
23 stars 8 forks source link

ShEx functions or macros #31

Open labra opened 7 years ago

labra commented 7 years ago

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)
gkellogg commented 7 years ago

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.

labra commented 7 years ago

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.

ericprud commented 7 years ago

should we have a long-now milestone?

labra commented 7 years ago

ShEx 3.0 ?

dbooth-boston commented 6 years ago

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

labra commented 6 years ago

Done