Commit Graph

130 Commits (d24467932b917f97a670a98f8d580453818b0b10)

Author SHA1 Message Date
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
GitHub 3f6020a1ad chore: generate and sync from cd3a29c9f7 2023-06-08 05:07:00 +07:00
Eugene Yokota 7c13fa896b Optimize complexity 2023-06-07 04:13:46 +07:00
Eugene Yokota 7ca15b8b78 Fix structural type in extends
Problem
-------
Structural type in extends clause fail to parse.

Solution
--------
This adds structural_type to the simple_type.
2023-06-07 02:48:06 +07:00
Eugene Yokota 0a8ca4c836 Apply format 2023-06-06 11:00:02 +07:00
Eugene Yokota 2d2e89f92c Repeat pattern
Problem
-------
1. Repeat pattern with `*` doesn't parse.
2. Capture pattern `@` doesn't capture wildcard.

Solution
--------
1. This implements support for `*` in pattern.
2. This also allows using `_@`.
2023-06-06 02:57:38 +07:00
susliko 5da643806c Support Scala CLI using directives
Summary
-------
Single line `$.comment` is split into a choice of `$._comment_text` and
`$.using_directive` to parse a structure of comments like
```
//> using scala 3.3.0
```
2023-05-31 23:04:52 +07:00
susliko 09b54b93f8 Document relative precedences 2023-05-31 00:53:05 +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 4b2cbc2e7c Refactor `$.compilation_unit`, optimize grammar
Summary
-------
`$.compilation_unit` is now a sequence of top-level stats separated by
`$.semicolon`

