LNG-85 Streams restrictions in aqua (#555)

This commit is contained in:
Dima 2022-09-20 18:04:55 +04:00 committed by GitHub
parent 33db5c51bf
commit e409605d21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 11 deletions

View File

@ -17,7 +17,7 @@ val scribeV = "3.7.1"
name := "aqua-hll"
val commons = Seq(
baseAquaVersion := "0.7.5",
baseAquaVersion := "0.7.6",
version := baseAquaVersion.value + "-" + sys.env.getOrElse("BUILD_NUMBER", "SNAPSHOT"),
scalaVersion := dottyVersion,
libraryDependencies ++= Seq(

View File

@ -2,7 +2,7 @@ package aqua.parser.expr
import aqua.parser.Expr
import aqua.parser.lexer.Token.*
import aqua.parser.lexer.{DataTypeToken, Name}
import aqua.parser.lexer.{DataTypeToken, Name, StreamTypeToken}
import aqua.parser.lift.LiftParser
import cats.Comonad
import cats.parse.Parser
@ -11,7 +11,7 @@ import aqua.parser.lift.Span
import aqua.parser.lift.Span.{P0ToSpan, PToSpan}
case class FieldTypeExpr[F[_]](name: Name[F], `type`: DataTypeToken[F])
extends Expr[F](FieldTypeExpr, name) {
extends Expr[F](FieldTypeExpr, name) {
override def mapK[K[_]: Comonad](fk: F ~> K): FieldTypeExpr[K] =
copy(name.mapK(fk), `type`.mapK(fk))
@ -20,7 +20,11 @@ case class FieldTypeExpr[F[_]](name: Name[F], `type`: DataTypeToken[F])
object FieldTypeExpr extends Expr.Leaf {
override val p: Parser[FieldTypeExpr[Span.S]] =
((Name.p <* ` : `) ~ DataTypeToken.`datatypedef`).map { case (name, t) =>
((Name.p <* ` : `) ~ (Parser
.not(StreamTypeToken.`streamtypedef`)
.withContext(
"Data fields cannot be of stream type (stream is designated by '*')."
) *> DataTypeToken.`datatypedef`)).map { case (name, t) =>
FieldTypeExpr(name, t)
}
}

View File

@ -3,10 +3,10 @@ package aqua.parser.expr.func
import aqua.parser.Expr
import aqua.parser.expr.func.AssignmentExpr
import aqua.parser.lexer.Token.*
import aqua.parser.lexer.{Name, ValueToken}
import aqua.parser.lexer.{CollectionToken, Name, ValueToken}
import aqua.parser.lift.LiftParser
import cats.parse.Parser as P
import cats.{Comonad, ~>}
import cats.{~>, Comonad}
import aqua.parser.lift.Span
import aqua.parser.lift.Span.{P0ToSpan, PToSpan}
@ -20,7 +20,16 @@ case class AssignmentExpr[F[_]](
object AssignmentExpr extends Expr.Leaf {
override val p: P[AssignmentExpr[Span.S]] =
((Name.p <* ` = `).with1 ~ ValueToken.`value`).map { case (variable, value) =>
AssignmentExpr(variable, value)
((Name.p <* ` = `).with1 ~ ValueToken.`value`).flatMap { case (variable, value) =>
value match {
case CollectionToken(_, values) =>
if (values.isEmpty)
P.failWith(
"Assigning empty array to a variable is prohibited. You can create an array with values (like '[a, b, c]') or use '[]' in place."
)
else P.pure(AssignmentExpr(variable, value))
case _ =>
P.pure(AssignmentExpr(variable, value))
}
}
}

View File

@ -59,7 +59,7 @@ case class OptionTypeToken[F[_]: Comonad](override val unit: F[Unit], data: Data
object OptionTypeToken {
val `optiontypedef`: P[OptionTypeToken[Span.S]] =
(`?`.lift ~ DataTypeToken.`datatypedef`).map(ud => OptionTypeToken(ud._1, ud._2))
(`?`.lift ~ DataTypeToken.`withoutstreamdatatypedef`).map(ud => OptionTypeToken(ud._1, ud._2))
}
@ -135,13 +135,13 @@ object ArrowTypeToken {
object DataTypeToken {
val `arraytypedef`: P[ArrayTypeToken[Span.S]] =
(`[]`.lift ~ `datatypedef`).map(ud => ArrayTypeToken(ud._1, ud._2))
(`[]`.lift ~ `withoutstreamdatatypedef`).map(ud => ArrayTypeToken(ud._1, ud._2))
val `topbottomdef`: P[TopBottomToken[Span.S]] =
`⊥`.lift.map(TopBottomToken(_, isTop = false)) |
``.lift.map(TopBottomToken(_, isTop = true))
val `withoutstreamdatatypedef`: P[DataTypeToken[Span.S]] =
def `withoutstreamdatatypedef`: P[DataTypeToken[Span.S]] =
P.oneOf(
P.defer(`topbottomdef`) :: P.defer(`arraytypedef`) :: P.defer(
OptionTypeToken.`optiontypedef`