-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove unnecessary imports, format scala3
- Loading branch information
1 parent
545e536
commit 924a02e
Showing
1 changed file
with
6 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
package os | ||
|
||
import os.Macros.validatedPathChunkImpl | ||
import os.PathChunk.{SubPathChunk, segmentsFromString} | ||
|
||
import scala.collection.immutable.IndexedSeq | ||
import scala.quoted.{Expr, Quotes} | ||
|
||
// StringPathChunkConversion is a fallback to non-macro String => PathChunk implicit conversion in case eta expansion is needed, this is required for ArrayPathChunk and SeqPathChunk | ||
trait PathChunkMacros extends StringPathChunkConversion{ | ||
inline implicit def stringPathChunkValidated(s:String): PathChunk = ${stringPathChunkValidatedImpl('s)} | ||
trait PathChunkMacros extends StringPathChunkConversion { | ||
inline implicit def stringPathChunkValidated(s: String): PathChunk = | ||
${ Macros.stringPathChunkValidatedImpl('s) } | ||
} | ||
|
||
object Macros { | ||
def stringPathChunkValidatedImpl(s:Expr[String])(using quotes: Quotes): Expr[SubPathChunk] = { | ||
def stringPathChunkValidatedImpl(s: Expr[String])(using quotes: Quotes): Expr[SubPathChunk] = { | ||
import quotes.reflect.* | ||
|
||
s.asTerm match { | ||
case Inlined(_, _, Literal(StringConstant(literal))) => | ||
val stringSegments = segmentsFromString(literal) | ||
stringSegments.foreach(BasePath.checkSegment) | ||
|
||
'{new SubPathChunk(SubPath.apply(${Expr(stringSegments)}.toIndexedSeq))} | ||
'{ new SubPathChunk(SubPath.apply(${ Expr(stringSegments) }.toIndexedSeq)) } | ||
case _ => | ||
'{{new SubPathChunk(SubPath.apply(IndexedSeq($s)))}} | ||
'{ { new SubPathChunk(SubPath.apply(IndexedSeq($s))) } } | ||
} | ||
} | ||
} |