mirror of
https://github.com/fluencelabs/aqua.git
synced 2025-03-15 19:50:51 +00:00
LNG-78 parser error on negative array indexes (#538)
This commit is contained in:
parent
4f21f0a0bd
commit
792e174641
@ -20,18 +20,20 @@ import cats.data.{Chain, State}
|
||||
|
||||
object CollectionRawInliner extends RawInliner[CollectionRaw] {
|
||||
|
||||
override def apply[S: Mangler : Exports : Arrows](
|
||||
raw: CollectionRaw,
|
||||
lambdaAllowed: Boolean
|
||||
): State[S, (ValueModel, Inline)] =
|
||||
override def apply[S: Mangler: Exports: Arrows](
|
||||
raw: CollectionRaw,
|
||||
lambdaAllowed: Boolean
|
||||
): State[S, (ValueModel, Inline)] =
|
||||
for {
|
||||
streamName <- Mangler[S].findAndForbidName((
|
||||
raw.boxType match {
|
||||
case _: StreamType => "stream"
|
||||
case _: ArrayType => "array"
|
||||
case _: OptionType => "option"
|
||||
}
|
||||
) + "-inline")
|
||||
streamName <- Mangler[S].findAndForbidName(
|
||||
(
|
||||
raw.boxType match {
|
||||
case _: StreamType => "stream"
|
||||
case _: ArrayType => "array"
|
||||
case _: OptionType => "option"
|
||||
}
|
||||
) + "-inline"
|
||||
)
|
||||
|
||||
stream = VarModel(streamName, StreamType(raw.elementType))
|
||||
streamExp = CallModel.Export(stream.name, stream.`type`)
|
||||
|
@ -13,6 +13,7 @@ import scala.language.postfixOps
|
||||
import cats.~>
|
||||
import aqua.parser.lift.Span
|
||||
import aqua.parser.lift.Span.{P0ToSpan, PToSpan}
|
||||
import aqua.types.LiteralType
|
||||
|
||||
sealed trait LambdaOp[F[_]] extends Token[F] {
|
||||
def mapK[K[_]: Comonad](fk: F ~> K): LambdaOp[K]
|
||||
@ -39,16 +40,18 @@ object LambdaOp {
|
||||
private val parseField: P[LambdaOp[Span.S]] =
|
||||
(`.` *> `name`).lift.map(IntoField(_))
|
||||
|
||||
private val nonNegativeIntP0: P0[Int] =
|
||||
Numbers.nonNegativeIntString.map(_.toInt).?.map(_.getOrElse(0))
|
||||
|
||||
private val parseIdx: P[LambdaOp[Span.S]] =
|
||||
P.defer(
|
||||
(P.defer(
|
||||
(ValueToken.`value`.between(`[`, `]`) | (exclamation *> ValueToken.num))
|
||||
.map(v => IntoIndex(v, Some(v)))
|
||||
.backtrack
|
||||
) |
|
||||
exclamation.lift.map(e => IntoIndex(Token.lift[Span.S, Unit](e), None))
|
||||
) | exclamation.lift.map(e => IntoIndex(Token.lift[Span.S, Unit](e), None))).flatMap { ii =>
|
||||
ii.idx match {
|
||||
case Some(LiteralToken(_, lt)) if lt == LiteralType.signed =>
|
||||
P.fail.withContext("Collection indexes must be non-negative")
|
||||
case _ => P.pure(ii)
|
||||
}
|
||||
}
|
||||
|
||||
private val parseOp: P[LambdaOp[Span.S]] =
|
||||
P.oneOf(parseField.backtrack :: parseIdx :: Nil)
|
||||
|
@ -17,6 +17,9 @@ class LambdaOpSpec extends AnyFlatSpec with Matchers with EitherValues {
|
||||
opsP(".field") should be(NonEmptyList.of(IntoField[Id]("field")))
|
||||
opsP(".field.sub") should be(NonEmptyList.of(IntoField[Id]("field"), IntoField[Id]("sub")))
|
||||
|
||||
LambdaOp.ops.parseAll("[-1]").isLeft shouldBe true
|
||||
LambdaOp.ops.parseAll("!-1").isLeft shouldBe true
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user