Skip to content

Commit b0408eb

Browse files
committed
Address comments
1 parent c514aaa commit b0408eb

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

docs/docs/reference/tasty-reflect.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ layout: doc-page
33
title: "TASTy reflect"
44
---
55

6-
TASTy reflect provides an API that allows inspection and construction of Typed Abstract Syntax Trees (TAST).
7-
It may be used on quoted expressions (`quoted.Expr`) and types (`quoted.Type`) from [Principled Meta-programming](./principled-meta-programming.html)
6+
TASTy Reflect enables inspection and construction of Typed Abstract Syntax Trees (TAST).
7+
It may be used on quoted expressions (`quoted.Expr`) and quoted types (`quoted.Type`) from [Principled Meta-programming](./principled-meta-programming.html)
88
or on full TASTy files.
99

10-
If you are starting using macros see first [Principled Meta-programming](./principled-meta-programming.html) and then follow with API (if really needed).
10+
If you are writing macros, please first read [Principled Meta-programming](./principled-meta-programming.html).
11+
You may find all you need without using TASTy Reflect.
1112

1213

1314
## From quotes and splices to TASTs and back
1415

15-
`quoted.Expr` and `quoted.Type` are opaque TASTs.
16-
The opaqueness required in [Principled Meta-programming](./principled-meta-programming.html) provide the guarantee that
17-
the generation of code of the macro will be type correct.
18-
Using TASTy reflect will break these guarantees and may fail at macro expansion time, hence additional explicit check must be done.
16+
`quoted.Expr` and `quoted.Type` are only meant for generative meta-programming, generation of code without inspecting the ASTs.
17+
[Principled Meta-programming](./principled-meta-programming.html) provides the guarantee that the generation of code will be type-correct.
18+
Using TASTy Reflect will break these guarantees and may fail at macro expansion time, hence additional explicit check must be done.
1919

2020

2121
To provide reflection capabilities in macro we need to add an implicit parameter of type `scala.tasty.Reflection` and import it in the scope where it is used.
@@ -32,8 +32,8 @@ def natConstImpl(x: Expr[Int])(implicit reflection: Reflection): Expr[Int] = {
3232
}
3333
```
3434

35-
`import reflection._` will provide a `reflect` extension method on `quoted.Expr` and `quoted.Type` with return a `reflection.Term` and `reflection.TypeTree` respectivly.
36-
It will also import all extractors and methods on TASTy reflect trees. For example the `Term.Literal(_)` extractor used bellow.
35+
`import reflection._` will provide a `reflect` extension method on `quoted.Expr` and `quoted.Type` which return a `reflection.Term` and `reflection.TypeTree` respectivly.
36+
It will also import all extractors and methods on TASTy Reflect trees. For example the `Term.Literal(_)` extractor used bellow.
3737
To easily know which extractor are needed the `reflection.Term.show` method returns the string representation of the extractors.
3838

3939

@@ -72,12 +72,16 @@ class Consumer extends TastyConsumer {
7272
Then the consumer can be instantiated with the following code to get the tree of the class `foo.Bar` for a foo in the classpath.
7373

7474
```scala
75-
ConsumeTasty(classpath, List("foo.Bar"), new Consumer)
75+
object Test {
76+
def main(args: Array[String]): Unit = {
77+
ConsumeTasty("", List("foo.Bar"), new Consumer)
78+
}
79+
}
7680
```
7781

78-
## TASTy reflect ASTs
82+
## TASTy Reflect ASTs
7983

80-
TASTy reflect provides the following types as defined in `scala.tasty.reflect.Core`.
84+
TASTy Reflect provides the following types:
8185

8286
```none
8387
+- Tree -+- PackageClause
@@ -187,7 +191,7 @@ Aliases:
187191
# TermOrTypeTree = Term | TypeTree
188192
```
189193

190-
## Other resources
194+
## More Examples
191195

192-
* Start plaing TASTy reflect ([link](https://github.com/nicolasstucki/tasty-reflection-exercise))
196+
* Start experimenting with TASTy Reflect ([link](https://github.com/nicolasstucki/tasty-reflection-exercise))
193197

0 commit comments

Comments
 (0)