File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
docs/docs/reference/metaprogramming Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -446,7 +446,7 @@ as follows:
446
446
of splices minus the number of quotes between use and definition
447
447
is either 0 or 1.
448
448
449
- ### Limitations to Splicing
449
+ ### Scope Extrusion
450
450
451
451
Quotes and splices are duals as far as the PCP is concerned. But there is an additional
452
452
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:
566
566
### Relationship with Whitebox Inline
567
567
568
568
` 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]
Original file line number Diff line number Diff line change @@ -91,6 +91,30 @@ def macroImpl(param: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = {
91
91
92
92
TODO
93
93
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
+
94
118
### Tree Utilities
95
119
96
120
`scala.tasty.reflect.TreeUtils` contains three facilities for tree traversal and
You can’t perform that action at this time.
0 commit comments