cwl-d 0.1.5

Autogenerated classes for reading and writing CWL objects using the D language.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

cwl-d-auto

build license code.dlang.org

Autogenerated classes for reading and writing CWL objects using the D language.

It integrates with schema-salad-d and provides the following features:

  • Support almost all the CWL v1.0, v1.1 and v1.2 documents
  • Load YAML files and nodes to generate corresponding D objects
  • Store D object for CWL to YAML nodes

How is the parser generated?

Each parser is generated with schema-salad-tool as shown below.

  • CWL v1.0
  $ schema-salad-tool --codegen dlang https://github.com/common-workflow-language/common-workflow-language/raw/codegen/v1.0/CommonWorkflowLanguage.yml --codegen-package cwl_d_auto.v1_0 --codegen-parser-info "CWL v1.0 parser generated with schema-salad-tool" --codegen-examples resources/cwl-v1.0 > v1_0.d
  • CWL v1.1
  $ schema-salad-tool --codegen dlang https://github.com/common-workflow-language/cwl-v1.1/raw/codegen/CommonWorkflowLanguage.yml --codegen-package cwl_d_auto.v1_1 --codegen-parser-info "CWL v1.1 parser generated with schema-salad-tool" --codegen-examples resources/cwl-v1.1 > v1_1.d
  • CWL v1.2
  $ schema-salad-tool --codegen dlang https://github.com/common-workflow-language/cwl-v1.2/raw/1.2.1_proposed/CommonWorkflowLanguage.yml --codegen-package cwl_d_auto.v1_2 --codegen-parser-info "CWL v1.2 parser generated with schema-salad-tool" --codegen-examples resources/cwl-v1.2 > v1_2.d
  • You can specify the package name via --codegen-package.
  • You can add informative message into the generated package via --codegen-parser-info. It can be accessed via cwl.v1_2.parserInfo.

How to use

See source/app.d for a concrete example.

import cwl_d_auto.v1_0; // auto generated CWL parser
import salad.resolver : absoluteURI;

import dyaml : Node;
import std : match, tryMatch, writefln;

///// Loading file

auto uri = file.absoluteURI;

// dispatch with std.sumtype.match for loaded object
auto doc = importFromURI(uri).match!(
	// typical case
	(DocumentRootType r) => r,
	// When loaded CWL has `$graph`, the result is DocumentRootType[]
	(DocumentRootType[] rs) => rs[0],
);

// use std.sumtype.tryMatch if you can assume the type of target object 
// The following `tryMatch` assumes `doc` is CLT or Workflow. Otherwise it throws an exception
auto classStr = doc.tryMatch!(
	(CommandLineTool clt) => "CommandLineTool",
	(Workflow wf) => "Workflow",
);
		
writefln!"%s is %s class."(uri, classStr);

///// Convert CWL object to YAML node
auto yamlNode = doc.match!(d => Node(d));

How to run the example

The example just prints the document class of a given CWL document.

$ dub run -c demo -- resources/cwl-v1.0/valid_rename.cwl
...
Running cwl-d-auto resources/cwl-v1.0/valid_rename.cwl
file:///workspaces/cwl-d-auto/resources/cwl-v1.0/valid_rename.cwl is CommandLineTool class.

How to test

It checks that CWL documents in resources can be loaded with parsers in source/cwl_d_auto.

$ dub test

Future plan

  • Support extension fields
  • Support CWL documents that are based on YAML v1.2
  • e.g., Documents in which there is : in the unquoted strings
Authors:
  • Tomoya Tanjo
Dependencies:
schema-salad-d
Versions:
0.3.1 2024-Mar-31
0.3.0 2023-Aug-14
0.2.1 2023-Mar-02
0.2.0 2022-Dec-11
0.1.5 2022-Dec-09
Show all 11 versions
Download Stats:
  • 0 downloads today

  • 14 downloads this week

  • 92 downloads this month

  • 276 downloads total

Score:
1.9
Short URL:
cwl-d.dub.pm