Skip to content

Commit

Permalink
feat: closes GH-50 - @rewrite blocks (#106)
Browse files Browse the repository at this point in the history
* feat: GH-50 @rewrite blocks
* remove failing test and put in GH ticket
  • Loading branch information
kylegoetz authored Nov 7, 2024
1 parent e18194c commit 920c8e1
Show file tree
Hide file tree
Showing 15 changed files with 210,171 additions and 156,619 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
!*/
node_modules
.jj
*.log
log
log.html
.unisonHistory
.gitattributes

# OS-specific
.DS_Store

# IDE-specific
.vscode
.editorconfig

# app specific
Makefile
*.swift
pyproject.toml
src/*
!src/tree_sitter
!src/tree_sitter/parser.h
scratch.u
*.wasm
*.py
bindings/c
bindings/go
bindings/python
bindings/swift
target/
build/
Cargo.lock
setup.py
test.html

!grammar.json
!parser.c
Expand Down
22 changes: 16 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,29 @@

All notable changes to this project will be documented in this file.

## [2.0.0] - 2024-10-29
## [2.0.0] - 2024-11-06

### New

- #86 - add `force`, in which `x()` is parsed as `(force (regular_identifier) (unit))`
- GH-50 - term rewrite blocks
- GH-85 - a built-in hash is a single unit, no longer `*PATH_SEGMENT . REGULAR_ID`
- GH-86 - add `force`, in which `x()` is parsed as `(force (regular_identifier) (unit))`
- GH-90 - liberal recognition of `_layout_semicolon` at ends of lines with equal indentation levels, which helps with parsing in many places
- GH-91 - infix symops can have namespace/path prefix

### Fixed

- #82 - allow doc block wherever
- #84 - Symbols in paths now work
- #85 - built-ins are now just `built_in_hash` without any child nodes
- GH-80 - parsing folds of more than three hyphens
- GH-84 - Symbols in paths now work
- GH-85 - built-ins are now just `built_in_hash` without any child nodes
- GH-92 - test watch expressions can only have `test` and `test.io` as prefix for `>`
- GH-95 - doc blocks can only appear two ways (syntax sugar before a top-level `binding` and in similar places as a `literal`)
- GH-96 - enable built-in hashes
- GH-97 - separate a term `binding` from a top-level `binding` (latter has the doc block syntax sugar)
- GH-98 - +4 is correctly tokenized as `int` rather than `symboly_id . nat`
- #?? - pattern matching guards now are part of a layouted block

- GH-103 - `match` scrutinee now correctly categorized as `_term` rather than `_expression`
- GH-105 - two-char symbols ending in `&` or `|` now parse as two-char symbols

### Changed

Expand Down
32 changes: 32 additions & 0 deletions grammar/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,36 @@ module.exports = {

// handle [block] with [block]
handler: ($) => seq($.handle, $._block, $.with, $._block),

rewrite_block: $ => seq(
$.rewrite,
$._layout_start,
seq($._rewrite_type, repeat(seq($._layout_semicolon, $._rewrite_type))),
$._layout_end),

_rewrite_type: $ => choice(
$.rewrite_term,
$.rewrite_case,
$.rewrite_type,
),
_rewrite_term_like: $ => seq(
$._term,
$.rewrite_arrow,
$._layout_start,
$.__layout_block
),

rewrite_term: $ => seq($.term, $._rewrite_term_like),
rewrite_case: $ => seq($.case, $._rewrite_term_like),
rewrite_type: $ => seq(
$.signature,
optional(seq(
repeat1($._prefix_definition_name),
alias('.', $.dot))),
$._computation_type,
$.rewrite_arrow,
$._layout_start,
$._computation_type,
$._layout_end,
),
};
1 change: 1 addition & 0 deletions grammar/conflicts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ module.exports = ($) => [
[$._literal, $._link],
[$._infix_app_or_boolean_op],
[$._pattern_constructor, $.effect_bind],
[$._identifier, $._wordy_definition_name],
];
1 change: 1 addition & 0 deletions grammar/delayed-computation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
choice(
$.exp_let,
$.handler,
$.rewrite_block,
$.exp_if,
$._pattern_matching, // this is match and lam case
),
Expand Down
5 changes: 5 additions & 0 deletions grammar/reserved.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ module.exports = {
with: ($) => "with",
open_parens: $ => prec.right('('),
close_parens: $ => ')',
rewrite: $ => '@rewrite',
term: $ => 'term',
case: $ => 'case',
signature: $ => 'signature',
rewrite_arrow: $ => '==>',
};
193 changes: 192 additions & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
"name": "unison",
"rules": {
"unison": {
Expand Down Expand Up @@ -2240,6 +2239,10 @@
"type": "SYMBOL",
"name": "handler"
},
{
"type": "SYMBOL",
"name": "rewrite_block"
},
{
"type": "SYMBOL",
"name": "exp_if"
Expand Down Expand Up @@ -2686,6 +2689,170 @@
}
]
},
"rewrite_block": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "rewrite"
},
{
"type": "SYMBOL",
"name": "_layout_start"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_rewrite_type"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_layout_semicolon"
},
{
"type": "SYMBOL",
"name": "_rewrite_type"
}
]
}
}
]
},
{
"type": "SYMBOL",
"name": "_layout_end"
}
]
},
"_rewrite_type": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "rewrite_term"
},
{
"type": "SYMBOL",
"name": "rewrite_case"
},
{
"type": "SYMBOL",
"name": "rewrite_type"
}
]
},
"_rewrite_term_like": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_term"
},
{
"type": "SYMBOL",
"name": "rewrite_arrow"
},
{
"type": "SYMBOL",
"name": "_layout_start"
},
{
"type": "SYMBOL",
"name": "__layout_block"
}
]
},
"rewrite_term": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "term"
},
{
"type": "SYMBOL",
"name": "_rewrite_term_like"
}
]
},
"rewrite_case": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "case"
},
{
"type": "SYMBOL",
"name": "_rewrite_term_like"
}
]
},
"rewrite_type": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "signature"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_prefix_definition_name"
}
},
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "."
},
"named": true,
"value": "dot"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_computation_type"
},
{
"type": "SYMBOL",
"name": "rewrite_arrow"
},
{
"type": "SYMBOL",
"name": "_layout_start"
},
{
"type": "SYMBOL",
"name": "_computation_type"
},
{
"type": "SYMBOL",
"name": "_layout_end"
}
]
},
"type_signature": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -3882,6 +4049,26 @@
"type": "STRING",
"value": ")"
},
"rewrite": {
"type": "STRING",
"value": "@rewrite"
},
"term": {
"type": "STRING",
"value": "term"
},
"case": {
"type": "STRING",
"value": "case"
},
"signature": {
"type": "STRING",
"value": "signature"
},
"rewrite_arrow": {
"type": "STRING",
"value": "==>"
},
"wordy_id": {
"type": "PREC_RIGHT",
"value": 0,
Expand Down Expand Up @@ -4491,6 +4678,10 @@
[
"_pattern_constructor",
"effect_bind"
],
[
"_identifier",
"_wordy_definition_name"
]
],
"precedences": [
Expand Down
Loading

0 comments on commit 920c8e1

Please sign in to comment.