Commit Graph

48 Commits (dda875eae9fb5137dc8d58432896a69d4289f4ea)

Author SHA1 Message Date
Johannes Coetzee dda875eae9 Rename interpolation_identifier 2023-07-20 14:42:40 +07:00
Johannes Coetzee aa5907747b Fix interpolated string identifiers 2023-07-19 23:40:59 +07:00
s.bazarsadaev 662a3e9957 Closes #260 2023-06-14 19:34:29 +07:00
susliko 16974b4535 Issue OUTDENT with extra spaces before brackets
Problem
-------
```scala
{ x =>
  if (a) b.c }
```
is not parsed because OUTDENT token is not emitted in a presense of
space characters before the closing bracket

Solution
-------
Reorder space-handling and outdent-ing logic in external scanner
2023-06-11 00:00:13 +07:00
susliko a889c3c749 Rework lambda expressions
Summary
-------
`$.lambda_expression` body was changed from `$._block` to
`$._indentable_expression`. This had the following effects:
* x10 faster parser generation
* parser size reduced from 41M to 24M
* conflict with `$.self_type`, which was resolved by matching
  indent-tokens in `$.template_body`. This change, in its turn required
  scanner.c to stop emitting INDENT and OUTDENT tokens when encountering
  comments
2023-06-08 17:20:52 +07:00
Eugene Yokota 38137ff97f Allow closing paren/bracket to outdent
Problem
-------
Braceless syntax can terminate with closing paren or bracket
of the outer context, but we don't support that.

Solution
--------
This changes the scanner so when an outdent is expected,
closing paren or bracket can inject an outdent.
2023-06-06 00:57:55 +07:00
susliko 4da42f4e71 Allow soft keywords as identifiers
Problem
-------
Soft keywords ('open', 'end', 'infix', etc.) are not allowed to be used
as identifiers, e.g. in
```
open()
```
Solution
-------
Introduce `$._soft_identifier` with a lower precedence than modifiers
2023-05-30 23:25:52 +07:00
susliko 03d1848437 Top-level expressions
Problem
-------
Top-level expressions are not supported. However, it's a valid case for
Scala scripts or sbt configurations

Solution
-------
Now that AUTOMATIC_SEMICOLON tokens are handled at the top-level
enabling top-level expressions is done by including `$.expression` into
`$._top_level_definition`
2023-05-30 12:29:35 +07:00
susliko 8f1f347918 Add test case for `**` operator identifier 2023-05-28 01:33:46 +07:00
susliko 693c651b50 Nested block comments
Problem
-------
Nested block comments are not parsed, e.g.
```
/* /* */ */
```

Solution
-------
Leave $.comment for single-line comments.
Introduce $.block_comment for block-comments.
Make $.block_comment out of several tokens to be able to detect nested
block comments
2023-05-28 01:16:58 +07:00
susliko bac013bec8 Better catch clause
Problem
-------
Catch-clause is not parsed when case is on the same line as 'catch':
```
try a catch b: C => d
```

Solution
-------
Intoduce `$._expr_case_clause` alternative to the catch-clause
2023-05-26 23:37:52 +07:00
susliko 8cb5a00a1d Using clause in $.arguments
Problem
-------
Scala 3 introduced using clauses to function call expressions:
```scala
f(using A)
```
The grammar did not allow that

Solution
-------
Add `choice` between regular and using-clause argument lists in
`$.arguments`
2023-05-25 18:34:21 +07:00
susliko 4dadee71d5 fix: case clauses with guards
Problem
-------
Guards in case clauses are thought to be lambda expressions sometimes,
e.g. in
```scala
{case a if b => c}
```
This happens, because `$.lambda_expression` has a higher parsing
precedence than `$._simple_expression`

Solution
-------
Avoid using numeric parsing precedence for `$.lambda_expression`.
Resolve specific conflicts instead
2023-05-24 19:01:40 +07:00
susliko 60243c07a3 fix: Handle newlines and comments in the middle of expressions
Problem:
-------
Code like
```scala
if true ()

else ()
```
or
```scala
a
 .b
 // comment
 .c
```
is not parsed correctly, for extra `$._automated_semicolon` tokens,
which are produced after newlines

