tree-sitter-haskell


Nametree-sitter-haskell JSON
Version 0.23.1 PyPI version JSON
download
home_pageNone
SummaryHaskell grammar for tree-sitter
upload_time2024-11-10 18:11:30
maintainerTorsten Schmits
docs_urlNone
authorRick Winfrey
requires_python>=3.9
licenseMIT
keywords incremental parsing tree-sitter haskell
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tree-sitter-haskell

[![CI][ci]](https://github.com/tree-sitter/tree-sitter-haskell/actions/workflows/ci.yml)
[![discord][discord]](https://discord.gg/w7nTvsVJhm)
[![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org)
[![crates][crates]](https://crates.io/crates/tree-sitter-haskell)
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-haskell)
[![pypi][pypi]](https://pypi.org/project/tree-sitter-haskell)

Haskell grammar for [tree-sitter].

# References

- [Haskell 2010 Language Report – Syntax References][ref]
- [GHC Language Extensions][ext]

# Supported Language Extensions

These extensions are supported ✅, unsupported ❌ or not applicable because they don't involve parsing ➖️:

- AllowAmbiguousTypes ➖️
- ApplicativeDo ➖️
- Arrows ❌
- BangPatterns ✅
- BinaryLiterals ✅
- BlockArguments ✅
- CApiFFI ✅
- ConstrainedClassMethods ✅
- ConstraintKinds ✅
- CPP ✅
- CUSKs ✅
- DataKinds ✅
- DatatypeContexts ✅
- DefaultSignatures ✅
- DeriveAnyClass ➖️
- DeriveDataTypeable ➖️
- DeriveFoldable ➖️
- DeriveFunctor ➖️
- DeriveGeneric ➖️
- DeriveLift ➖️
- DeriveTraversable ➖️
- DerivingStrategies ✅
- DerivingVia ✅
- DisambiguateRecordFields ➖️
- DuplicateRecordFields ➖️
- EmptyCase ✅
- EmptyDataDecls ✅
- EmptyDataDeriving ✅
- ExistentialQuantification ✅
- ExplicitForAll ✅
- ExplicitNamespaces ✅
- ExtendedDefaultRules ➖️
- FlexibleContexts ✅
- FlexibleInstances ✅
- ForeignFunctionInterface ✅
- FunctionalDependencies ✅
- GADTs ✅
- GADTSyntax ✅
- GeneralisedNewtypeDeriving ➖️
- GHCForeignImportPrim ✅
- Haskell2010 ➖️
- Haskell98 ➖️
- HexFloatLiterals ✅
- ImplicitParams ✅
- ImplicitPrelude ➖️
- ImportQualifiedPost ✅
- ImpredicativeTypes ➖️
- IncoherentInstances ➖️
- InstanceSigs ✅
- InterruptibleFFI ✅
- KindSignatures ✅
- LambdaCase ✅
- LexicalNegation ❌
- LiberalTypeSynonyms ✅
- LinearTypes ✅
- ListTuplePuns ✅
- MagicHash ✅
- Modifiers ❌
- MonadComprehensions ➖️
- MonadFailDesugaring ➖️
- MonoLocalBinds ➖️
- MonomorphismRestriction ➖️
- MultiParamTypeClasses ✅
- MultiWayIf ✅
- NamedFieldPuns ✅
- NamedWildCards ✅
- NegativeLiterals ➖️
- NondecreasingIndentation ✅
- NPlusKPatterns ➖️
- NullaryTypeClasses ✅
- NumDecimals ➖️
- NumericUnderscores ✅
- OverlappingInstances ➖️
- OverloadedLabels ✅
- OverloadedLists ➖️
- OverloadedRecordDot ✅
- OverloadedRecordUpdate ✅
- OverloadedStrings ➖️
- PackageImports ✅
- ParallelListComp ✅
- PartialTypeSignatures ✅
- PatternGuards ✅
- PatternSynonyms ✅
- PolyKinds ➖️
- PostfixOperators ➖️
- QualifiedDo ✅
- QuantifiedConstraints ✅
- QuasiQuotes ✅
- Rank2Types ✅
- RankNTypes ✅
- RebindableSyntax ➖️
- RecordWildCards ➖️
- RecursiveDo ✅
- RequiredTypeArguments ✅
- RoleAnnotations ✅
- Safe ➖️
- ScopedTypeVariables ✅
- StandaloneDeriving ✅
- StandaloneKindSignatures ✅
- StarIsType ✅
- StaticPointers ❌
- Strict ➖️
- StrictData ✅
- TemplateHaskell ✅
- TemplateHaskellQuotes ✅
- TraditionalRecordSyntax ➖️
- TransformListComp ✅
- Trustworthy ➖️
- TupleSections ✅
- TypeAbstractions ✅
- TypeApplications ✅
- TypeData ✅
- TypeFamilies ✅
- TypeFamilyDependencies ✅
- TypeInType ✅
- TypeOperators ✅
- TypeSynonymInstances ➖️
- UnboxedSums ✅
- UnboxedTuples ✅
- UndecidableInstances ➖️
- UndecidableSuperClasses ➖️
- UnicodeSyntax ✅
- UnliftedFFITypes ➖️
- UnliftedNewtypes ✅
- Unsafe ➖️
- ViewPatterns ✅

# Bugs

## CPP

Preprocessor `#elif` and `#else` directives cannot be handled correctly, since the parser state would have to be
manually reset to what it was at the `#if`.
As a workaround, the code blocks in the alternative branches are parsed as part of the directives.

# Querying

The grammar contains several [supertypes](https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types),
which group multiple other node types under a single name.

Supertype names do not occur as extra nodes in parse trees, but they can be used in queries in special ways:

- As an alias, matching any of their subtypes
- As prefix for one of their subtypes, matching its symbol only when it occurs as a production of the supertype

For example, the query `(expression)` matches the nodes `infix`, `record`, `projection`, `constructor`, and the second
and third `variable` in this tree for `cats <> Cat {mood = moods.sleepy}`:

```
(infix
  (variable)
  (operator)
  (record
    (constructor)
    (field_update
      (field_name (variable))
      (projection (variable) (field_name (variable)))))))))
```

The two occurrences of `variable` in `field_name` (`mood` and `sleepy`) are not expressions, but record field names part
of a composite `record` expression.

Matching `variable` nodes specifically that are expressions is possible with the second special form.
A query for `(expression/variable)` will match only the other two, `cats` and `moods`.

The grammar's supertypes consist of the following sets:

- [`expression`](./grammar/exp.js)

  Rules that are valid in any expression position, excluding type applications, explicit types and expression
  signatures.

- [`pattern`](./grammar/pat.js)

  Rules that are valid in any pattern position, excluding type binders, explicit types and pattern signatures.

- [`type`](./grammar/type.js)

  Types that are either atomic (have no ambiguous associativity, like bracketed constructs, variables and type
  constructors), applied types or infix types.

- [`quantified_type`](./grammar/type.js)

  Types prefixed with a `forall`, context or function parameter.

- [`constraint`](./grammar/constraint.js)

  Almost the same rules as `type`, but mirrored for use in contexts.

- [`constraints`](./grammar/constraints.js)

  Analog of `quantified_type`, for constraints with `forall` or context.

- [`type_param`](./grammar/type.js)

  Atomic nodes in type and class heads, like the three nodes following `A` in `data A @k a (b :: k)`.

- [`declaration`](./grammar/module.js)

  All top-level declarations, like functions and data types.

- [`decl`](./grammar/decl.js)

  Shorthand for declarations that are also valid in local bindings (`let` and `where`) and in class and instance bodies,
  except for fixity declarations.
  Consists of `signature`, `function` and `bind`.

- [`class_decl` and `instance_decl`](./grammar/class.js)

  All declarations that are valid in classes and instances, which includes associated type and data families.

- [`statement`](./grammar/exp.js)

  Different forms of `do`-notation statements.

- [`qualifier`](./grammar/exp.js)

  Different forms of list comprehension qualifiers.

- [`guard`](./grammar/exp.js)

  Different forms of guards in function equations and case alternatives.

# Development

The main driver for generating and testing the parser for this grammar is the [tree-sitter CLI][cli].
Other components of the project require additional tools, described below.

Some are made available through `npm` – for example, `npx tree-sitter` runs the CLI.
If you don't have `tree-sitter` available otherwise, prefix all the commands in the following sections with `npx`.

## Output path

The CLI writes the shared library containing the parser to the directory denoted by `$TREE_SITTER_LIBDIR`.
If that variable is unset, it defaults to `$HOME/.cache/tree-sitter/lib`.

In order to avoid clobbering this global directory with development versions, you can set the env var to a local path:

```
export TREE_SITTER_LIBDIR=$PWD/.lib
```

## The grammar

The javascript file `grammar.js` contains the entry point into the grammar's production rules.
Please consult the [tree-sitter documentation][grammar-docs] for a comprehensive introduction to the syntax and
semantics.

Parsing starts with the first item in the `rules` field:

```javascript
{
  rules: {
    haskell: $ => seq(
      optional($.header),
      optional($._body),
    ),
  }
}
```

## Generating the parser

The first step in the development workflow converts the javascript rule definitions to C code in `src/parser.c`:

```
$ tree-sitter generate
```

Two byproducts of this process are written to `src/grammar.json` and `src/node-types.json`.

## Compiling the parser

The C code is automatically compiled by most of the test tools mentioned below, but you can instruct tree-sitter to do
it in one go:

```
$ tree-sitter generate --build
```

If you've set `$TREE_SITTER_LIBDIR` as mentioned above, the shared object will be written to `$PWD/.lib/haskell.so`.

Aside from the generated `src/parser.c`, tree-sitter will also compile and link `src/scanner.c` into this object.
This file contains the _external scanner_, which is a custom extension of the built-in lexer whose purpose is to handle
language constructs that cannot be expressed (efficiently) in the javascript grammar, like Haskell layouts.

### WebAssembly

The parser can be compiled to WebAssembly as well, which requires `emscripten`:

```
$ tree-sitter build --wasm
```

The resulting binary is written to `$PWD/tree-sitter-haskell.wasm`.

## Testing the parser

The most fundamental test infrastructure for tree-sitter grammars consists of a set of code snippets with associated
reference ASTs stored in `./test/corpus/*.txt`.

```
$ tree-sitter test
```

Individual tests can be run by specifying (a substring of) their description with `-f`:

```
$ tree-sitter test -f 'module: exports empty'
```

The project contains several other types of tests:

- `test/parse/run.bash [update] [test names ...]` parses the files in `test/parse/*.hs` and compares the output with
  `test/parse/*.target`.
  If `update` is specified as the first argument, it will update the `.target` file for the first failing test.

- `test/query/run.bash [update] [test names ...]` parses the files in `test/query/*.hs`, applies the queries in
  `test/query/*.query` and compares the output with `test/query/*.target`, similar to `test/parse`.

- `test/rust/parse-test.rs` contains a few tests that use tree-sitter's Rust API to extract the test ranges for
  terminals in a slightly more convenient way.
  This requires `cargo` to be installed, and can be executed with `cargo test` (which also runs the tests in
  `bindings/rust`).

- `test/parse-libs [wasm]` clones a set of Haskell libraries to `test/libs` and parses the entire codebase.
  When invoked as `test/parse-libs wasm`, it will use the WebAssembly parser.
  This requires `bc` to be installed.

- `test/parse-lib name [wasm]` parses only the library `name` in that directory (without cloning the repository).

### Debugging

The shared library built by `tree-sitter test` includes debug symbols, so if the scanner segfaults you can just run
`coredumpctl debug` to inspect the backtrace and memory:

```
newline_lookahead () at src/scanner.c:2583
2583                ((Newline *) 0)->indent = 5;
(gdb) bt
#0  newline_lookahead () at src/scanner.c:2583
#1  0x00007ffff7a0740e in newline_start () at src/scanner.c:2604
#2  scan () at src/scanner.c:2646
#3  eval () at src/scanner.c:2684
#4  tree_sitter_haskell_external_scanner_scan (payload=<optimized out>, lexer=<optimized out>,
    valid_symbols=<optimized out>) at src/scanner.c:2724
#5  0x0000555555772488 in ts_parser.lex ()
```

For more control, launch `gdb tree-sitter` and start the process with `run test -f 'some test'`, and set a breakpoint
with `break tree_sitter_haskell_external_scanner_scan`.

To disable optimizations, run `tree-sitter test --debug-build`.

#### Tracing

The `test` and `parse` commands offer two modes for obtaining detailed information about the parsing process.

With `tree-sitter test --debug`, every lexer step and shift/reduce action is printed to stderr.

With `tree-sitter test --debug-graph`, the CLI will generate an HTML file showing a graph representation of every step.
This requires `graphviz` to be installed.

[tree-sitter]: https://github.com/tree-sitter/tree-sitter
[ref]: https://www.haskell.org/onlinereport/haskell2010/haskellch10.html
[ext]: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/table.html
[cli]: https://github.com/tree-sitter/tree-sitter/tree/master/cli
[grammar-docs]: https://tree-sitter.github.io/tree-sitter/creating-parsers#writing-the-grammar
[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/tree-sitter-haskell/ci.yml?logo=github&label=CI
[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord
[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix
[npm]: https://img.shields.io/npm/v/tree-sitter-haskell?logo=npm
[crates]: https://img.shields.io/crates/v/tree-sitter-haskell?logo=rust
[pypi]: https://img.shields.io/pypi/v/tree-sitter-haskell?logo=pypi&logoColor=ffd242

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tree-sitter-haskell",
    "maintainer": "Torsten Schmits",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "incremental, parsing, tree-sitter, haskell",
    "author": "Rick Winfrey",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/8b/33/113b15c85be3c12ba46f353214b3152639190d970ad1739607952998216d/tree_sitter_haskell-0.23.1.tar.gz",
    "platform": null,
    "description": "# tree-sitter-haskell\n\n[![CI][ci]](https://github.com/tree-sitter/tree-sitter-haskell/actions/workflows/ci.yml)\n[![discord][discord]](https://discord.gg/w7nTvsVJhm)\n[![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org)\n[![crates][crates]](https://crates.io/crates/tree-sitter-haskell)\n[![npm][npm]](https://www.npmjs.com/package/tree-sitter-haskell)\n[![pypi][pypi]](https://pypi.org/project/tree-sitter-haskell)\n\nHaskell grammar for [tree-sitter].\n\n# References\n\n- [Haskell 2010 Language Report \u2013 Syntax References][ref]\n- [GHC Language Extensions][ext]\n\n# Supported Language Extensions\n\nThese extensions are supported \u2705, unsupported \u274c or not applicable because they don't involve parsing \u2796\ufe0f:\n\n- AllowAmbiguousTypes \u2796\ufe0f\n- ApplicativeDo \u2796\ufe0f\n- Arrows \u274c\n- BangPatterns \u2705\n- BinaryLiterals \u2705\n- BlockArguments \u2705\n- CApiFFI \u2705\n- ConstrainedClassMethods \u2705\n- ConstraintKinds \u2705\n- CPP \u2705\n- CUSKs \u2705\n- DataKinds \u2705\n- DatatypeContexts \u2705\n- DefaultSignatures \u2705\n- DeriveAnyClass \u2796\ufe0f\n- DeriveDataTypeable \u2796\ufe0f\n- DeriveFoldable \u2796\ufe0f\n- DeriveFunctor \u2796\ufe0f\n- DeriveGeneric \u2796\ufe0f\n- DeriveLift \u2796\ufe0f\n- DeriveTraversable \u2796\ufe0f\n- DerivingStrategies \u2705\n- DerivingVia \u2705\n- DisambiguateRecordFields \u2796\ufe0f\n- DuplicateRecordFields \u2796\ufe0f\n- EmptyCase \u2705\n- EmptyDataDecls \u2705\n- EmptyDataDeriving \u2705\n- ExistentialQuantification \u2705\n- ExplicitForAll \u2705\n- ExplicitNamespaces \u2705\n- ExtendedDefaultRules \u2796\ufe0f\n- FlexibleContexts \u2705\n- FlexibleInstances \u2705\n- ForeignFunctionInterface \u2705\n- FunctionalDependencies \u2705\n- GADTs \u2705\n- GADTSyntax \u2705\n- GeneralisedNewtypeDeriving \u2796\ufe0f\n- GHCForeignImportPrim \u2705\n- Haskell2010 \u2796\ufe0f\n- Haskell98 \u2796\ufe0f\n- HexFloatLiterals \u2705\n- ImplicitParams \u2705\n- ImplicitPrelude \u2796\ufe0f\n- ImportQualifiedPost \u2705\n- ImpredicativeTypes \u2796\ufe0f\n- IncoherentInstances \u2796\ufe0f\n- InstanceSigs \u2705\n- InterruptibleFFI \u2705\n- KindSignatures \u2705\n- LambdaCase \u2705\n- LexicalNegation \u274c\n- LiberalTypeSynonyms \u2705\n- LinearTypes \u2705\n- ListTuplePuns \u2705\n- MagicHash \u2705\n- Modifiers \u274c\n- MonadComprehensions \u2796\ufe0f\n- MonadFailDesugaring \u2796\ufe0f\n- MonoLocalBinds \u2796\ufe0f\n- MonomorphismRestriction \u2796\ufe0f\n- MultiParamTypeClasses \u2705\n- MultiWayIf \u2705\n- NamedFieldPuns \u2705\n- NamedWildCards \u2705\n- NegativeLiterals \u2796\ufe0f\n- NondecreasingIndentation \u2705\n- NPlusKPatterns \u2796\ufe0f\n- NullaryTypeClasses \u2705\n- NumDecimals \u2796\ufe0f\n- NumericUnderscores \u2705\n- OverlappingInstances \u2796\ufe0f\n- OverloadedLabels \u2705\n- OverloadedLists \u2796\ufe0f\n- OverloadedRecordDot \u2705\n- OverloadedRecordUpdate \u2705\n- OverloadedStrings \u2796\ufe0f\n- PackageImports \u2705\n- ParallelListComp \u2705\n- PartialTypeSignatures \u2705\n- PatternGuards \u2705\n- PatternSynonyms \u2705\n- PolyKinds \u2796\ufe0f\n- PostfixOperators \u2796\ufe0f\n- QualifiedDo \u2705\n- QuantifiedConstraints \u2705\n- QuasiQuotes \u2705\n- Rank2Types \u2705\n- RankNTypes \u2705\n- RebindableSyntax \u2796\ufe0f\n- RecordWildCards \u2796\ufe0f\n- RecursiveDo \u2705\n- RequiredTypeArguments \u2705\n- RoleAnnotations \u2705\n- Safe \u2796\ufe0f\n- ScopedTypeVariables \u2705\n- StandaloneDeriving \u2705\n- StandaloneKindSignatures \u2705\n- StarIsType \u2705\n- StaticPointers \u274c\n- Strict \u2796\ufe0f\n- StrictData \u2705\n- TemplateHaskell \u2705\n- TemplateHaskellQuotes \u2705\n- TraditionalRecordSyntax \u2796\ufe0f\n- TransformListComp \u2705\n- Trustworthy \u2796\ufe0f\n- TupleSections \u2705\n- TypeAbstractions \u2705\n- TypeApplications \u2705\n- TypeData \u2705\n- TypeFamilies \u2705\n- TypeFamilyDependencies \u2705\n- TypeInType \u2705\n- TypeOperators \u2705\n- TypeSynonymInstances \u2796\ufe0f\n- UnboxedSums \u2705\n- UnboxedTuples \u2705\n- UndecidableInstances \u2796\ufe0f\n- UndecidableSuperClasses \u2796\ufe0f\n- UnicodeSyntax \u2705\n- UnliftedFFITypes \u2796\ufe0f\n- UnliftedNewtypes \u2705\n- Unsafe \u2796\ufe0f\n- ViewPatterns \u2705\n\n# Bugs\n\n## CPP\n\nPreprocessor `#elif` and `#else` directives cannot be handled correctly, since the parser state would have to be\nmanually reset to what it was at the `#if`.\nAs a workaround, the code blocks in the alternative branches are parsed as part of the directives.\n\n# Querying\n\nThe grammar contains several [supertypes](https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types),\nwhich group multiple other node types under a single name.\n\nSupertype names do not occur as extra nodes in parse trees, but they can be used in queries in special ways:\n\n- As an alias, matching any of their subtypes\n- As prefix for one of their subtypes, matching its symbol only when it occurs as a production of the supertype\n\nFor example, the query `(expression)` matches the nodes `infix`, `record`, `projection`, `constructor`, and the second\nand third `variable` in this tree for `cats <> Cat {mood = moods.sleepy}`:\n\n```\n(infix\n  (variable)\n  (operator)\n  (record\n    (constructor)\n    (field_update\n      (field_name (variable))\n      (projection (variable) (field_name (variable)))))))))\n```\n\nThe two occurrences of `variable` in `field_name` (`mood` and `sleepy`) are not expressions, but record field names part\nof a composite `record` expression.\n\nMatching `variable` nodes specifically that are expressions is possible with the second special form.\nA query for `(expression/variable)` will match only the other two, `cats` and `moods`.\n\nThe grammar's supertypes consist of the following sets:\n\n- [`expression`](./grammar/exp.js)\n\n  Rules that are valid in any expression position, excluding type applications, explicit types and expression\n  signatures.\n\n- [`pattern`](./grammar/pat.js)\n\n  Rules that are valid in any pattern position, excluding type binders, explicit types and pattern signatures.\n\n- [`type`](./grammar/type.js)\n\n  Types that are either atomic (have no ambiguous associativity, like bracketed constructs, variables and type\n  constructors), applied types or infix types.\n\n- [`quantified_type`](./grammar/type.js)\n\n  Types prefixed with a `forall`, context or function parameter.\n\n- [`constraint`](./grammar/constraint.js)\n\n  Almost the same rules as `type`, but mirrored for use in contexts.\n\n- [`constraints`](./grammar/constraints.js)\n\n  Analog of `quantified_type`, for constraints with `forall` or context.\n\n- [`type_param`](./grammar/type.js)\n\n  Atomic nodes in type and class heads, like the three nodes following `A` in `data A @k a (b :: k)`.\n\n- [`declaration`](./grammar/module.js)\n\n  All top-level declarations, like functions and data types.\n\n- [`decl`](./grammar/decl.js)\n\n  Shorthand for declarations that are also valid in local bindings (`let` and `where`) and in class and instance bodies,\n  except for fixity declarations.\n  Consists of `signature`, `function` and `bind`.\n\n- [`class_decl` and `instance_decl`](./grammar/class.js)\n\n  All declarations that are valid in classes and instances, which includes associated type and data families.\n\n- [`statement`](./grammar/exp.js)\n\n  Different forms of `do`-notation statements.\n\n- [`qualifier`](./grammar/exp.js)\n\n  Different forms of list comprehension qualifiers.\n\n- [`guard`](./grammar/exp.js)\n\n  Different forms of guards in function equations and case alternatives.\n\n# Development\n\nThe main driver for generating and testing the parser for this grammar is the [tree-sitter CLI][cli].\nOther components of the project require additional tools, described below.\n\nSome are made available through `npm` \u2013 for example, `npx tree-sitter` runs the CLI.\nIf you don't have `tree-sitter` available otherwise, prefix all the commands in the following sections with `npx`.\n\n## Output path\n\nThe CLI writes the shared library containing the parser to the directory denoted by `$TREE_SITTER_LIBDIR`.\nIf that variable is unset, it defaults to `$HOME/.cache/tree-sitter/lib`.\n\nIn order to avoid clobbering this global directory with development versions, you can set the env var to a local path:\n\n```\nexport TREE_SITTER_LIBDIR=$PWD/.lib\n```\n\n## The grammar\n\nThe javascript file `grammar.js` contains the entry point into the grammar's production rules.\nPlease consult the [tree-sitter documentation][grammar-docs] for a comprehensive introduction to the syntax and\nsemantics.\n\nParsing starts with the first item in the `rules` field:\n\n```javascript\n{\n  rules: {\n    haskell: $ => seq(\n      optional($.header),\n      optional($._body),\n    ),\n  }\n}\n```\n\n## Generating the parser\n\nThe first step in the development workflow converts the javascript rule definitions to C code in `src/parser.c`:\n\n```\n$ tree-sitter generate\n```\n\nTwo byproducts of this process are written to `src/grammar.json` and `src/node-types.json`.\n\n## Compiling the parser\n\nThe C code is automatically compiled by most of the test tools mentioned below, but you can instruct tree-sitter to do\nit in one go:\n\n```\n$ tree-sitter generate --build\n```\n\nIf you've set `$TREE_SITTER_LIBDIR` as mentioned above, the shared object will be written to `$PWD/.lib/haskell.so`.\n\nAside from the generated `src/parser.c`, tree-sitter will also compile and link `src/scanner.c` into this object.\nThis file contains the _external scanner_, which is a custom extension of the built-in lexer whose purpose is to handle\nlanguage constructs that cannot be expressed (efficiently) in the javascript grammar, like Haskell layouts.\n\n### WebAssembly\n\nThe parser can be compiled to WebAssembly as well, which requires `emscripten`:\n\n```\n$ tree-sitter build --wasm\n```\n\nThe resulting binary is written to `$PWD/tree-sitter-haskell.wasm`.\n\n## Testing the parser\n\nThe most fundamental test infrastructure for tree-sitter grammars consists of a set of code snippets with associated\nreference ASTs stored in `./test/corpus/*.txt`.\n\n```\n$ tree-sitter test\n```\n\nIndividual tests can be run by specifying (a substring of) their description with `-f`:\n\n```\n$ tree-sitter test -f 'module: exports empty'\n```\n\nThe project contains several other types of tests:\n\n- `test/parse/run.bash [update] [test names ...]` parses the files in `test/parse/*.hs` and compares the output with\n  `test/parse/*.target`.\n  If `update` is specified as the first argument, it will update the `.target` file for the first failing test.\n\n- `test/query/run.bash [update] [test names ...]` parses the files in `test/query/*.hs`, applies the queries in\n  `test/query/*.query` and compares the output with `test/query/*.target`, similar to `test/parse`.\n\n- `test/rust/parse-test.rs` contains a few tests that use tree-sitter's Rust API to extract the test ranges for\n  terminals in a slightly more convenient way.\n  This requires `cargo` to be installed, and can be executed with `cargo test` (which also runs the tests in\n  `bindings/rust`).\n\n- `test/parse-libs [wasm]` clones a set of Haskell libraries to `test/libs` and parses the entire codebase.\n  When invoked as `test/parse-libs wasm`, it will use the WebAssembly parser.\n  This requires `bc` to be installed.\n\n- `test/parse-lib name [wasm]` parses only the library `name` in that directory (without cloning the repository).\n\n### Debugging\n\nThe shared library built by `tree-sitter test` includes debug symbols, so if the scanner segfaults you can just run\n`coredumpctl debug` to inspect the backtrace and memory:\n\n```\nnewline_lookahead () at src/scanner.c:2583\n2583                ((Newline *) 0)->indent = 5;\n(gdb) bt\n#0  newline_lookahead () at src/scanner.c:2583\n#1  0x00007ffff7a0740e in newline_start () at src/scanner.c:2604\n#2  scan () at src/scanner.c:2646\n#3  eval () at src/scanner.c:2684\n#4  tree_sitter_haskell_external_scanner_scan (payload=<optimized out>, lexer=<optimized out>,\n    valid_symbols=<optimized out>) at src/scanner.c:2724\n#5  0x0000555555772488 in ts_parser.lex ()\n```\n\nFor more control, launch `gdb tree-sitter` and start the process with `run test -f 'some test'`, and set a breakpoint\nwith `break tree_sitter_haskell_external_scanner_scan`.\n\nTo disable optimizations, run `tree-sitter test --debug-build`.\n\n#### Tracing\n\nThe `test` and `parse` commands offer two modes for obtaining detailed information about the parsing process.\n\nWith `tree-sitter test --debug`, every lexer step and shift/reduce action is printed to stderr.\n\nWith `tree-sitter test --debug-graph`, the CLI will generate an HTML file showing a graph representation of every step.\nThis requires `graphviz` to be installed.\n\n[tree-sitter]: https://github.com/tree-sitter/tree-sitter\n[ref]: https://www.haskell.org/onlinereport/haskell2010/haskellch10.html\n[ext]: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/table.html\n[cli]: https://github.com/tree-sitter/tree-sitter/tree/master/cli\n[grammar-docs]: https://tree-sitter.github.io/tree-sitter/creating-parsers#writing-the-grammar\n[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/tree-sitter-haskell/ci.yml?logo=github&label=CI\n[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord\n[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix\n[npm]: https://img.shields.io/npm/v/tree-sitter-haskell?logo=npm\n[crates]: https://img.shields.io/crates/v/tree-sitter-haskell?logo=rust\n[pypi]: https://img.shields.io/pypi/v/tree-sitter-haskell?logo=pypi&logoColor=ffd242\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Haskell grammar for tree-sitter",
    "version": "0.23.1",
    "project_urls": {
        "Homepage": "https://github.com/tree-sitter/tree-sitter-haskell"
    },
    "split_keywords": [
        "incremental",
        " parsing",
        " tree-sitter",
        " haskell"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fd9b4ea8c9b7e4706ac7de6f4958bff33ff37b521f348a5439516872939d7933",
                "md5": "25acb0b6ff9a10268b6523a1e74140a2",
                "sha256": "f5fee07409e90111107319df223a247a1cf4cb5223f8639219a6b7a7bbde3fd2"
            },
            "downloads": -1,
            "filename": "tree_sitter_haskell-0.23.1-cp39-abi3-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "25acb0b6ff9a10268b6523a1e74140a2",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9",
            "size": 320189,
            "upload_time": "2024-11-10T18:11:19",
            "upload_time_iso_8601": "2024-11-10T18:11:19.748356Z",
            "url": "https://files.pythonhosted.org/packages/fd/9b/4ea8c9b7e4706ac7de6f4958bff33ff37b521f348a5439516872939d7933/tree_sitter_haskell-0.23.1-cp39-abi3-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5cc3efb7849a4b3f18d584901a2d18e39076320a4231756b68892edeff19ff05",
                "md5": "4b90cc5a1275d9e281ec25acebc3f2d1",
                "sha256": "9df79012d26d47ee19988fc3084e369eeea4494c27389f78568151d7bc4a710e"
            },
            "downloads": -1,
            "filename": "tree_sitter_haskell-0.23.1-cp39-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "4b90cc5a1275d9e281ec25acebc3f2d1",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9",
            "size": 349631,
            "upload_time": "2024-11-10T18:11:20",
            "upload_time_iso_8601": "2024-11-10T18:11:20.897545Z",
            "url": "https://files.pythonhosted.org/packages/5c/c3/efb7849a4b3f18d584901a2d18e39076320a4231756b68892edeff19ff05/tree_sitter_haskell-0.23.1-cp39-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b63d764266c1e78c1b7efcbcb6d7fff4c7ec03199218cfb74da0e40fccbc9a07",
                "md5": "9d23b3961e0c73a2617da46ee7ba915e",
                "sha256": "81b817ae855c5505d40a549666d875efaa1d0ff584e36ba76b6dabce9071fd11"
            },
            "downloads": -1,
            "filename": "tree_sitter_haskell-0.23.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "9d23b3961e0c73a2617da46ee7ba915e",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9",
            "size": 427409,
            "upload_time": "2024-11-10T18:11:22",
            "upload_time_iso_8601": "2024-11-10T18:11:22.623597Z",
            "url": "https://files.pythonhosted.org/packages/b6/3d/764266c1e78c1b7efcbcb6d7fff4c7ec03199218cfb74da0e40fccbc9a07/tree_sitter_haskell-0.23.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5e2408092e0848634bb74f7b621218d209022adedd67284d9aeaf41cbb9c9d3",
                "md5": "794b5583ad09183969469e46386262a2",
                "sha256": "fe2d286cc187464ee14259f6765b09d588916e0e6ff5572dea74290f30f3988d"
            },
            "downloads": -1,
            "filename": "tree_sitter_haskell-0.23.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "794b5583ad09183969469e46386262a2",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9",
            "size": 424608,
            "upload_time": "2024-11-10T18:11:24",
            "upload_time_iso_8601": "2024-11-10T18:11:24.299910Z",
            "url": "https://files.pythonhosted.org/packages/a5/e2/408092e0848634bb74f7b621218d209022adedd67284d9aeaf41cbb9c9d3/tree_sitter_haskell-0.23.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c102152d9fdc07e0ce452d4ec5d3d3b0a6c53b3b42d9c10b5d66b23126227b12",
                "md5": "b6ceea40f8d9c258615f50fa3188315a",
                "sha256": "6aa2d29b57842e67ab386aa090072eff64205f42cbd541793b61b1142017012c"
            },
            "downloads": -1,
            "filename": "tree_sitter_haskell-0.23.1-cp39-abi3-musllinux_1_2_x86_64.whl",
            "has_sig": false,
            "md5_digest": "b6ceea40f8d9c258615f50fa3188315a",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9",
            "size": 417808,
            "upload_time": "2024-11-10T18:11:25",
            "upload_time_iso_8601": "2024-11-10T18:11:25.954623Z",
            "url": "https://files.pythonhosted.org/packages/c1/02/152d9fdc07e0ce452d4ec5d3d3b0a6c53b3b42d9c10b5d66b23126227b12/tree_sitter_haskell-0.23.1-cp39-abi3-musllinux_1_2_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8775df1ecd0858e23ca03dc2cf15755538c5a41cc5f024c31bd4d9a1daa4f5f1",
                "md5": "cfe94937cee2f3504c5e0127a0159be1",
                "sha256": "33580ee28caeb38a87e94c3d7ca62e1edb376882085c61f8923cb892a75cbed4"
            },
            "downloads": -1,
            "filename": "tree_sitter_haskell-0.23.1-cp39-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "cfe94937cee2f3504c5e0127a0159be1",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9",
            "size": 314353,
            "upload_time": "2024-11-10T18:11:27",
            "upload_time_iso_8601": "2024-11-10T18:11:27.835178Z",
            "url": "https://files.pythonhosted.org/packages/87/75/df1ecd0858e23ca03dc2cf15755538c5a41cc5f024c31bd4d9a1daa4f5f1/tree_sitter_haskell-0.23.1-cp39-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13099339957119fc91ba400183305ee6ca96a6b741678eabb961b4beaffc9454",
                "md5": "87e80e9774d45ab299d16e33945d40e3",
                "sha256": "b58be70419fe684e6b3990e98b08c913ea9c0583bbf32e7181c1aaece417da7f"
            },
            "downloads": -1,
            "filename": "tree_sitter_haskell-0.23.1-cp39-abi3-win_arm64.whl",
            "has_sig": false,
            "md5_digest": "87e80e9774d45ab299d16e33945d40e3",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9",
            "size": 312365,
            "upload_time": "2024-11-10T18:11:29",
            "upload_time_iso_8601": "2024-11-10T18:11:29.419142Z",
            "url": "https://files.pythonhosted.org/packages/13/09/9339957119fc91ba400183305ee6ca96a6b741678eabb961b4beaffc9454/tree_sitter_haskell-0.23.1-cp39-abi3-win_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b33113b15c85be3c12ba46f353214b3152639190d970ad1739607952998216d",
                "md5": "b29a8b3b850cbaa36f2a187d29cb98c0",
                "sha256": "4e3428b790f2e43bd96a474ed00dc8a8e222c3c50be80b59a2cf73a9895aa652"
            },
            "downloads": -1,
            "filename": "tree_sitter_haskell-0.23.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b29a8b3b850cbaa36f2a187d29cb98c0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 808705,
            "upload_time": "2024-11-10T18:11:30",
            "upload_time_iso_8601": "2024-11-10T18:11:30.523841Z",
            "url": "https://files.pythonhosted.org/packages/8b/33/113b15c85be3c12ba46f353214b3152639190d970ad1739607952998216d/tree_sitter_haskell-0.23.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-10 18:11:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tree-sitter",
    "github_project": "tree-sitter-haskell",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "tree-sitter-haskell"
}
        
Elapsed time: 1.04951s