#tree-sitter #parser #wdl

tree-sitter-wdl-1

WDL 1.x grammar for the tree-sitter parsing library

10 releases

0.1.10 Feb 17, 2023
0.1.8 Feb 13, 2023
0.1.4 Jan 23, 2023
0.1.1 Dec 21, 2022

#2778 in Parser implementations

39 downloads per month

MIT license

355KB
13K SLoC

C 12K SLoC JavaScript 687 SLoC // 0.0% comments C++ 395 SLoC Rust 62 SLoC

tree-sitter-wdl

Tree-sitter grammar for WDL (Workflow Description Language).

Usage

See the Tree-sitter documentation for the list of available language bindings and basic usage information. To use the Rust binding, add the following to your Cargo.toml:

[dependencies]
tree-sitter-wdl-1 = "0.1.0"

A convenience function is provided to create a new TreeSitter parser with the language set to tree-sitter-wdl-1:

use tree_sitter_wdl_1 as wdl;

fn main() {
    let parser = wdl::parser().expect("Error creating WDL parser");
    ...
}

There is also a convenience function to parse a single document into a tree_sitter::Tree:

use tree_sitter::Tree;
use tree_sitter_wdl_1 as wdl;

fn main() {
    let text = r#"
    version 1.0

    workflow foo {
    }
    "#;
    let tree: Tree = wdl::parse_document(text).expect("Error parsing WDL parser");
    ...
}

Design

This repository provides a single grammar that parses WDL versions 1.x (draft-* and development versions are not supported). The grammar is designed to be permissive and error-tolerant. A parser generated from this grammar will allow token combinations that are forbidden by the WDL specification or that are only allowed in certain WDL versions.

As Tree-sitter generates LR(1) parsers, only one token of look-ahead is available and thus syntax elements that require multiple tokens of look-ahead are difficult or impossible to write. For WDL, this means strings (including the contents of the command block) cannot be described by the grammar. Fortunately, Tree-sitter allows for external parsing of these syntax elements. The external parser for the WDL grammar is in scanner.cc and implements the API described in the Tree-sitter documentation.

Development

  • Follow the instructions to install the Tree-sitter CLI
  • Generate and compile the parser: npm run build
  • Run the tests npm run test

Dependencies

~3–5MB
~96K SLoC