mirror of
https://github.com/fluencelabs/aqua.git
synced 2025-04-25 06:52:13 +00:00
Type aliases
This commit is contained in:
parent
694b3a040e
commit
9f80069615
@ -1,13 +1,13 @@
|
||||
package aqua.parse
|
||||
|
||||
import aqua.parse.DataType.`datatypedef`
|
||||
import aqua.parse.DataType.{`customtypedef`, `datatypedef`}
|
||||
import aqua.parse.lexer.Token._
|
||||
import aqua.parse.Type.{`arrowdef`, `typedef`}
|
||||
import aqua.parse.lift.LiftParser
|
||||
import aqua.parse.lift.LiftParser._
|
||||
import cats.Functor
|
||||
import cats.data.{NonEmptyList, NonEmptyMap}
|
||||
import cats.parse.{Parser ⇒ P}
|
||||
import cats.parse.{Parser => P}
|
||||
|
||||
sealed trait Block[F[_]]
|
||||
case class DefType[F[_]](name: F[String], fields: NonEmptyMap[String, F[DataType]]) extends Block[F]
|
||||
@ -16,6 +16,7 @@ case class DefService[F[_]](name: F[String], funcs: NonEmptyMap[String, ArrowTyp
|
||||
case class FuncHead[F[_]](name: F[String], args: Map[String, Type], ret: Option[DataType])
|
||||
|
||||
case class DefFunc[F[_]](head: FuncHead[F], body: NonEmptyList[F[FuncOp[F]]]) extends Block[F]
|
||||
case class DefAlias[F[_]](alias: CustomType, target: Type) extends Block[F]
|
||||
|
||||
object DefType {
|
||||
def `dname`[F[_]: LiftParser]: P[F[String]] = `data` *> ` ` *> Name.lift <* ` `.? <* `:` <* ` \n*`
|
||||
@ -61,8 +62,18 @@ object DefService {
|
||||
}
|
||||
}
|
||||
|
||||
object DefAlias {
|
||||
|
||||
def `defalias`[F[_]: LiftParser]: P[DefAlias[F]] =
|
||||
((`alias` *> ` ` *> `customtypedef` <* ` : `) ~ `typedef`).map {
|
||||
case (ct, t) => DefAlias(ct, t)
|
||||
}
|
||||
}
|
||||
|
||||
object Block {
|
||||
|
||||
def block[F[_]: LiftParser: Functor]: P[Block[F]] =
|
||||
` \n*`.rep0.with1 *> P.oneOf(DefType.`deftype` :: DefService.`defservice` :: DefFunc.`deffunc` :: Nil)
|
||||
` \n*`.rep0.with1 *> P.oneOf(
|
||||
DefType.`deftype` :: DefService.`defservice` :: DefFunc.`deffunc` :: DefAlias.`defalias` :: Nil
|
||||
)
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ object Token {
|
||||
|
||||
val ` ` : P[String] = P.charsWhile(fSpaces)
|
||||
val `data`: P[Unit] = P.string("data")
|
||||
val `alias`: P[Unit] = P.string("alias")
|
||||
val `service`: P[Unit] = P.string("service")
|
||||
val `func`: P[Unit] = P.string("func")
|
||||
val `on`: P[Unit] = P.string("on")
|
||||
|
@ -1,7 +1,8 @@
|
||||
package aqua.parse.lift
|
||||
|
||||
import cats.{Comonad, Functor}
|
||||
import cats.Comonad
|
||||
import cats.parse.{Parser ⇒ P}
|
||||
import cats.free.Free
|
||||
|
||||
import scala.language.implicitConversions
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user