Solution:
-------
Tweak `scanner.c` to stop producing AUTOMATED_SEMICOLON tokens when
encountering comments, else/catch clauses, etc.
2023-05-24 01:32:33 +07:00
susliko 293aaec2ee refactor: format corpus/expressions.txt with `tree-sitter test -u` 2023-05-23 01:39:46 +07:00
Anton Sviridov b74eb241df String interpolation case pattern 2023-01-22 16:13:24 +07:00
Eugene Yokota dc3f68fe8b Fixes pattern match with guard
Problem
-------
Currently pattern match with guard doesn't parse.

Solution
--------
This implements it by creating an intermediate node called `_case_pattern` with right associativity.
2023-01-20 11:20:49 +07:00
Eugene Yokota 944196126a Trailing commas
Problem
-------
Trailing commas are not supported.

Solution
--------
This adds support for that.
2023-01-19 01:39:30 +07:00
Eugene Yokota a7e9394935 Add support for indented_cases in colon_argument 2023-01-12 12:58:53 +07:00
Eugene Yokota 710e5cccc5 Add the val y = x: Int example 2023-01-12 10:45:32 +07:00
Eugene Yokota ffcbfc90a9 SIP-44 Fewer braces support
Fixes https://github.com/tree-sitter/tree-sitter-scala/issues/127

Problem
-------
Currently our grammar does not support the fewer braces syntax,
which basically lets us pass the last argument as a block after `:`.

Solution
--------
This implements fewer braces support for call_expression,
infix_expression, with and without the lambda start.
2023-01-12 10:45:32 +07:00
Eugene Yokota 14a22e7baa Add more test for instance_expression 2023-01-12 02:09:01 +07:00
Eugene Yokota 77ea27edbe Fixes instance_expression
Problem
-------
Current grammar accepts expression immeidately after `new`,
which is not correct, and doesn't work for Scala 3 syntax.

Solution
--------
This fixes it by actually using `$.template_body`.
It does create a tricky conflict between `new A: <block>`
construct and `new A: <type>`.
To deal with that, we are using `prec.dynamic`.
2023-01-11 19:15:42 +07:00
Eugene Yokota 996b7849eb Fixes for expression
Fixes https://github.com/tree-sitter/tree-sitter-scala/issues/123

Problem
-------
Guard `if something` isn't supported in the for expression.

Solution
--------
This implements it.
2023-01-10 05:18:28 +07:00
Eugene Yokota bf4102c863 Include operator-like identifier as simple expression
Problem
-------
Currently operator-like identifiers are not part of the simple
expression, so you can't call `::(123)`.

Solution
--------
This includes `$.operator_identifier` into `_simple_expression`,
and further improves the expression hierarchy.

Note that this removes test on double-prefix-expression.
It's not allowed in Scala spec to have double-prefix.
2023-01-09 18:54:50 +07:00
Anton Sviridov 80cb5ed88f Inline def, if, given, match 2023-01-09 22:48:08 +07:00
Eugene Yokota ce34cd5343 Scala 3 macros
Fixes https://github.com/tree-sitter/tree-sitter-scala/issues/109

This implements support for Scala 3 macros.
2023-01-09 02:08:40 +07:00
Eugene Yokota efa49c8c73 Improve expression hierarchy
Problem
-------
Currently we use `$.expression` everywhere even though it often
requires much narrower set of expressions.

Solution
--------
Now that we've gained some memory budget, this adds
`_simple_expression`, mirroring the EBNF, and adjusts
`infix_expression` etc to use narrower choice of expression tokens.
With this change, the smoke test for Scala 2 library jumps to 95%.
2023-01-08 23:24:35 +07:00
Eugene Yokota 8c358ddf37 Scala 3 for expression 2022-12-20 11:38:51 +07:00
Eugene Yokota f440283f4f Scala 3 while expression 2022-12-20 11:38:51 +07:00
Eugene Yokota 5d129d3bd9 Scala 3 match expression 2022-12-20 11:38:51 +07:00
Eugene Yokota debb382b38 Scala 3 try-catch support 2022-12-20 11:38:51 +07:00
Eugene Yokota fa8d64b77e Optional braces, part 2
Problem
-------
Currently Scala 3 optional braces syntax does not work.
Specifically, in this PR I want to address decls/defns not
properly grouped under the right owner in part 1.

