Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leading infix operator (infix_expression across multiple lines) #141

Open
eed3si9n opened this issue Jan 13, 2023 · 0 comments
Open

Leading infix operator (infix_expression across multiple lines) #141

eed3si9n opened this issue Jan 13, 2023 · 0 comments
Labels
area/scala3 Scala 3 syntax

Comments

@eed3si9n
Copy link
Collaborator

eed3si9n commented Jan 13, 2023

https://docs.scala-lang.org/scala3/reference/changed-features/operators.html#syntax-change

steps

def foo: Boolean =
  x
  || a.b(C)

problem

Infix doesn't seem to parse correctly when the operator is on the next line.

(compilation_unit [0, 0] - [4, 0]
  (function_definition [0, 0] - [4, 0]
    name: (identifier [0, 4] - [0, 7])
    return_type: (type_identifier [0, 9] - [0, 16])
    body: (indented_block [1, 2] - [4, 0]
      (identifier [1, 2] - [1, 3])
      (call_expression [2, 2] - [2, 11]
        function: (field_expression [2, 2] - [2, 8]
          value: (operator_identifier [2, 2] - [2, 4])
          (ERROR [2, 5] - [2, 6]
            (identifier [2, 5] - [2, 6]))
          field: (identifier [2, 7] - [2, 8]))
        arguments: (arguments [2, 8] - [2, 11]
          (identifier [2, 9] - [2, 10]))))))

expectation

It should work.

(compilation_unit [0, 0] - [2, 0]
  (function_definition [0, 0] - [2, 0]
    name: (identifier [0, 4] - [0, 7])
    return_type: (type_identifier [0, 9] - [0, 16])
    body: (indented_block [1, 2] - [2, 0]
      (infix_expression [1, 2] - [1, 13]
        left: (identifier [1, 2] - [1, 3])
        operator: (operator_identifier [1, 4] - [1, 6])
        right: (call_expression [1, 7] - [1, 13]
          function: (field_expression [1, 7] - [1, 10]
            value: (identifier [1, 7] - [1, 8])
            field: (identifier [1, 9] - [1, 10]))
          arguments: (arguments [1, 10] - [1, 13]
            (identifier [1, 11] - [1, 12])))))))

notes

scala> {
     |   val x = 1
     |     + 1
     | }
val x: Int = 2
@eed3si9n eed3si9n changed the title infix_expression across multiple lines Leading infix operator (infix_expression across multiple lines) Jan 13, 2023
@eed3si9n eed3si9n added the area/scala3 Scala 3 syntax label Jan 13, 2023
susliko added a commit to susliko/tree-sitter-scala-1 that referenced this issue May 29, 2023
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 (tree-sitter#198) and leading infix operators (tree-sitter#141)
susliko added a commit to susliko/tree-sitter-scala-1 that referenced this issue May 29, 2023
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 (tree-sitter#198) and leading infix operators (tree-sitter#141)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/scala3 Scala 3 syntax
Projects
None yet
Development

No branches or pull requests

1 participant