Skip to content

Commit

Permalink
better naming, moving comments to right place
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsadlo committed Sep 6, 2024
1 parent 300f198 commit 545e536
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions os/src-2/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import os.PathChunk.{SubPathChunk, segmentsFromString}
import scala.language.experimental.macros
import acyclic.skipped

trait PathChunkMacros extends ViewBoundImplicit {
implicit def validatedStringChunk(s: String): PathChunk = macro Macros.validatedStringChunkImpl
// 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 {
implicit def stringPathChunkValidated(s: String): PathChunk =
macro Macros.stringPathChunkValidatedImpl
}

object Macros {

def validatedStringChunkImpl(c: blackbox.Context)(s: c.Expr[String]): c.Expr[SubPathChunk] = {
def stringPathChunkValidatedImpl(c: blackbox.Context)(s: c.Expr[String]): c.Expr[SubPathChunk] = {
import c.universe._

s match {
Expand Down
7 changes: 4 additions & 3 deletions os/src-3/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import os.PathChunk.{SubPathChunk, segmentsFromString}
import scala.collection.immutable.IndexedSeq
import scala.quoted.{Expr, Quotes}

trait PathChunkMacros extends ViewBoundImplicit{
inline implicit def validatedStringChunk(s:String): PathChunk = ${validatedPathChunkImpl('s)}
// 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)}
}

object Macros {
def validatedPathChunkImpl(s:Expr[String])(using quotes: Quotes): Expr[SubPathChunk] = {
def stringPathChunkValidatedImpl(s:Expr[String])(using quotes: Quotes): Expr[SubPathChunk] = {
import quotes.reflect.*

s.asTerm match {
Expand Down
5 changes: 2 additions & 3 deletions os/src/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ trait PathChunk {
def segments: Seq[String]
def ups: Int
}
trait ViewBoundImplicit {
trait StringPathChunkConversion {

// fallback to non-macro String => PathChunk implicit conversion in case eta expansion is needed, this is required for ArrayPathChunk and SeqPathChunk
implicit def validatedStringFunction(s: String): PathChunk =
implicit def stringToPathChunk(s: String): PathChunk =
new PathChunk.StringPathChunkInternal(s)
}

Expand Down

0 comments on commit 545e536

Please sign in to comment.