• Stars
    star
    146
  • Rank 244,741 (Top 5 %)
  • Language
    C
  • License
    MIT License
  • Created about 8 years ago
  • Updated 12 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Haskell grammar for tree-sitter.

tree-sitter-haskell

CI

Haskell grammar for tree-sitter.

References

Building with nvim-treesitter

When installing the grammar from source, be sure to include the scanner in the source files:

lua <<EOF
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.haskell = {
  install_info = {
    url = "~/path/to/tree-sitter-haskell",
    files = {"src/parser.c", "src/scanner.c", "src/unicode.h"}
  }
}
EOF

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 βœ…
  • 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 βœ…
  • RoleAnnotations βœ…
  • Safe βž–οΈ
  • ScopedTypeVariables βœ…
  • StandaloneDeriving βœ…
  • StandaloneKindSignatures βœ…
  • StarIsType βœ…
  • StaticPointers ❌
  • Strict βž–οΈ
  • StrictData βœ…
  • TemplateHaskell βœ…
  • TemplateHaskellQuotes βœ…
  • TraditionalRecordSyntax βž–οΈ
  • TransformListComp βœ…
  • Trustworthy βž–οΈ
  • TupleSections βœ…
  • 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.

Layout

NondecreasingIndentation is not supported (yet?).

Operators on newlines in do

A strange edge case is when an infix operator follows an expression statement of a do block with an indent of less or equal the do's layout column:

f = do
  readSomething
  >>= doSomething

The >>= causes the do's layout to be terminated, resulting in an AST similar to

f = (do readSomething) >>= doSomething

This is checked heuristically, probably unreliably.

Testing

Requires: tree-sitter(-cli)

Run test corpus

These are stored in ./tests/corpus/

$ tree-sitter test

Test parsing an example codebase

Requires: bc This will print the percentage of the codebase parsed, and the time taken

$ ./script/parse-examples             # this clones all repos
$ ./script/parse-example <example>    # where <example> is a project under ./examples/

Enable scanner debug output

To get an extra-verbose scanner, unoptimized, with debug symbols:

$ CFLAGS='-DDEBUG' make debug.so
$ cp debug.so $HOME/.cache/tree-sitter/lib/haskell.so    # So `tree-sitter-cli` uses our binary
$ tree-sitter test
$ ./script/parse-example <example>

If you want to debug the scanner with gdb, you can b tree_sitter_haskell_external_scanner_scan with tree-sitter test.

Create visual graph of parser steps

Requires: graphviz

$ tree-sitter parse -D test/Basic.hs    # Produces log.html

More Repositories

1

tree-sitter

An incremental parsing system for programming tools
Rust
16,473
star
2

py-tree-sitter

Python bindings to the Tree-sitter parsing library
C
690
star
3

node-tree-sitter

Node.js bindings for tree-sitter
C++
464
star
4

tree-sitter-rust

Rust grammar for tree-sitter
JavaScript
318
star
5

tree-sitter-typescript

TypeScript grammar for tree-sitter
JavaScript
272
star
6

tree-sitter-javascript

Javascript grammar for tree-sitter
JavaScript
272
star
7

tree-sitter-python

Python grammar for tree-sitter
JavaScript
261
star
8

tree-sitter-go

Go grammar for tree-sitter
JavaScript
224
star
9

tree-sitter-cpp

C++ grammar for tree-sitter
JavaScript
198
star
10

tree-sitter-graph

Construct graphs from parsed source code
Rust
182
star
11

tree-sitter-c

C grammar for tree-sitter
JavaScript
175
star
12

tree-sitter-c-sharp

C# Grammar for tree-sitter
JavaScript
172
star
13

tree-sitter-scala

Scala grammar for tree-sitter
JavaScript
153
star
14

tree-sitter-bash

Bash grammar for tree-sitter
JavaScript
152
star
15

tree-sitter-ruby

Ruby grammar for tree-sitter
JavaScript
137
star
16

haskell-tree-sitter

Haskell bindings for tree-sitter
Haskell
137
star
17

tree-sitter-java

Java grammar for tree-sitter
JavaScript
86
star
18

tree-sitter-php

PHP grammar for tree-sitter
JavaScript
86
star
19

tree-sitter-json

JSON grammar for tree-sitter
Makefile
86
star
20

tree-sitter-verilog

SystemVerilog grammar for tree-sitter
C
85
star
21

tree-sitter-html

HTML grammar for Tree-sitter
C++
82
star
22

tree-sitter-julia

Julia grammar for Tree-sitter
JavaScript
78
star
23

tree-sitter-ocaml

OCaml grammar for tree-sitter
JavaScript
71
star
24

tree-sitter-css

CSS grammar for Tree-sitter
JavaScript
66
star
25

ruby-tree-sitter.old

Ruby bindings to tree-sitter
C
60
star
26

tree-sitter-swift

Swift grammar for tree-sitter
JavaScript
56
star
27

tree-sitter-regex

Tree-sitter parser for regular expressions
JavaScript
47
star
28

tree-sitter-cli

CLI tool for creating and testing tree-sitter parsers
JavaScript
43
star
29

tree-sitter-embedded-template

Tree-sitter grammar for embedded template languages like ERB, EJS
C
34
star
30

rust-tree-sitter

Rust bindings to Tree-sitter
Rust
30
star
31

tree-sitter-agda

Agda grammar for tree-sitter
Yacc
29
star
32

tree-sitter-jsdoc

JSDoc grammar for Tree-sitter
Rust
20
star
33

tree-sitter-ql

tree-sitter grammar for the CodeQL language
JavaScript
15
star
34

tree-sitter.github.io

Source HTML for the Tree-sitter organization site
JavaScript
10
star
35

highlight-schema

Schema for syntax highlighting property sheets
JavaScript
7
star
36

csharp-tree-sitter

C# bindings to the Tree-sitter parsing library
C#
6
star
37

tree-sitter-tsq

tree-sitter grammar for the tree-sitter query language
JavaScript
6
star
38

afl-tree-sitter

AFL test harness for tree-sitter runtime and parsers
C
5
star
39

tree-sitter-fluent

JavaScript
4
star
40

tree-sitter-razor

(WIP) C# Razor grammar for tree-sitter
C
4
star
41

tree-sitter-ql-dbscheme

tree-sitter support for `.dbscheme` files (as used in CodeQL).
C
2
star
42

.github

Tree-sitter organization info
1
star