From 4c9da29cbdc100c6a48b18975c015e54e620c298 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sun, 15 Oct 2023 14:43:34 -0400 Subject: [PATCH] fix(scala): add `for_expression` locals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change does two main things: 1. Indicate that `(for_expression)`'s introduce a `@scope` (this is the scope for the enumerators to be used within the loop). 2. Indicate that the `(identifiers)` within the `(enumerators)` are `@definition.var`s. --- For the following example snippet: ```scala val fruits = List("apple", "banana", "avocado", "papaya") val countsToFruits = fruits.groupBy(fruit => fruit.count(_ == 'a')) for ((count, fruits) <- countsToFruits) { println(s"with (fruits) 'a' × $count = $fruits") } ``` The `count` and `fruits` identifiers are new definitions introduced by the `for` expressions scope. --- queries/scala/locals.scm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/queries/scala/locals.scm b/queries/scala/locals.scm index d006556ab..9f81e2859 100644 --- a/queries/scala/locals.scm +++ b/queries/scala/locals.scm @@ -5,6 +5,7 @@ (lambda_expression) (function_definition) (block) + (for_expression) ] @scope ; References @@ -44,3 +45,8 @@ (var_declaration name: (identifier) @definition.var) +(for_expression + enumerators: (enumerators + (enumerator + (tuple_pattern + (identifier) @definition.var))))