Solution
--------
1. This brings in indent/outdent impl by keynmol
2. Introduce `_indentable_expression`.
   This allows us to limit where indent/outdent shows up without
   confusing tree-sitter too much. To start, val/def/var defn
   and if-expressions are given indentable expression.
2022-12-17 21:10:45 +07:00
Stuart Mashaal 6a10d3f8ef fix corpus/expressions.txt formatting 2022-05-22 18:47:43 +07:00
Stuart Mashaal 542a1e8e78 lambda_expression can have _block as body 2022-05-22 18:29:49 +07:00
Stevan Milic 98f703493d
Add lambda expression (#34)
Fix call expression to allow block as arguments (#21)

Update for comprehension to handle patterns

Fix for comprehension to detect assignment as an enumerator

Add access modifiers

Update trait, object and class parameter to support modifiers

Update scanner to support `with` on a new line

Update function definition/declaration to support operator naming

Update field expression to support operators as methods

Co-authored-by: Stevan Milic <stevan.milic@tradecore.com>
2021-10-07 09:03:08 +07:00
Stevan Milic 449b6baa6b
Add recognition of multi-line field expression (#23) (#32) 2021-08-31 13:42:29 +07:00
Stevan Milic e79f8cd2d0
Update expression rule (#33)
* add postfix expression

* add ascription expression
2021-08-31 13:41:54 +07:00
Stuart Mashaal ec38674996
add while/do loops and for-comprehension (#30) 2021-08-08 14:43:30 +07:00
Denis Pyshev f80daaa212
Miscallleneous stuff (#27)
* Null literal

* Unit expression, required for `for {...} ()` case

* Add `return` expression

* Add `throw` expression

* Apply changes per review

Remove redundant token fun call.
2021-07-19 13:26:02 +07:00
Denis Pyshev bfa2a81388
Feature/literals (#25)
* Fix typo

* Rework literals part of grammar

Introduce hierarchy of literals as it is done in Scala language grammar.
Move existing literal types into hierarcy under `literal` parent.
Add and extend literals for integer and floating point numbers.
Add test cases for integer and floating point numbers in corpus.
Adjust existing test cases to changes.

Also fixes #24

* Apply review comments

Hide `literal` node from appearing in s-expressions and increasing
amount of states.
Update test cases according to grammar change.

* Add automatic changes

Add tree-sitter dependency update by npm.
Add atomatic changes in parser and grammar from building the parser.
2021-06-23 15:37:27 +07:00
Chris Kipp 63f103cc87
Allow for catch and finally in try expression to be on a new line (#16)
* Allow for catch and finally in try expression to be on a new line

* Fix actions to run on all pull requests
2021-03-12 09:41:49 +07:00
Tuấn-Anh Nguyễn 211bb726bb
Various improvements (#13)
* Add supertypes

* Support multi-line case clauses

* Allow definitions in case clauses, expressions in class/object bodies

* Add annotations, infix patterns, implicit parameters

* Add tree-sitter CLI declaration to package.json

* Add annotations on type parameters

* Add type annotations, type projections; fix compound types

* Fix operator_identifier regexp

* Add tuple types and repeated parameter types

* Give infix_pattern higher precedence than capture_pattern

* Make infix_type nestable

* Allow body-less trait_definition

* Allow omitting parens when function_type's input is a single type

* Put all alternatives function_type's parameters under parameter_types

* Give alternative_pattern lower precedence than typed_pattern

* Remove parenthesized_pattern

* Allow empty body in case_clause

* Regenerate parser
2020-07-13 13:31:00 +07:00
Max Brunsfeld 5a17adfe39 Add try expressions 2018-02-22 17:06:29 +07:00
Max Brunsfeld a8b0acb96c Refine semicolon insertion, add arguments in extends clause 2018-02-22 17:00:13 +07:00
Max Brunsfeld 37269678d3 Add capture patterns, multiple expressions in case clauses 2018-02-22 16:40:33 +07:00
Max Brunsfeld cfdfe47282 Don't allow square brackets in operator names 2018-02-22 16:05:45 +07:00
Max Brunsfeld dc4c0d4963 Initial commit 2018-02-22 10:58:11 +07:00