Skip to content

Commit 98b55e9

Browse files
committed
Export clauses
1 parent cbf8207 commit 98b55e9

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

corpus/definitions.txt

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ import reflect.io.{Directory, File, Path}
185185
(identifier) (identifier))
186186
(import_declaration
187187
(identifier) (identifier)
188-
(import_selectors (identifier) (identifier) (identifier))))
188+
(namespace_selectors (identifier) (identifier) (identifier))))
189189

190190
================================
191191
Imports: Wildcard
@@ -198,7 +198,7 @@ import tools.nsc.classpath._
198198
(compilation_unit
199199
(import_declaration
200200
(identifier) (identifier) (identifier)
201-
(import_wildcard)))
201+
(namespace_wildcard)))
202202

203203
================================
204204
Imports: Wildcard (Scala 3 syntax)
@@ -211,12 +211,12 @@ import a.b.*, b.c, c.*
211211

212212
(compilation_unit
213213
(import_declaration
214-
(identifier) (identifier) (identifier) (import_wildcard))
214+
(identifier) (identifier) (identifier) (namespace_wildcard))
215215

216216
(import_declaration
217-
(identifier) (identifier) (import_wildcard)
217+
(identifier) (identifier) (namespace_wildcard)
218218
(identifier) (identifier)
219-
(identifier) (import_wildcard)))
219+
(identifier) (namespace_wildcard)))
220220

221221
================================
222222
Imports: Wildcard and wildcard givens (Scala 3 syntax)
@@ -230,12 +230,12 @@ import tools.given
230230
(compilation_unit
231231
(import_declaration
232232
(identifier) (identifier) (identifier)
233-
(import_selectors
234-
(import_wildcard)
235-
(import_wildcard)))
233+
(namespace_selectors
234+
(namespace_wildcard)
235+
(namespace_wildcard)))
236236
(import_declaration
237237
(identifier)
238-
(import_wildcard)))
238+
(namespace_wildcard)))
239239

240240
================================
241241
Imports: Givens by type (Scala 3 syntax)
@@ -248,7 +248,7 @@ import tools.nsc.classpath.{given Test, given Test2, Test3}
248248
(compilation_unit
249249
(import_declaration
250250
(identifier) (identifier) (identifier)
251-
(import_selectors
251+
(namespace_selectors
252252
(type_identifier)
253253
(type_identifier)
254254
(identifier))))
@@ -264,7 +264,7 @@ import lang.System.{lineSeparator as EOL}
264264
(compilation_unit
265265
(import_declaration
266266
(identifier) (identifier)
267-
(import_selectors (renamed_identifier (identifier) (identifier)))))
267+
(namespace_selectors (renamed_identifier (identifier) (identifier)))))
268268

269269
================================
270270
Imports: Rename
@@ -277,7 +277,7 @@ import lang.System.{lineSeparator => EOL}
277277
(compilation_unit
278278
(import_declaration
279279
(identifier) (identifier)
280-
(import_selectors (renamed_identifier (identifier) (identifier)))))
280+
(namespace_selectors (renamed_identifier (identifier) (identifier)))))
281281

282282

283283
=================================
@@ -1101,3 +1101,26 @@ transparent trait Kind:
11011101
(function_definition
11021102
(identifier)
11031103
(integer_literal)))))
1104+
1105+
1106+
1107+
================================
1108+
Exports (Scala 3)
1109+
================================
1110+
1111+
export scanUnit.scan
1112+
export printUnit.{status as _, *}
1113+
1114+
---
1115+
1116+
(compilation_unit
1117+
(export_declaration
1118+
(identifier)
1119+
(identifier))
1120+
(export_declaration
1121+
(identifier)
1122+
(namespace_selectors
1123+
(renamed_identifier
1124+
(identifier)
1125+
(wildcard))
1126+
(namespace_wildcard))))

grammar.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ module.exports = grammar({
8989
$.extension_definition,
9090
$.class_definition,
9191
$.import_declaration,
92+
$.export_declaration,
9293
$.object_definition,
9394
$.enum_definition,
9495
$.trait_definition,
@@ -176,31 +177,37 @@ module.exports = grammar({
176177

177178
import_declaration: $ => prec.left(seq(
178179
'import',
179-
sep1(',', $._import_expression)
180+
sep1(',', $._namespace_expression)
180181
)),
181182

182-
_import_expression: $ => prec.left(seq(
183+
export_declaration: $ => prec.left(seq(
184+
'export',
185+
sep1(',', $._namespace_expression)
186+
)),
187+
188+
189+
_namespace_expression: $ => prec.left(seq(
183190
field('path', sep1('.', $.identifier)),
184191
optional(seq(
185192
'.',
186193
choice(
187-
$.import_wildcard,
188-
$.import_selectors,
194+
$.namespace_wildcard,
195+
$.namespace_selectors,
189196
),
190197
)),
191198
)),
192199

193-
import_wildcard: $ => prec.left(1,
200+
namespace_wildcard: $ => prec.left(1,
194201
choice('*', '_', 'given')
195202
),
196203

197-
_import_given_by_type: $ => seq('given', $._type),
204+
_namespace_given_by_type: $ => seq('given', $._type),
198205

199-
import_selectors: $ => seq(
206+
namespace_selectors: $ => seq(
200207
'{',
201208
commaSep1(choice(
202-
$._import_given_by_type,
203-
$.import_wildcard,
209+
$._namespace_given_by_type,
210+
$.namespace_wildcard,
204211
$.identifier,
205212
$.renamed_identifier
206213
)),

queries/highlights.scm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
(function_definition
5757
name: (identifier) @method)
5858

59-
; imports
59+
; imports/exports
6060

6161
(import_declaration
6262
path: (identifier) @namespace)
@@ -66,7 +66,15 @@
6666
path: (identifier) @type) (#lua-match? @type "^[A-Z]"))
6767
((stable_identifier (identifier) @type) (#lua-match? @type "^[A-Z]"))
6868

69-
((import_selectors (identifier) @type) (#lua-match? @type "^[A-Z]"))
69+
(export_declaration
70+
path: (identifier) @namespace)
71+
((stable_identifier (identifier) @namespace))
72+
73+
((export_declaration
74+
path: (identifier) @type) (#lua-match? @type "^[A-Z]"))
75+
((stable_identifier (identifier) @type) (#lua-match? @type "^[A-Z]"))
76+
77+
((namespace_selectors (identifier) @type) (#lua-match? @type "^[A-Z]"))
7078

7179
; method invocation
7280

@@ -213,7 +221,7 @@
213221
"@"
214222
] @operator
215223

216-
"import" @include
224+
["import" "export"] @include
217225

218226
[
219227
"try"

test/highlight/scala3.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,17 @@ given Test with
6767
def test = 1
6868
// ^keyword.function
6969
val a = "hello"
70+
71+
72+
class Copier:
73+
private val printUnit = new Printer { type PrinterType = InkJet }
74+
private val scanUnit = new Scanner
75+
76+
export scanUnit.scan
77+
// ^ include
78+
// ^namespace
79+
export printUnit.{status as _, *}
80+
// ^ include
81+
// ^namespace
82+
83+
def status: List[String] = printUnit.status ++ scanUnit.status

0 commit comments

Comments
 (0)