Skip to content

Commit

Permalink
remove unnecessary imports, format scala3
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsadlo committed Sep 6, 2024
1 parent 545e536 commit 924a02e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions os/src-3/Macros.scala
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))) } }
}
}
}

0 comments on commit 924a02e

Please sign in to comment.