Skip to content

Commit

Permalink
fixes #37, doc blocks are now a type of expression + anonymous doc bl…
Browse files Browse the repository at this point in the history
…ocks preceding term declarations
  • Loading branch information
kylegoetz committed Jul 26, 2023
1 parent cb28edd commit 1de4fc8
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Every feature of the Unison language is implemented here.

If you have recommendations for improvements, create an issue, please. Thank you!

* [2023-07-26] v1.0.1 released. No idea why previous package version got screwed up and labeled as 0.9.x. Previous version allowed documentation blocks anywhere. They are only supposed to be allowed right before term definitions (as "anonymous documentation blocks") or as a type of expression.
* [2023-06-28] v1 released. All Unison entities parsed, but doc blocks are only parsed as a doc block without breaking them down further into sections, etc.
1 change: 0 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ module.exports = grammar({
extras: $ => [
/\\?\s/,
$.comment,
$.doc_block,
],
rules: {
unison: $ => repeat(
Expand Down
1 change: 1 addition & 0 deletions grammar/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
$._boolean_exp,
$.delay_block,
$.bang,
$.doc_block,
)),

operator_as_parameter: $ => seq('(',$.operator, ')'),
Expand Down
1 change: 1 addition & 0 deletions grammar/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
* x = 5 <-- term definition
*/
term_declaration: $ => prec(20, seq(
optional($.doc_block),
optional($.type_signature),
$.term_definition
)),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tree-sitter-unison",
"license": "MIT",
"author": "Kyle Goetz <[email protected]>",
"version": "0.9.2",
"version": "1.0.1",
"description": "Unison grammar for tree-sitter",
"repository": "github:kylegoetz/tree-sitter-unison",
"main": "bindings/node",
Expand Down
8 changes: 1 addition & 7 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,7 @@ static Result layout_start(uint32_t column, State *state) {
if (PEEK == '-') {
return multiline_comment(state);
}
goto foo;
}
SYMBOLIC_CASES: { // Cannot start a layout with a -/+ unless it's part of '->' or -+INT/FLOAT
if (PEEK == '+') {
Expand All @@ -1642,17 +1643,10 @@ static Result layout_start(uint32_t column, State *state) {
}
} else if(isdigit(PEEK)) {
goto foo;
// Result res = numeric(state);
// if (res.sym == NAT) { // Really it's an INT since we consumed `-` already
// res = finish_if_valid(INT, "int", state);
// }
// SHORT_SCANNER;
}
}
return res_cont;
}
// TODO add stuff in here for comments, which can appear anywhere
// and need to be handled
}
foo:
push(column, state);
Expand Down
6 changes: 3 additions & 3 deletions test/corpus/documentation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
poet = "Maya Angelou"
---
(unison
(doc_block)
(term_declaration
(doc_block)
(term_definition
(wordy_id)
(kw_equals)
Expand All @@ -16,7 +16,7 @@ poet = "Maya Angelou"
===
[Docs] complex
===
{{
> {{
`repeat` is a function which will repeat the provided text a specified number of times.

Source:
Expand All @@ -30,4 +30,4 @@ poet = "Maya Angelou"
```
}}
---
(unison (doc_block))
(unison (watch_expression (doc_block)))
20 changes: 18 additions & 2 deletions test/corpus/regression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ x = ##Foo
===
> 1 Nat.+ 2
---
(unison (watch_expression (function_application (nat) (path) (operator) (nat))))===
(unison (watch_expression (function_application (nat) (path) (operator) (nat))))
===
[Regression] #34 - watch expressions can be binds (term definitions, but types are not allowed as per TermParser.hs, so not term declarations)
They cannot be destructuring binds, which cannot happen at the top level. Verified via Unison LSP.
===
Expand All @@ -38,4 +39,19 @@ They cannot be destructuring binds, which cannot happen at the top level. Verifi
(unison
(watch_expression
(term_definition
(wordy_id) (kw_equals) (nat))))
(wordy_id) (kw_equals) (nat))))
===
[Regression] Issue 37, docblock can be anywhere an expression is
===
z = {{ test }}
---
(unison (term_declaration (term_definition (wordy_id) (kw_equals) (doc_block))))
===
[Regression] Issue 37, anonymous docblock immediately precedes term declaration
===
{{ howdy }}
x = 5
---
(unison (term_declaration
(doc_block)
(term_definition (wordy_id) (kw_equals) (nat))))

0 comments on commit 1de4fc8

Please sign in to comment.