Merge commit 'cf394604ae2ec2a5e65b1afbc7dea21258ede403'

pull/315/head
Wilfred Hughes 2022-07-10 23:00:27 +07:00
commit 2e0a7da8ea
23 changed files with 420295 additions and 364454 deletions

@ -13,21 +13,21 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.72"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "memchr"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "regex"
version = "1.5.4"
version = "1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1"
dependencies = [
"aho-corasick",
"memchr",
@ -36,15 +36,15 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.25"
version = "0.6.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
[[package]]
name = "tree-sitter"
version = "0.19.5"
version = "0.20.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad726ec26496bf4c083fff0f43d4eb3a2ad1bba305323af5ff91383c0b6ecac0"
checksum = "09b3b781640108d29892e8b9684642d2cda5ea05951fd58f0fea1db9edeb9b71"
dependencies = [
"cc",
"regex",

@ -19,7 +19,7 @@ include = [
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "0.19.4"
tree-sitter = "0.20"
[build-dependencies]
cc = "1.0"

@ -6,8 +6,8 @@ Haskell grammar for [tree-sitter].
# References
* [Haskell 2010 Language Report Syntax References](ref)
* [GHC Language Extensions](ext)
* [Haskell 2010 Language Report Syntax References][ref]
* [GHC Language Extensions][ext]
# Building with nvim-treesitter

@ -13,14 +13,12 @@ fn main() {
// If your language uses an external scanner written in C,
// then include this block of code:
/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
// If your language uses an external scanner written in C++,
// then include this block of code:
@ -34,7 +32,7 @@ fn main() {
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
}

@ -6,7 +6,7 @@
//! ```
//! let code = "";
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_javascript::language()).expect("Error loading haskell grammar");
//! parser.set_language(tree_sitter_haskell::language()).expect("Error loading haskell grammar");
//! let tree = parser.parse(code, None).unwrap();
//! ```
//!
@ -35,9 +35,9 @@ pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
// Uncomment these to include any queries that this grammar contains
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
#[cfg(test)]

@ -49,7 +49,7 @@ module.exports = grammar({
$.quasiquote_bar,
$.quasiquote_body,
$._strict,
$._unboxed_tuple_close,
$._unboxed_close,
'|',
'in',
/\n/,
@ -203,6 +203,16 @@ module.exports = grammar({
*/
[$._type_or_implicit, $._context_constraints],
/**
* `(# | | ...` can start both `pat` and `exp`.
*/
[$._pat_unboxed_sum, $._exp_unboxed_sum],
/**
* The nullary unboxed tuple `(# #)` is indistinguishable between exp and pat.
*/
[$.exp_unboxed_tuple, $.pat_unboxed_tuple],
[$.exp_lambda_case],
],

@ -74,6 +74,8 @@ module.exports = {
$._number,
),
_unboxed_open: _ => choice('(# ', '(#\n'),
// ------------------------------------------------------------------------
// pragma
// ------------------------------------------------------------------------

@ -24,15 +24,27 @@ module.exports = {
repeat(seq($.comma, optional($._exp)))
),
exp_sum_empty: _ => ' ',
_exp_sum: $ => sep2('|', choice($._exp, $.exp_sum_empty)),
exp_tuple: $ => parens($._exp_tuple),
exp_unboxed_tuple: $ => seq('(# ', $._exp_tuple, $._unboxed_tuple_close),
/**
* Unlike their boxed variants, unboxed tuples may be nullary and unary, making it simpler to parse them.
* The nullary tuple may even have no space between the hashes, but this format coincides with the prefix notation of
* the `##` symop. Since the latter is already parsed by other rules and is valid in the same positions, it is left out
* here.
*
* The opening lexeme, `(#`, is parsed with a hardcoded trailing space in exp, pat and type. This is a hack that works
* around some peculiarities of the interactions with some features like TH and symbolic operators that would most
* likely be significantly more complex to implement correctly. As it stands, the grammar can't parse an unboxed sum
* exp without a leading space, as in `(#| x #)`.
*/
exp_unboxed_tuple: $ => seq($._unboxed_open, sep($.comma, optional($._exp)), $._unboxed_close),
/**
* Unboxed sums must have at least one separating `|`, otherwise the expression would be a unary or nullary tuple.
*/
_exp_unboxed_sum: $ => sep2('|', optional($._exp)),
exp_unboxed_sum: $ => seq('(# ', $._exp_sum, $._unboxed_tuple_close),
exp_unboxed_sum: $ => seq($._unboxed_open, $._exp_unboxed_sum, $._unboxed_close),
exp_list: $ => brackets(sep1($.comma, $._exp)),

@ -16,7 +16,11 @@ module.exports = {
pat_tuple: $ => parens(sep2($.comma, $._nested_pat)),
pat_unboxed_tuple: $ => seq('(# ', sep1($.comma, $._nested_pat), $._unboxed_tuple_close),
pat_unboxed_tuple: $ => seq($._unboxed_open, sep($.comma, $._nested_pat), $._unboxed_close),
_pat_unboxed_sum: $ => sep2('|', optional($._nested_pat)),
pat_unboxed_sum: $ => seq($._unboxed_open, $._pat_unboxed_sum, $._unboxed_close),
pat_list: $ => brackets(sep1($.comma, $._nested_pat)),
@ -24,7 +28,7 @@ module.exports = {
pat_irrefutable: $ => seq('~', $._apat),
pat_negation: $ => seq('-', $._number),
pat_negation: $ => seq('-', $._apat),
pat_name: $ => $._var,
@ -47,6 +51,7 @@ module.exports = {
$.pat_parens,
$.pat_tuple,
$.pat_unboxed_tuple,
$.pat_unboxed_sum,
$.pat_list,
$.pat_strict,
$.pat_irrefutable,

@ -62,9 +62,12 @@ module.exports = {
type_star: _ => '*',
type_unboxed_tuple: $ => seq('(# ', $._type_tuple, $._unboxed_tuple_close),
/**
* The `(##)` format of the unary tuple is parsed as an operator, see `exp_unboxed_tuple`.
*/
type_unboxed_tuple: $ => seq($._unboxed_open, sep($.comma, $._type_or_implicit), $._unboxed_close),
type_unboxed_sum: $ => seq('(# ', $._type_sum, $._unboxed_tuple_close),
type_unboxed_sum: $ => seq($._unboxed_open, $._type_sum, $._unboxed_close),
_atype: $ => choice(
$.type_name,

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@ -1,3 +1,17 @@
;; Copyright 2022 nvim-treesitter
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
;; ----------------------------------------------------------------------------
;; Literals and comments
@ -73,10 +87,7 @@
"@"
] @operator
(qualified_module (module) @constructor)
(qualified_type (module) @namespace)
(qualified_variable (module) @namespace)
(import (module) @namespace)
(module) @namespace
[
(where)
@ -107,26 +118,37 @@
;; Functions and variables
(variable) @variable
"_" @variable.special
(pat_wildcard) @variable
(signature name: (variable) @type)
(function
name: (variable) @function
patterns: (patterns))
((signature (fun)) . (function (variable) @function))
((signature (context (fun))) . (function (variable) @function))
((signature (forall (context (fun)))) . (function (variable) @function))
(exp_infix (variable) @operator) ; consider infix functions as operators
(exp_infix (exp_name) @function (#set! "priority" 101))
(exp_apply . (exp_name (variable) @function))
("@" @namespace) ; "as" pattern operator, e.g. x@Constructor
(exp_apply . (exp_name (qualified_variable (variable) @function)))
;; ----------------------------------------------------------------------------
;; Types
(type) @type
(type_variable) @type
(constructor) @constructor
; True or False
((constructor) @_bool (#match? @_bool "(True|False)")) @boolean
;; ----------------------------------------------------------------------------
;; Quasi-quotes
(quoter) @function
; Highlighting of quasiquote_body is handled by injections.scm

@ -35,7 +35,8 @@ clone_repo GaloisInc ivory 3d00324ad1c113c7e70957ff6a6d636d271d0fc4
clone_repo polysemy-research polysemy c37d485b614e98622f5e7473a478b781a6ad5c45
clone_repo github semantic b162132339622fe1e80e243f630fe092d5c0cbe1
clone_repo haskell haskell-language-server d397ef491ef1689d43028f4d3d01a42118292235
clone_repo AndrasKovacs flatparse ddae0996d2bdd0b5b092484dbe5829b4ee2ef1f6
for name in effects postgrest ivory polysemy semantic haskell-language-server; do
for name in effects postgrest ivory polysemy semantic haskell-language-server flatparse; do
script/parse-example "$name" "$mode"
done

@ -573,6 +573,19 @@
}
]
},
"_unboxed_open": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "(# "
},
{
"type": "STRING",
"value": "(#\n"
}
]
},
"pragma": {
"type": "TOKEN",
"content": {
@ -1801,16 +1814,45 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "(# "
"type": "SYMBOL",
"name": "_unboxed_open"
},
{
"type": "SYMBOL",
"name": "_type_tuple"
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_type_or_implicit"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "comma"
},
{
"type": "SYMBOL",
"name": "_type_or_implicit"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_unboxed_tuple_close"
"name": "_unboxed_close"
}
]
},
@ -1818,8 +1860,8 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "(# "
"type": "SYMBOL",
"name": "_unboxed_open"
},
{
"type": "SYMBOL",
@ -1827,7 +1869,7 @@
},
{
"type": "SYMBOL",
"name": "_unboxed_tuple_close"
"name": "_unboxed_close"
}
]
},
@ -2906,11 +2948,86 @@
}
]
},
"exp_sum_empty": {
"type": "STRING",
"value": " "
"exp_tuple": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_exp_tuple"
},
{
"type": "STRING",
"value": ")"
}
]
},
"_exp_sum": {
"exp_unboxed_tuple": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_unboxed_open"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_exp"
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "comma"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_exp"
},
{
"type": "BLANK"
}
]
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_unboxed_close"
}
]
},
"_exp_unboxed_sum": {
"type": "SEQ",
"members": [
{
@ -2921,8 +3038,7 @@
"name": "_exp"
},
{
"type": "SYMBOL",
"name": "exp_sum_empty"
"type": "BLANK"
}
]
},
@ -2943,8 +3059,7 @@
"name": "_exp"
},
{
"type": "SYMBOL",
"name": "exp_sum_empty"
"type": "BLANK"
}
]
}
@ -2953,54 +3068,20 @@
}
]
},
"exp_tuple": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_exp_tuple"
},
{
"type": "STRING",
"value": ")"
}
]
},
"exp_unboxed_tuple": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "(# "
},
{
"type": "SYMBOL",
"name": "_exp_tuple"
},
{
"type": "SYMBOL",
"name": "_unboxed_tuple_close"
}
]
},
"exp_unboxed_sum": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "(# "
"type": "SYMBOL",
"name": "_unboxed_open"
},
{
"type": "SYMBOL",
"name": "_exp_sum"
"name": "_exp_unboxed_sum"
},
{
"type": "SYMBOL",
"name": "_unboxed_tuple_close"
"name": "_unboxed_close"
}
]
},
@ -4962,37 +5043,103 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "(# "
"type": "SYMBOL",
"name": "_unboxed_open"
},
{
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_nested_pat"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "comma"
},
{
"type": "SYMBOL",
"name": "_nested_pat"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_unboxed_close"
}
]
},
"_pat_unboxed_sum": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_nested_pat"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"type": "BLANK"
}
]
},
{
"type": "REPEAT1",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "|"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "comma"
"name": "_nested_pat"
},
{
"type": "SYMBOL",
"name": "_nested_pat"
"type": "BLANK"
}
]
}
}
]
]
}
}
]
},
"pat_unboxed_sum": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_unboxed_open"
},
{
"type": "SYMBOL",
"name": "_pat_unboxed_sum"
},
{
"type": "SYMBOL",
"name": "_unboxed_tuple_close"
"name": "_unboxed_close"
}
]
},
@ -5069,7 +5216,7 @@
},
{
"type": "SYMBOL",
"name": "_number"
"name": "_apat"
}
]
},
@ -5155,6 +5302,10 @@
"type": "SYMBOL",
"name": "pat_unboxed_tuple"
},
{
"type": "SYMBOL",
"name": "pat_unboxed_sum"
},
{
"type": "SYMBOL",
"name": "pat_list"
@ -9072,6 +9223,14 @@
"_type_or_implicit",
"_context_constraints"
],
[
"_pat_unboxed_sum",
"_exp_unboxed_sum"
],
[
"exp_unboxed_tuple",
"pat_unboxed_tuple"
],
[
"exp_lambda_case"
]
@ -9175,7 +9334,7 @@
},
{
"type": "SYMBOL",
"name": "_unboxed_tuple_close"
"name": "_unboxed_close"
},
{
"type": "STRING",

@ -378,6 +378,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -737,6 +741,10 @@
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -2204,6 +2212,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -2390,6 +2402,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -2603,6 +2619,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -4977,6 +4997,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -6602,7 +6626,7 @@
},
"children": {
"multiple": true,
"required": true,
"required": false,
"types": [
{
"type": "exp_apply",
@ -6680,10 +6704,6 @@
"type": "exp_section_right",
"named": true
},
{
"type": "exp_sum_empty",
"named": true
},
{
"type": "exp_th_quoted_name",
"named": true
@ -6796,7 +6816,7 @@
},
"children": {
"multiple": true,
"required": true,
"required": false,
"types": [
{
"type": "comma",
@ -7486,6 +7506,10 @@
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -8886,6 +8910,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -8966,6 +8994,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -9681,6 +9713,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -9744,6 +9780,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -9838,6 +9878,10 @@
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -9960,6 +10004,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -10031,6 +10079,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -10114,6 +10166,10 @@
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -10220,11 +10276,59 @@
"required": true,
"types": [
{
"type": "float",
"type": "pat_as",
"named": true
},
{
"type": "integer",
"type": "pat_irrefutable",
"named": true
},
{
"type": "pat_list",
"named": true
},
{
"type": "pat_literal",
"named": true
},
{
"type": "pat_name",
"named": true
},
{
"type": "pat_parens",
"named": true
},
{
"type": "pat_record",
"named": true
},
{
"type": "pat_strict",
"named": true
},
{
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
},
{
"type": "pat_wildcard",
"named": true
},
{
"type": "quasiquote",
"named": true
},
{
"type": "splice",
"named": true
}
]
@ -10290,6 +10394,10 @@
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -10383,6 +10491,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -10466,6 +10578,10 @@
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -10545,6 +10661,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -10639,13 +10759,100 @@
}
}
},
{
"type": "pat_unboxed_sum",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "pat_apply",
"named": true
},
{
"type": "pat_as",
"named": true
},
{
"type": "pat_infix",
"named": true
},
{
"type": "pat_irrefutable",
"named": true
},
{
"type": "pat_list",
"named": true
},
{
"type": "pat_literal",
"named": true
},
{
"type": "pat_name",
"named": true
},
{
"type": "pat_negation",
"named": true
},
{
"type": "pat_parens",
"named": true
},
{
"type": "pat_record",
"named": true
},
{
"type": "pat_strict",
"named": true
},
{
"type": "pat_tuple",
"named": true
},
{
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
},
{
"type": "pat_view",
"named": true
},
{
"type": "pat_wildcard",
"named": true
},
{
"type": "quasiquote",
"named": true
},
{
"type": "splice",
"named": true
}
]
}
},
{
"type": "pat_unboxed_tuple",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"required": false,
"types": [
{
"type": "comma",
@ -10703,6 +10910,10 @@
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -10957,6 +11168,10 @@
"type": "pat_typed",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -11237,6 +11452,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -11319,6 +11538,10 @@
"type": "pat_tuple",
"named": true
},
{
"type": "pat_unboxed_sum",
"named": true
},
{
"type": "pat_unboxed_tuple",
"named": true
@ -13822,6 +14045,10 @@
"type": "(",
"named": false
},
{
"type": "(#\n",
"named": false
},
{
"type": "(# ",
"named": false
@ -13966,10 +14193,6 @@
"type": "empty_file",
"named": true
},
{
"type": "exp_sum_empty",
"named": true
},
{
"type": "export",
"named": false

File diff suppressed because it is too large Load Diff

@ -87,7 +87,7 @@
* when the quasiquote body starts with an operator character.
* - qq_body: Prevent extras, like comments, from breaking quasiquotes
* - strict: Disambiguate strictness annotation `!` from symbolic operators
* - unboxed_tuple_close: Disambiguate the closing parens for unboxed tuples `#)` from symbolic operators
* - unboxed_close: Disambiguate the closing parens for unboxed tuples/sums `#)` from symbolic operators
* - bar: The vertical bar `|`, used for guards and list comprehension
* - in: Closes the layout of a `let` and consumes the token `in`
* - indent: Used as a dummy symbol for initialization; uses newline in the grammar to ensure the scanner is called
@ -138,7 +138,7 @@ static char *sym_names[] = {
"qq_bar",
"qq_body",
"strict",
"unboxed_tuple_close",
"unboxed_close",
"bar",
"in",
"indent",
@ -237,7 +237,7 @@ void debug_state(State *state) {
debug_valid(state->symbols);
DEBUG_PRINTF(", indents = ");
debug_indents(state->indents);
DEBUG_PRINTF("\n");
DEBUG_PRINTF(" }\n");
}
#endif
@ -365,7 +365,7 @@ static bool isws(uint32_t c) {
}
/**
* A token like a varsym can be terminated by whitespace of brackets.
* A token like a varsym can be terminated by whitespace or brackets.
*/
static bool token_end(uint32_t c) {
switch (c) {
@ -857,9 +857,9 @@ static Result cpp_workaround(State *state) {
}
/**
* If the current column i 0, a cpp directive may begin.
* If the current column is 0, a cpp directive may begin.
*/
static Result cpp_init(State *state) {
static Result cpp(State *state) {
if (column(state) == 0) {
return cpp_workaround(state);
}
@ -1008,12 +1008,12 @@ static Result splice(State *state) {
return res_cont;
}
static Result unboxed_tuple_close(State *state) {
static Result unboxed_close(State *state) {
if (state->symbols[UNBOXED_TUPLE_CLOSE]) {
if (PEEK == ')') {
S_ADVANCE;
MARK("unboxed_tuple_close", false, state);
return finish(UNBOXED_TUPLE_CLOSE, "unboxed_tuple_close");
MARK("unboxed_close", false, state);
return finish(UNBOXED_TUPLE_CLOSE, "unboxed_close");
}
}
return res_cont;
@ -1079,7 +1079,7 @@ static Result symop_marked(Symbolic type, State *state) {
return res_fail;
}
case S_UNBOXED_TUPLE_CLOSE:
return unboxed_tuple_close(state);
return unboxed_close(state);
default:
return res_cont;
}
@ -1415,7 +1415,7 @@ static Result newline(uint32_t indent, State *state) {
SHORT_SCANNER;
res = initialize(indent, state);
SHORT_SCANNER;
res = cpp_workaround(state);
res = cpp(state);
SHORT_SCANNER;
res = comment(state);
SHORT_SCANNER;
@ -1461,7 +1461,7 @@ static Result init(State *state) {
SHORT_SCANNER;
res = dot(state);
SHORT_SCANNER;
res = cpp_init(state);
res = cpp(state);
SHORT_SCANNER;
if (state->symbols[QQ_BODY]) {
return qq_body(state);
@ -1591,7 +1591,9 @@ bool tree_sitter_haskell_external_scanner_scan(void *indents_v, TSLexer *lexer,
unsigned tree_sitter_haskell_external_scanner_serialize(void *indents_v, char *buffer) {
indent_vec *indents = (indent_vec*) indents_v;
unsigned to_copy = sizeof(indents->data[0]) * indents->len;
assert(to_copy <= TREE_SITTER_SERIALIZATION_BUFFER_SIZE);
if (to_copy > TREE_SITTER_SERIALIZATION_BUFFER_SIZE) {
return 0;
}
memcpy(buffer, indents->data, to_copy);
return to_copy;
}

@ -1123,12 +1123,75 @@ a = (# a, a #)
(signature (variable) (type_unboxed_tuple (type_name (type)) (comma) (type_name (type))))
(function (variable) (exp_unboxed_tuple (exp_name (variable)) (comma) (exp_name (variable)))))
================================================================================
exp: unboxed nullary tuple
================================================================================
a = (# #)
a = (##)
---
(haskell
(function
(variable)
(exp_unboxed_tuple))
(function
(variable)
(exp_name
(operator))))
================================================================================
exp: unboxed unary tuple
================================================================================
a = (# A a + a #)
---
(haskell
(function
(variable)
(exp_unboxed_tuple
(exp_infix
(exp_apply
(exp_name (constructor))
(exp_name (variable)))
(operator)
(exp_name (variable))))))
================================================================================
exp: section of unboxed tuple
================================================================================
a = (# ,,a, #)
a = (# a,, #)
---
(haskell
(function
(variable)
(exp_unboxed_tuple
(comma)
(comma)
(exp_name (variable))
(comma)))
(function
(variable)
(exp_unboxed_tuple
(exp_name (variable))
(comma)
(comma))))
================================================================================
exp: unboxed sum
================================================================================
a :: (# A | (# A, A #) | A #)
a = (# a | | #)
a = (# | a #)
---
@ -1142,9 +1205,30 @@ a = (# a | | #)
(function
(variable)
(exp_unboxed_sum
(exp_name (variable))
(exp_sum_empty)
(exp_sum_empty))))
(exp_name (variable))))
(function
(variable)
(exp_unboxed_sum
(exp_name (variable)))))
================================================================================
exp: error: unboxed sum without space
================================================================================
a = (#| 5 #)
---
(haskell
(function
(variable)
(exp_section_right
(operator)
(exp_infix
(exp_literal (integer))
(operator)
(exp_name
(variable (MISSING _varid)))))))
================================================================================
exp: label

@ -498,7 +498,7 @@ a = b where -1 = a
(variable)
(exp_name (variable))
(where)
(decls (function (pat_negation (integer)) (exp_name (variable))))))
(decls (function (pat_negation (pat_literal (integer))) (exp_name (variable))))))
================================================================================
layout: comment in empty where on next line indented

@ -351,6 +351,21 @@ a (# a, a, a #) = a
(patterns (pat_unboxed_tuple (pat_name (variable)) (comma) (pat_name (variable)) (comma) (pat_name (variable))))
(exp_name (variable))))
================================================================================
pat: unboxed sum, nullary tuple
================================================================================
a (# (# #) | | #) = a
---
(haskell
(function
(variable)
(patterns
(pat_unboxed_sum (pat_unboxed_tuple)))
(exp_name (variable))))
================================================================================
pat: signature
================================================================================
@ -452,3 +467,19 @@ a (++) = a
---
(haskell (function (variable) (patterns (pat_name (operator))) (exp_name (variable))))
================================================================================
pat: negation with parens
================================================================================
f (-(a)) = a
---
(haskell
(function
(variable)
(patterns
(pat_parens
(pat_negation (pat_parens (pat_name (variable))))))
(exp_name (variable))))

@ -101,6 +101,20 @@ signature: parenthesized operator fun
(haskell (function (operator) (exp_name (variable))))
================================================================================
signature: operator starting with hash
================================================================================
(#!) :: a
---
(haskell
(signature
(operator)
(type_name (type_variable))))
================================================================================
signature: HKT annotation
================================================================================

@ -470,3 +470,67 @@ type A = a %m -> a
(type_name (type_variable))
(modifier (type_name (type_variable)))
(type_name (type_variable)))))
================================================================================
type decl: unboxed nullary tuple
================================================================================
type A = (# #)
type A = (##)
---
(haskell
(type_alias
(type)
(type_unboxed_tuple))
(type_alias
(type)
(type_name (type_operator))))
================================================================================
type decl: unboxed unary tuple
================================================================================
type A = (# a #)
---
(haskell
(type_alias
(type)
(type_unboxed_tuple (type_name (type_variable)))))
================================================================================
type decl: unboxed tuple with newline after opening brace
================================================================================
type A =
(#
a #)
---
(haskell
(type_alias
(type)
(type_unboxed_tuple
(type_name
(type_variable)))))
================================================================================
type decl: unboxed tuple with newline before closing brace
================================================================================
type A =
(# a
#)
---
(haskell
(type_alias
(type)
(type_unboxed_tuple
(type_name
(type_variable)))))