Merge branch 'master' into next-line-derives

pull/659/head
eugene yokota 2023-09-18 23:14:57 +07:00 committed by GitHub
commit ee2e9ab164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 27 deletions

@ -404,6 +404,11 @@ class C:
else
()
if (a) || b(c) then return true
if (a) && b.c then
()
--------------------------------------------------------------------------------
(compilation_unit
@ -445,6 +450,27 @@ class C:
(indented_block
(unit)
(comment))
(indented_block
(unit)))
(if_expression
(infix_expression
(parenthesized_expression
(identifier))
(operator_identifier)
(call_expression
(identifier)
(arguments
(identifier))))
(return_expression
(boolean_literal)))
(if_expression
(infix_expression
(parenthesized_expression
(identifier))
(operator_identifier)
(field_expression
(identifier)
(identifier)))
(indented_block
(unit))))))))
@ -1067,6 +1093,7 @@ object O {
if (c) d.e }
{ a => implicit b => b }
{ (a: Int) ?=> (b: Int) => b }
{ (_, a) => a }
}
--------------------------------------------------------------------------------
@ -1157,7 +1184,15 @@ object O {
(binding
(identifier)
(type_identifier)))
(identifier)))))))
(identifier))))
(block
(lambda_expression
(bindings
(binding
(wildcard))
(binding
(identifier)))
(identifier))))))
================================================================================
Unit expressions

@ -93,6 +93,10 @@ module.exports = grammar({
// 'for' operator_identifier ':' _annotated_type • ':' …
[$._type, $.compound_type],
[$.lambda_expression, $.modifiers],
// 'if' parenthesized_expression • '{' …
[$._if_condition, $._simple_expression],
// _postfix_expression_choice ':' '(' wildcard • ':' …
[$.binding, $._simple_type],
],
word: $ => $._alpha_identifier,
@ -1105,22 +1109,25 @@ module.exports = grammar({
),
if_expression: $ =>
prec.right(
PREC.control,
seq(
optional($.inline_modifier),
"if",
field(
"condition",
choice(
$.parenthesized_expression,
seq($._indentable_expression, "then"),
),
),
field("consequence", $._indentable_expression),
optional(seq("else", field("alternative", $._indentable_expression))),
),
),
prec.right(PREC.control, seq(
optional($.inline_modifier),
"if",
field(
"condition",
$._if_condition,
),
field("consequence", $._indentable_expression),
optional(seq("else", field("alternative", $._indentable_expression))),
)),
// NOTE(susliko): _if_condition and its magic dynamic precedence were introduced as a fix to
// https://github.com/tree-sitter/tree-sitter-scala/issues/263 and
// https://github.com/tree-sitter/tree-sitter-scala/issues/342
// Neither do I understand why this works, nor have I found a better solution
_if_condition: $ => prec.dynamic(4, choice(
$.parenthesized_expression,
seq($._indentable_expression, "then"),
)),
/*
* MatchClause ::= 'match' <<< CaseClauses >>>
@ -1160,11 +1167,14 @@ module.exports = grammar({
finally_clause: $ => prec.right(seq("finally", $._indentable_expression)),
/*
* Binding ::= (id | _) [: Type]
*/
binding: $ =>
prec.dynamic(
PREC.binding,
seq(
field("name", $._identifier),
choice(field("name", $._identifier), $.wildcard),
optional(seq(":", field("type", $._param_type))),
),
),

@ -4,7 +4,7 @@
SCALA_SCALA_LIBRARY_EXPECTED=100
SCALA_SCALA_COMPILER_EXPECTED=96
DOTTY_COMPILER_EXPECTED=83
DOTTY_COMPILER_EXPECTED=84
SYNTAX_COMPLEXITY_CEILING=1400
if [ ! -d "$SCALA_SCALA_DIR" ]; then

@ -26,19 +26,19 @@ object Hello {
trait Test {
// ^ keyword
// ^ type
def meth(i: Int)(implicit x: Boolean) = ???
def meth(i: Int)(implicit x: Boolean) = ???
// ^keyword.function
// ^keyword
// ^type
// ^method
// ^parameter
// ^parameter
val anonFun: Int => Int = (a: Int) => a
// ^variable
// ^type
// ^operator
// ^type
// ^parameter
val anonFun: Int => Int = (a: Int) => a
// ^variable
// ^type
// ^operator
// ^type
// ^parameter
}
protected abstract class Bla(test: String)