Skip to content

Commit 8c8267a

Browse files
committed
wip
1 parent a0333f9 commit 8c8267a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

docs/docs/reference/metaprogramming/macros.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ as follows:
446446
of splices minus the number of quotes between use and definition
447447
is either 0 or 1.
448448

449-
### Limitations to Splicing
449+
### Scope Extrusion
450450

451451
Quotes and splices are duals as far as the PCP is concerned. But there is an additional
452452
restriction that needs to be imposed on splices to guarantee soundness:
@@ -566,4 +566,6 @@ Here’s an application of `map` and how it rewrites to optimized code:
566566
### Relationship with Whitebox Inline
567567

568568
`inline def charOrString(inline str: String) <: Any = ${ impl(str) }`
569-
https://github.com/lampepfl/dotty/pull/5846/files (more tests needed)
569+
https://github.com/lampepfl/dotty/pull/5846/files (more tests needed)
570+
571+
[More details]

docs/docs/reference/metaprogramming/tasty-reflect.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ def macroImpl(param: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = {
9191

9292
TODO
9393

94+
### Positions
95+
96+
The tasty context provides a `rootPosition` value. For macros it corresponds to
97+
the expansion site. The macro authors can obtain various information about that
98+
expansion site. The example below shows how we can obtain position information
99+
such as the start line, the end line or even the source code at the expansion
100+
point.
101+
102+
```scala
103+
def macroImpl()(reflect: Reflection): Expr[Unit] = {
104+
import reflect.{Position => _, _}
105+
val pos = rootPosition
106+
107+
val path = pos.sourceFile.jpath.toString
108+
val start = pos.start
109+
val end = pos.end
110+
val startLine = pos.startLine
111+
val endLine = pos.endLine
112+
val startColumn = pos.startColumn
113+
val endColumn = pos.endColumn
114+
val sourceCode = pos.sourceCode
115+
...
116+
```
117+
94118
### Tree Utilities
95119

96120
`scala.tasty.reflect.TreeUtils` contains three facilities for tree traversal and

0 commit comments

Comments
 (0)