Skip to content

Commit 8e1ee2e

Browse files
committed
Add documentation for tasty reflect
1 parent 6ac7520 commit 8e1ee2e

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

library/src/scala/tasty/Tasty.scala

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,98 +199,126 @@ abstract class Tasty { tasty =>
199199

200200
implicit def termClassTag: ClassTag[Term]
201201

202+
/** Scala term. Any tree that can go in expression position. */
202203
val Term: TermModule
203204
abstract class TermModule {
204205

206+
/** Matches any term */
205207
def unapply(x: Term)(implicit ctx: Context): Boolean
206208

209+
/** Scala term identifier */
207210
val Ident: IdentExtractor
208211
abstract class IdentExtractor {
212+
/** Matches a term identifier and returns its name */
209213
def unapply(x: Term)(implicit ctx: Context): Option[String]
210214
}
211215

216+
/** Scala term selection */
212217
val Select: SelectExtractor
213218
abstract class SelectExtractor {
219+
/** Matches `<qual: Term>.<name: String>: <sig: Signature>` */
214220
def unapply(x: Term)(implicit ctx: Context): Option[(Term, String, Option[Signature])]
215221
}
216222

223+
/** Scala literal constant */
217224
val Literal: LiteralExtractor
218225
abstract class LiteralExtractor {
219226
def unapply(x: Term)(implicit ctx: Context): Option[Constant]
220227
}
221228

229+
/** Scala `this` or `this[id]` */
222230
val This: ThisExtractor
223231
abstract class ThisExtractor {
232+
/** Matches new `this[<id: Option[Id]>` */
224233
def unapply(x: Term)(implicit ctx: Context): Option[Option[Id]]
225234
}
226235

236+
/** Scala `new` */
227237
val New: NewExtractor
228238
abstract class NewExtractor {
239+
/** Matches new `new <tpt: TypeTree>` */
229240
def unapply(x: Term)(implicit ctx: Context): Option[TypeTree]
230241
}
231242

243+
/** Scala named argument `x = y` in argument position */
232244
val NamedArg: NamedArgExtractor
233245
abstract class NamedArgExtractor {
246+
/** Matches `<name: String> = <value: Term>` */
234247
def unapply(x: Term)(implicit ctx: Context): Option[(String, Term)]
235248
}
236249

250+
/** Scala parameter application */
237251
val Apply: ApplyExtractor
238252
abstract class ApplyExtractor {
253+
/** Matches function application `<fun: Term>(<args: List[Term]>)` */
239254
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[Term])]
240255
}
241256

257+
/** Scala type parameter application */
242258
val TypeApply: TypeApplyExtractor
243259
abstract class TypeApplyExtractor {
260+
/** Matches function type application `<fun: Term>[<args: List[TypeTree]>]` */
244261
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[TypeTree])]
245262
}
246263

264+
/** Scala `x.super` or `x.super[id]` */
247265
val Super: SuperExtractor
248266
abstract class SuperExtractor {
267+
/** Matches new `<qualifier: Term>.super[<id: Option[Id]>` */
249268
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Option[Id])]
250269
}
251270

271+
/** Scala ascription `x: T` */
252272
val Typed: TypedExtractor
253273
abstract class TypedExtractor {
274+
/** Matches `<x: Term>: <tpt: Term>` */
254275
def unapply(x: Term)(implicit ctx: Context): Option[(Term, TypeTree)]
255276
}
256277

278+
/** Scala assign `x = y` */
257279
val Assign: AssignExtractor
258280
abstract class AssignExtractor {
281+
/** Matches `<lhs: Term> = <rhs: Term>` */
259282
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Term)]
260283
}
261284

285+
/** Scala code block `{ stat0; ...; statN; expr }` term */
262286
val Block: BlockExtractor
263287
abstract class BlockExtractor {
288+
/** Matches `{ <statements: List[Statement]>; <expr: Term> }` */
264289
def unapply(x: Term)(implicit ctx: Context): Option[(List[Statement], Term)]
265290
}
266291

267-
val Inlined: InlinedExtractor
268-
abstract class InlinedExtractor {
269-
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[Definition], Term)]
270-
}
271-
272292
val Lambda: LambdaExtractor
273293
abstract class LambdaExtractor {
274294
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Option[TypeTree])]
275295
}
276296

297+
/** Scala `if`/`else` term */
277298
val If: IfExtractor
278299
abstract class IfExtractor {
300+
/** Matches `if (<cond: Term>) <thenp: Term> else <elsep: Term>` */
279301
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Term, Term)]
280302
}
281303

304+
/** Scala `match` term */
282305
val Match: MatchExtractor
283306
abstract class MatchExtractor {
307+
/** Matches `<scrutinee: Trem> match { <cases: List[CaseDef]> }` */
284308
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[CaseDef])]
285309
}
286310

311+
/** Scala `try`/`catch`/`finally` term */
287312
val Try: TryExtractor
288313
abstract class TryExtractor {
314+
/** Matches `try <body: Term> catch { <cases: List[CaseDef]> } finally <finalizer: Option[Term]>` */
289315
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[CaseDef], Option[Term])]
290316
}
291317

318+
/** Scala local `return` */
292319
val Return: ReturnExtractor
293320
abstract class ReturnExtractor {
321+
/** Matches `return <expr: Term>` */
294322
def unapply(x: Term)(implicit ctx: Context): Option[Term]
295323
}
296324

@@ -299,6 +327,11 @@ abstract class Tasty { tasty =>
299327
def unapply(x: Term)(implicit ctx: Context): Option[List[Term]]
300328
}
301329

330+
val Inlined: InlinedExtractor
331+
abstract class InlinedExtractor {
332+
def unapply(x: Term)(implicit ctx: Context): Option[(Term, List[Definition], Term)]
333+
}
334+
302335
val SelectOuter: SelectOuterExtractor
303336
abstract class SelectOuterExtractor {
304337
def unapply(x: Term)(implicit ctx: Context): Option[(Term, Int, Type)]

0 commit comments

Comments
 (0)