{"id":13480275,"url":"https://github.com/tree-sitter/tree-sitter-haskell","last_synced_at":"2025-10-09T05:41:05.412Z","repository":{"id":38803118,"uuid":"52014188","full_name":"tree-sitter/tree-sitter-haskell","owner":"tree-sitter","description":"Haskell grammar for tree-sitter.","archived":false,"fork":false,"pushed_at":"2025-08-29T03:18:04.000Z","size":283563,"stargazers_count":171,"open_issues_count":23,"forks_count":42,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-10-08T09:22:16.274Z","etag":null,"topics":["haskell","parser","tree-sitter"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tree-sitter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-02-18T14:45:59.000Z","updated_at":"2025-08-17T20:16:48.000Z","dependencies_parsed_at":"2023-09-25T03:51:44.694Z","dependency_job_id":"e2cd010f-ee28-4bc1-af6c-19d37b3d38e7","html_url":"https://github.com/tree-sitter/tree-sitter-haskell","commit_stats":{"total_commits":952,"total_committers":22,"mean_commits":43.27272727272727,"dds":"0.22899159663865543","last_synced_commit":"2c2fcb22e3b939ed59ae8d6f10500c3213c68670"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/tree-sitter/tree-sitter-haskell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Ftree-sitter-haskell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Ftree-sitter-haskell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Ftree-sitter-haskell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Ftree-sitter-haskell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tree-sitter","download_url":"https://codeload.github.com/tree-sitter/tree-sitter-haskell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tree-sitter%2Ftree-sitter-haskell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000741,"owners_count":26082932,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haskell","parser","tree-sitter"],"created_at":"2024-07-31T17:00:36.626Z","updated_at":"2025-10-09T05:41:05.385Z","avatar_url":"https://github.com/tree-sitter.png","language":"C","funding_links":[],"categories":["C","Grammars"],"sub_categories":["Tree Sitter Org"],"readme":"# 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 – Syntax References][ref]\n- [GHC Language Extensions][ext]\n\n# Supported Language Extensions\n\nThese extensions are supported ✅, unsupported ❌ or not applicable because they don't involve parsing ➖️:\n\n- AllowAmbiguousTypes ➖️\n- ApplicativeDo ➖️\n- Arrows ❌\n- BangPatterns ✅\n- BinaryLiterals ✅\n- BlockArguments ✅\n- CApiFFI ✅\n- ConstrainedClassMethods ✅\n- ConstraintKinds ✅\n- CPP ✅\n- CUSKs ✅\n- DataKinds ✅\n- DatatypeContexts ✅\n- DefaultSignatures ✅\n- DeriveAnyClass ➖️\n- DeriveDataTypeable ➖️\n- DeriveFoldable ➖️\n- DeriveFunctor ➖️\n- DeriveGeneric ➖️\n- DeriveLift ➖️\n- DeriveTraversable ➖️\n- DerivingStrategies ✅\n- DerivingVia ✅\n- DisambiguateRecordFields ➖️\n- DuplicateRecordFields ➖️\n- EmptyCase ✅\n- EmptyDataDecls ✅\n- EmptyDataDeriving ✅\n- ExistentialQuantification ✅\n- ExplicitForAll ✅\n- ExplicitNamespaces ✅\n- ExtendedDefaultRules ➖️\n- FlexibleContexts ✅\n- FlexibleInstances ✅\n- ForeignFunctionInterface ✅\n- FunctionalDependencies ✅\n- GADTs ✅\n- GADTSyntax ✅\n- GeneralisedNewtypeDeriving ➖️\n- GHCForeignImportPrim ✅\n- Haskell2010 ➖️\n- Haskell98 ➖️\n- HexFloatLiterals ✅\n- ImplicitParams ✅\n- ImplicitPrelude ➖️\n- ImportQualifiedPost ✅\n- ImpredicativeTypes ➖️\n- IncoherentInstances ➖️\n- InstanceSigs ✅\n- InterruptibleFFI ✅\n- KindSignatures ✅\n- LambdaCase ✅\n- LexicalNegation ❌\n- LiberalTypeSynonyms ✅\n- LinearTypes ✅\n- ListTuplePuns ✅\n- MagicHash ✅\n- Modifiers ❌\n- MonadComprehensions ➖️\n- MonadFailDesugaring ➖️\n- MonoLocalBinds ➖️\n- MonomorphismRestriction ➖️\n- MultiParamTypeClasses ✅\n- MultiWayIf ✅\n- NamedFieldPuns ✅\n- NamedWildCards ✅\n- NegativeLiterals ➖️\n- NondecreasingIndentation ✅\n- NPlusKPatterns ➖️\n- NullaryTypeClasses ✅\n- NumDecimals ➖️\n- NumericUnderscores ✅\n- OverlappingInstances ➖️\n- OverloadedLabels ✅\n- OverloadedLists ➖️\n- OverloadedRecordDot ✅\n- OverloadedRecordUpdate ✅\n- OverloadedStrings ➖️\n- PackageImports ✅\n- ParallelListComp ✅\n- PartialTypeSignatures ✅\n- PatternGuards ✅\n- PatternSynonyms ✅\n- PolyKinds ➖️\n- PostfixOperators ➖️\n- QualifiedDo ✅\n- QuantifiedConstraints ✅\n- QuasiQuotes ✅\n- Rank2Types ✅\n- RankNTypes ✅\n- RebindableSyntax ➖️\n- RecordWildCards ➖️\n- RecursiveDo ✅\n- RequiredTypeArguments ✅\n- RoleAnnotations ✅\n- Safe ➖️\n- ScopedTypeVariables ✅\n- StandaloneDeriving ✅\n- StandaloneKindSignatures ✅\n- StarIsType ✅\n- StaticPointers ❌\n- Strict ➖️\n- StrictData ✅\n- TemplateHaskell ✅\n- TemplateHaskellQuotes ✅\n- TraditionalRecordSyntax ➖️\n- TransformListComp ✅\n- Trustworthy ➖️\n- TupleSections ✅\n- TypeAbstractions ✅\n- TypeApplications ✅\n- TypeData ✅\n- TypeFamilies ✅\n- TypeFamilyDependencies ✅\n- TypeInType ✅\n- TypeOperators ✅\n- TypeSynonymInstances ➖️\n- UnboxedSums ✅\n- UnboxedTuples ✅\n- UndecidableInstances ➖️\n- UndecidableSuperClasses ➖️\n- UnicodeSyntax ✅\n- UnliftedFFITypes ➖️\n- UnliftedNewtypes ✅\n- Unsafe ➖️\n- ViewPatterns ✅\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 \u003c\u003e 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` – 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: $ =\u003e 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)-\u003eindent = 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=\u003coptimized out\u003e, lexer=\u003coptimized out\u003e,\n    valid_symbols=\u003coptimized out\u003e) 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\u0026label=CI\n[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord\u0026label=discord\n[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix\u0026label=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\u0026logoColor=ffd242\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftree-sitter%2Ftree-sitter-haskell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftree-sitter%2Ftree-sitter-haskell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftree-sitter%2Ftree-sitter-haskell/lists"}