From 1de4fc8a32f6946e2c4c94962e77de9a36f4539d Mon Sep 17 00:00:00 2001 From: Kyle Goetz Date: Wed, 26 Jul 2023 10:54:02 -0500 Subject: [PATCH] fixes #37, doc blocks are now a type of expression + anonymous doc blocks preceding term declarations --- README.md | 1 + grammar.js | 1 - grammar/expression.js | 1 + grammar/term.js | 1 + package.json | 2 +- src/scanner.c | 8 +------- test/corpus/documentation.txt | 6 +++--- test/corpus/regression.txt | 20 ++++++++++++++++++-- 8 files changed, 26 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 28578b5..2b62735 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/grammar.js b/grammar.js index 831d0e1..3237cda 100644 --- a/grammar.js +++ b/grammar.js @@ -111,7 +111,6 @@ module.exports = grammar({ extras: $ => [ /\\?\s/, $.comment, - $.doc_block, ], rules: { unison: $ => repeat( diff --git a/grammar/expression.js b/grammar/expression.js index f24d984..8e5b884 100644 --- a/grammar/expression.js +++ b/grammar/expression.js @@ -16,6 +16,7 @@ module.exports = { $._boolean_exp, $.delay_block, $.bang, + $.doc_block, )), operator_as_parameter: $ => seq('(',$.operator, ')'), diff --git a/grammar/term.js b/grammar/term.js index f3718db..b3d5997 100644 --- a/grammar/term.js +++ b/grammar/term.js @@ -7,6 +7,7 @@ module.exports = { * x = 5 <-- term definition */ term_declaration: $ => prec(20, seq( + optional($.doc_block), optional($.type_signature), $.term_definition )), diff --git a/package.json b/package.json index a94c76d..d59cd2a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "tree-sitter-unison", "license": "MIT", "author": "Kyle Goetz ", - "version": "0.9.2", + "version": "1.0.1", "description": "Unison grammar for tree-sitter", "repository": "github:kylegoetz/tree-sitter-unison", "main": "bindings/node", diff --git a/src/scanner.c b/src/scanner.c index ca9739b..6355e84 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -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 == '+') { @@ -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); diff --git a/test/corpus/documentation.txt b/test/corpus/documentation.txt index 57a3e58..c7a6953 100644 --- a/test/corpus/documentation.txt +++ b/test/corpus/documentation.txt @@ -5,8 +5,8 @@ poet = "Maya Angelou" --- (unison - (doc_block) (term_declaration + (doc_block) (term_definition (wordy_id) (kw_equals) @@ -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: @@ -30,4 +30,4 @@ poet = "Maya Angelou" ``` }} --- -(unison (doc_block)) \ No newline at end of file +(unison (watch_expression (doc_block))) \ No newline at end of file diff --git a/test/corpus/regression.txt b/test/corpus/regression.txt index 025635d..db9ed72 100644 --- a/test/corpus/regression.txt +++ b/test/corpus/regression.txt @@ -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. === @@ -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)))) \ No newline at end of file + (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)))) \ No newline at end of file