Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
mio-19 committed Oct 28, 2024
1 parent 74419f4 commit e09b42e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ up := {
log.warn(s"Directory ${dir.getName} does not exist, skipping")
}
}

log.success("Finished updating all dependencies")
}

Expand Down
2 changes: 1 addition & 1 deletion cli/shared/src/main/scala/chester/cli/CLI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class CLI[F[_]](using
|}""".stripMargin
def initializePackageJson(): F[Unit] = {
for {
currentDir <- IO.pwd
currentDir <- IO.workingDir
packageJsonPath = io.pathOps.join(currentDir, "package.json")
_ <- IO.writeString(packageJsonPath, content(io.pathOps.baseName(currentDir)))
_ <- IO.println("Initialized package.json in the current directory.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ implicit object DefaultIO extends IO[Future] {
inline override def println(x: String): Future[Unit] =
Future.successful(Predef.println(x))

override inline def ask(x: String): String = ???

inline override def readString(path: String): Future[String] =
fsPromisesMod.readFile(path, BufferEncoding.utf8)

Expand Down Expand Up @@ -59,7 +61,7 @@ implicit object DefaultIO extends IO[Future] {
false
}

inline override def pwd: Future[String] =
inline override def workingDir: Future[String] =
Future.successful(processMod.^.cwd())

inline override def getHomeDir: Future[String] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,48 @@ implicit object DefaultIO extends IO[Id] {
override inline def pathOps = DefaultPathOps

override inline def println(x: String): Unit = Predef.println(x)
override inline def ask(x: String): String = {
Predef.print(x)
scala.io.StdIn.readLine()
}

override def pwd: os.Path = os2.pwd
override def workingDir: os.Path = os2.pwd

override inline def readString(path: Path): String =
os.read(path.resolveFrom(pwd))
os.read(path.resolveFrom(workingDir))

override inline def read(path: Path): Array[Byte] =
os.read.bytes(path.resolveFrom(pwd))
os.read.bytes(path.resolveFrom(workingDir))

override inline def writeString(
path: Path,
content: String,
append: Boolean = false
): Unit = {
if (append) {
os.write.append(path.resolveFrom(pwd), content)
os.write.append(path.resolveFrom(workingDir), content)
} else {
os.write(path.resolveFrom(pwd), content)
os.write(path.resolveFrom(workingDir), content)
}
}

override inline def write(path: Path, content: Array[Byte]): Unit = {
os.write(path.resolveFrom(pwd), content)
os.write(path.resolveFrom(workingDir), content)
}

override inline def removeWhenExists(path: Path): Boolean = {
os.remove(path.resolveFrom(pwd), true)
os.remove(path.resolveFrom(workingDir), true)
}

override inline def getHomeDir: Path = FilePath(
java.nio.file.Paths.get(System.getProperty("user.home"))
)

override inline def exists(path: Path): Boolean =
os.exists(path.resolveFrom(pwd))
os.exists(path.resolveFrom(workingDir))

override inline def createDirRecursiveIfNotExists(path: Path): Unit = {
os.makeDir.all(path.resolveFrom(pwd))
os.makeDir.all(path.resolveFrom(workingDir))
}

override inline def downloadToFile(url: String, path: Path): Unit =
Expand All @@ -104,7 +108,7 @@ implicit object DefaultIO extends IO[Id] {
Files.setPosixFilePermissions(path.toNIO, perms)
}

override inline def getAbsolutePath(path: Path): Path = path.resolveFrom(pwd)
override inline def getAbsolutePath(path: Path): Path = path.resolveFrom(workingDir)

@ifndef("scalaNativeForTermux")
override inline def call(command: Seq[String]): CommandOutput = {
Expand All @@ -119,10 +123,10 @@ implicit object DefaultIO extends IO[Id] {
}

override def listFiles(path: Path): Id[Seq[Path]] = {
os.list(path.resolveFrom(pwd))
os.list(path.resolveFrom(workingDir))
}

override def isDirectory(path: Path): Id[Boolean] = {
os.isDir(path.resolveFrom(pwd))
os.isDir(path.resolveFrom(workingDir))
}
}
38 changes: 20 additions & 18 deletions syntax/src/main/scala/chester/syntax/core/Term.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import scala.language.implicitConversions
/* Type Hierarchy Naming Conventions:
*
* The codebase follows these suffix patterns:
*
*
* - *C (e.g. LocalVC): Abstract "case class-like" traits that define the structure and behavior
* for a specific term type. These contain the common fields and methods that will be
* for a specific term type. These contain the common fields and methods that will be
* implemented by concrete case classes.
*
* - *F (e.g. LocalVF): Function interfaces used for constructing terms. These define
Expand Down Expand Up @@ -999,8 +999,8 @@ case class Function(

@deprecated("not used")
case class MatchingClause(meta: OptionTermMeta) extends WHNF {
override type ThisTree = MatchingClause
override def descent(f: Term => Term, g: TreeMap[Term]): MatchingClause = this
override type ThisTree = MatchingClause
override def descent(f: Term => Term, g: TreeMap[Term]): MatchingClause = this
override def toDoc(using options: PrettierOptions): Doc = toString // TODO

}
Expand Down Expand Up @@ -2023,15 +2023,15 @@ trait ObjectCallTermC[Rec <: TermT[Rec]] extends UnevalT[Rec] {
override type ThisTree <: ObjectCallTermC[Rec]
def objectRef: Rec
def cons: ObjectCallTermF[Rec, ThisTree]

override def toTerm: ObjectCallTerm = ObjectCallTerm(objectRef.toTerm, meta)

override def toDoc(using options: PrettierOptions): Doc =
group("ObjectCall" <+> objectRef.toDoc)

def cpy(objectRef: Rec = objectRef, meta: OptionTermMeta = meta): ThisTree =
cons.apply(objectRef, meta)

def descent(f: Rec => Rec, g: TreeMap[Rec]): Rec = thisOr(
cpy(objectRef = f(objectRef))
)
Expand All @@ -2040,33 +2040,34 @@ trait ObjectCallTermC[Rec <: TermT[Rec]] extends UnevalT[Rec] {
case class ObjectCallTerm(
objectRef: Term,
meta: OptionTermMeta
) extends Uneval with ObjectCallTermC[Term] {
) extends Uneval
with ObjectCallTermC[Term] {
override type ThisTree = ObjectCallTerm
override def cons: ObjectCallTermF[Term, ThisTree] = this.copy

override def descent(f: Term => Term, g: TreeMap[Term]): ObjectCallTerm = thisOr(
copy(objectRef = f(objectRef))
)
}

@FunctionalInterface
trait ObjectTypeTermF[Rec <: TermT[Rec], ThisTree <: ObjectTypeTermC[Rec]] {
def apply(objectDef: ObjectStmtTerm, meta: OptionTermMeta): ThisTree
def apply(objectDef: ObjectStmtTerm, meta: OptionTermMeta): ThisTree
}

trait ObjectTypeTermC[Rec <: TermT[Rec]] extends TypeTermT[Rec] {
override type ThisTree <: ObjectTypeTermC[Rec]
def objectDef: ObjectStmtTerm
def cons: ObjectTypeTermF[Rec, ThisTree]

override def toTerm: ObjectTypeTerm = ObjectTypeTerm(objectDef, meta)

override def toDoc(using options: PrettierOptions): Doc =
Doc.text("ObjectType(") <> objectDef.name.toDoc <> Doc.text(")")

def cpy(objectDef: ObjectStmtTerm = objectDef, meta: OptionTermMeta = meta): ThisTree =
cons.apply(objectDef, meta)

def descent(f: Rec => Rec, g: TreeMap[Rec]): Rec = thisOr(
cpy(objectDef = g(objectDef))
)
Expand All @@ -2075,10 +2076,11 @@ trait ObjectTypeTermC[Rec <: TermT[Rec]] extends TypeTermT[Rec] {
case class ObjectTypeTerm(
objectDef: ObjectStmtTerm,
meta: OptionTermMeta
) extends TypeTerm with ObjectTypeTermC[Term] {
) extends TypeTerm
with ObjectTypeTermC[Term] {
override type ThisTree = ObjectTypeTerm
override def cons: ObjectTypeTermF[Term, ThisTree] = this.copy

override def descent(f: Term => Term, g: TreeMap[Term]): ObjectTypeTerm = thisOr(
copy(objectDef = g(objectDef))
)
Expand Down Expand Up @@ -2186,4 +2188,4 @@ object NodeKind {
case object ObjectCallTerm extends ConcreteNodeKind
case object ObjectTypeTerm extends ConcreteNodeKind
case object ObjectStmtTerm extends ConcreteNodeKind
}
}
6 changes: 4 additions & 2 deletions utils/shared/src/main/scala/chester/utils/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ implicit inline def summonPathOpsFromIO[F[_]](using
trait IO[F[_]] {
type Path

def pwd: F[Path]
def workingDir: F[Path]

def pathOps: PathOps[Path]

def println(x: String): F[Unit]
def ask(x: String): F[String]

def readString(path: Path): F[String]

Expand Down Expand Up @@ -84,7 +85,8 @@ object IO {
}

extension [F[_]](_io: IO.type)(using io: IO[F]) {
inline def pwd: F[io.Path] = io.pwd
inline def ask(inline x: String): F[String] = io.ask(x)
inline def workingDir: F[io.Path] = io.workingDir
inline def readString(inline path: io.Path): F[String] = io.readString(path)
inline def read(inline path: io.Path): F[Array[Byte]] = io.read(path)
inline def writeString(
Expand Down

0 comments on commit e09b42e

Please sign in to comment.