This change has two effects:
- Grammar optimization:
  - ~10% faster generation time
  - lower number of parser states ([before](https://gist.github.com/susliko/f950b997a98c54bbfd88969a949346fd), [after](https://gist.github.com/susliko/236a85dce46219c5868c494d7f5cf629))
  - parser size reduction from 43M to 36M
- It seems to me, that handling `$._automatic_semicolon` on the top level is a
  prerequisite to support top-level expressions (https://github.com/tree-sitter/tree-sitter-scala/issues/198) and leading infix operators (https://github.com/tree-sitter/tree-sitter-scala/issues/141)
2023-05-30 01:22:14 +07:00
Eugene Yokota 4801dc8a44 Refinement
Problem
-------
Compound type with refinement (structural type with a parent)
doesn't parse.

Solution
--------
This adds support for it.
It collides with context bounds `A: B: C`, so the precedence is set to
-1.
2023-05-29 00:16:55 +07:00
susliko 42bab6dc9c Self-types in braceless trait definitions
Problem
-------
Self-types are not parsed in braceless trait definitions:
```scala
trait A:
  this: B =>
````

Solution
-------
Move existing `$.self_type` rule in trait definition into indented scope.
Rebalance `$.self_type` precedence.
Without explicit precedence it looses to `$.call_expression` in
```scala
trait A {
  self: B =>
  def f = ""
}
```
With static precedence instead of dynamic it leads to errors in
definitions like:
```scala
class A
  x: Int // this should be $.ascription_expression
enum B:
  case C
```
2023-05-28 17:43:10 +07:00
Eugene Yokota ec70a4503a val defn with ids
Problem
-------
`val` definitions with multiple identifiers are not supported.

Solution
--------
This implements `identifiers`, which acts like a pattern.
2023-05-27 21:27:28 +07:00
susliko 63493b2f45 Annotations on enums
Problem
-------
Annotations on Scala 3 enums and their cases are not supported, e.g.
```scala
@A enum E:
  @A("") @B case A

```

Solution
-------
Allow annotations in enum definitions
2023-05-28 02:44:45 +07:00
eugene yokota 8ba8016ae5
Merge pull request #251 from susliko/nested-multiline-comments
Nested block comments
2023-05-27 19:29:16 +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
eugene yokota 5a6fcbdddd
Merge pull request #249 from susliko/class-lazy-params
By-name class parameters
2023-05-27 18:15:30 +07:00
susliko 2a1c3c9faf By-name class parameters
Problem
-------
By-name parameters in class definitions were not supported:
```
class A(a: => B)
```

Solution
-------
Support by-name parameters by changing the rule describing class
parameter type from `$._type` to `$._param_type`
2023-05-27 23:03:03 +07:00
susliko 4069d72047 Correct type bounds
Problem
-------
The grammar assumes upper type bound to go before lower type bound.
Although, in Scala it's the opposite:
```
TypeBounds ::= [‘>:’ Type] [‘<:’ Type]
```

Solution
-------
Swap type bounds' order in the grammar
2023-05-27 22:30:53 +07:00
eugene yokota 17a19b0f05
Merge pull request #244 from eed3si9n/wip/match_type
Match type
2023-05-27 04:12:22 +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
Eugene Yokota 41dcb78406 Remove unnecessary precedence 2023-05-26 11:09:00 +07:00
Eugene Yokota e292682508 Match type
This implements support for Scala 3 match types.
2023-05-26 10:18:32 +07:00
Eugene Yokota 6271277c8e Symbolic import
Problem
-------
symbolic import doesn't work.

Solution
--------
This switches a few things to `_identififer`
to fix the import.
2023-05-25 22:33:08 +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 c34e34e42a Intoduce `$._class_definition`
Problem
-------
Addition of optional `$.derives_clause` to the `$.class_definition` blowed its
states from ~500 to ~700 and doubled maximum memory usage during
generation. I've noticed, that the same addition of `$.derives_clause` to
the `$.object_definition` did not result in an increase of states. The
reason for this seems to be hidden in a separate rule
`$._object_definition`, that matches everything after the 'object' keyword

Solution
-------
Introduce `$._class_definition`, that matches everything after the
'class' keyword. This restrains the state machine blow when adding
support for `$.derives_clause`
2023-05-24 23:54:19 +07:00
susliko 978c64d888 Derives clause for classes and objects
Problem
-------
Derives clause is only defined for enums, but not for classes and
objects

Solution
-------
Include optional `$.derives_clause` in class and object definitions
2023-05-24 21:07:54 +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 b869fdcc35 fix: Anonymous parameters in `using` clauses
Problem
-------
`$.parameters` required each param to have a name, so `using` clauses like
`def x(using X =:= X)` failed to parse

Solution
-------
Introduce `$._using_parameters_clause`, which allows anonymous parameters
2023-05-21 23:27:17 +07:00
susliko 3a69f2c8bd fix: Anonymous alias and structural given instances 2023-05-20 00:37:04 +07:00
ghostbuster91 50e5bf3179 fix: Correctly handle _ separator in integer literals 2023-03-12 15:29:05 +07:00
Anton Sviridov cb34635bca Abstract type definitions 2023-01-28 08:50:35 +07:00
eugene yokota f7b83364c7
Fix semicolon on package (#184)
Problem
-------
Package declaration with semicolon fails to parse.

Solution
--------
This adds an optional semicolon to fix that.
2023-01-28 07:45:37 +07:00
Anton Sviridov d67e84cded
Fix `as` import renaming in Scala 3 (#175) 2023-01-24 16:01:49 +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
Chris Kipp 71b408eed0 feat: add an explicit interpolator field
_The problem_

Currently when you come across string interpolation you don't get any
special highlighting for the actual interpolator meaning:

```scala
ivy"com.lihaoyi::os-lib:0.9.0"
```

I all colored the same.

_The Solution_

The pr makes 2 changes.

- The `identifier` we use for the interpolator now becomes a field for
  no reason other than I thought it'd be nice to just give it a name
- A hightlight query that captures it and assigns it to `function.call`.
2023-01-18 08:21:39 +07:00
eugene yokota c764e31a99
Merge pull request #143 from eed3si9n/wip/annotation
Fixes annotation, sort of
2023-01-15 11:22:15 +07:00
Chris Kipp 73d5a6680c
Merge pull request #146 from eed3si9n/wip/singleton_types
Singleton type
2023-01-15 09:07:10 +07:00
Eugene Yokota 4c3cb92b4b Singleton type
Problem
-------
Currently singleton types are treated as `stable_type_identifier`.

Solution
--------
This adds `singleton_type`.
2023-01-14 15:37:55 +07:00
Eugene Yokota 8851250f35 Context function
This adds support for context function.
2023-01-14 15:04:25 +07:00
Eugene Yokota 0b7fd00750 Fixes annotation, sort of
Problem
-------
1. class constructor should accept annotation, but it doesn't.
2. Apparently Scala 3 does allow zero, one, or multiple parameter list
   to an annotation, and differentiated between the class parameter by
   its lack of type ascription.

Solution
--------
1. Add optional annotation for constructor. At this point, we can at
   least parse the code with annotation on the ctor.
2. Unfortunatley, however, tree-sitter doesn't make enough lookahead to
   distinguish postfix expr or ascription expression `(x: Int)`,
   for now the class parameters will end up being parsed as arguments to
   the annotation.
2023-01-14 00:29:24 +07:00
Eugene Yokota b5fd12eaab Fixes extends clause
Problem
-------
1. In Scala 3, extends clause can be comma separated.
2. In Scala 2 or 3 extends clause can ctor with parameters:
   `class D with E(x) with F(y)`.

Solution
--------
`extends` is now followed by *constructor applications* separated by
either `with` or `,` as opposed to treating them as a compound type.
2023-01-13 14:40:20 +07:00
Eugene Yokota fe6ff49ee8 Fix operator_identifier
Problem
-------
1. Currently `//` ends up matching `operator_identier`
2. There's also a bug in regex.

Solution
--------
1. Implement a workaround to avoid `//`.
2. Escape `-`, copying from the identifier regex.
2023-01-13 04:04:58 +07:00
eugene yokota c110fbaece
Merge pull request #128 from eed3si9n/wip/fewer_braces
SIP-44 Fewer braces support
2023-01-12 14:36:28 +07:00
eugene yokota 5991810787
Merge pull request #130 from ghostbuster91/structural-types-2
Add support for structural types
2023-01-12 13:54:45 +07:00
Eugene Yokota a7e9394935 Add support for indented_cases in colon_argument 2023-01-12 12:58:53 +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