Skip to content

Commit

Permalink
Add IntoApply
Browse files Browse the repository at this point in the history
  • Loading branch information
InversionSpaces committed Feb 13, 2024
1 parent 9423ffc commit b593c7d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions parser/src/main/scala/aqua/parser/lexer/NamedArg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ enum NamedArg[F[_]] extends Token[F] {
case Full(name, value) => Full(name.mapK(fk), value.mapK(fk))
case Short(variable) => Short(variable.mapK(fk))
}

override def toString: String = this match {
case Full(name, value) => s"$name = $value"
case Short(variable) => variable.toString
}
}

object NamedArg {
Expand Down
24 changes: 22 additions & 2 deletions parser/src/main/scala/aqua/parser/lexer/PropertyOp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ case class IntoField[F[_]: Comonad](name: F[String]) extends PropertyOp[F] {

override def mapK[K[_]: Comonad](fk: F ~> K): PropertyOp[K] = copy(fk(name))

def value: String = name.extract
lazy val value: String = name.extract

override def toString: String = name.extract
}
Expand All @@ -46,6 +46,8 @@ case class IntoIndex[F[_]: Comonad](point: F[Unit], idx: Option[ValueToken[F]])
override def as[T](v: T): F[T] = point.as(v)

override def mapK[K[_]: Comonad](fk: F ~> K): IntoIndex[K] = copy(fk(point), idx.map(_.mapK(fk)))

override def toString: String = s"[$idx]"
}

case class IntoCopy[F[_]: Comonad](
Expand All @@ -56,6 +58,21 @@ case class IntoCopy[F[_]: Comonad](

override def mapK[K[_]: Comonad](fk: F ~> K): IntoCopy[K] =
copy(fk(point), args.map(_.mapK(fk)))

override def toString: String = s".copy(${args.map(_.toString).toList.mkString(", ")})"
}

case class IntoApply[F[_]: Comonad](
argsF: F[NonEmptyList[NamedArg[F]]]
) extends PropertyOp[F] {
lazy val args: NonEmptyList[NamedArg[F]] = argsF.extract

override def as[T](v: T): F[T] = argsF.as(v)

override def mapK[K[_]: Comonad](fk: F ~> K): IntoApply[K] =
copy(fk(argsF.map(_.map(_.mapK(fk)))))

override def toString: String = s"(${args.map(_.toString).toList.mkString(", ")})"
}

object PropertyOp {
Expand Down Expand Up @@ -87,8 +104,11 @@ object PropertyOp {
}
}

private val parseApply: P[PropertyOp[Span.S]] =
namedArgs.lift.map(IntoApply.apply)

private val parseOp: P[PropertyOp[Span.S]] =
P.oneOf(parseCopy.backtrack :: parseArrow.backtrack :: parseField :: parseIdx :: Nil)
P.oneOf(parseCopy.backtrack :: parseArrow.backtrack :: parseField :: parseIdx :: parseApply :: Nil)

val ops: P[NonEmptyList[PropertyOp[Span.S]]] =
parseOp.rep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class HeaderHandler[S[_]: Comonad, C](using
.toValidNec(
error(
tkn,
s"Used module has no `module` header. Please add `module` header or use ... as ModuleName, or switch to import"
s"Used module has no `aqua` header. Please add `aqua` header or use ... as ModuleName, or switch to import"
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class ValuesAlgebra[S[_], Alg[_]: Monad](using
idx <- OptionT(op.idx.fold(LiteralRaw.Zero.some.pure)(valueToRaw))
valueType <- OptionT(T.resolveIntoIndex(op, rootType, idx.`type`))
} yield IntoIndexRaw(idx, valueType)).value
}
case op: IntoApply[S] => ???
}

def valueToRaw(v: ValueToken[S]): Alg[Option[ValueRaw]] =
v match {
Expand Down

0 comments on commit b593c7d

Please sign in to comment.