flow example from Henry's work

At yesterday's team meeting, Henry presented his work

   https://github.com/xproc/notes/tree/master/design

where he has authored non trivial xproc v1 and xproc v2 pipeline with
the xml syntax to discover API semantics, which he has started to
collect thoughts below:

   https://rawgit.com/xproc/notes/master/design/xmpl.html

These examples are an excellent 'proving ground' for the new flow
syntax and I have attached below.

As we are still discussing specifics of syntax and fleshing out how
expressions may fit into the language I have taken some liberties and
there are some glaring omissions.

The flow syntax is easier to read and easier to follow 'flow' but we
still have a bit of work to make things explicit. If we can get build
up a corpus of such examples, they will serve us well as a guide for
when we start speccing.

J

---------------

xproc version = "2.0";

inputs: $source as document-node()
outputs: $result as document-node()

declare option output:exclude-inline-prefixes="my c p"

declare %required option language
declare %required option match
declare %required option attr

declare flow my:dyer
  inputs: $source as document-node()
  outputs: $result as document-node()
($langage as xs:string,
 $match as xs:string,
 $attr as xs:string
){
$source → replace $match {
  [] → data xml `/*/@{$attr}` ≫ $ca,
  [] → { if($lex($ca))
         then data xml `attribute $attr{ $lex($ca) }`
         else . } ≫ []
 } ≫ $result
}

p:load(href="{$language}.json",
override-content-type="application/json")?colourMap ≫ $lexmap

$source →
  my:dyer(match={$match},lex={$lexmap},attr={$attr}) ≫ $result

Received on Thursday, 3 March 2016 13:35:20 UTC