From 9d776835f6e265d565252a919072110572e9920a Mon Sep 17 00:00:00 2001 From: DieMyst Date: Fri, 31 Mar 2023 15:57:24 +0400 Subject: [PATCH] parsr for pub/priv --- .../src/main/scala/aqua/parser/expr/FuncExpr.scala | 12 ++++++++++-- parser/src/main/scala/aqua/parser/lexer/Token.scala | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/parser/src/main/scala/aqua/parser/expr/FuncExpr.scala b/parser/src/main/scala/aqua/parser/expr/FuncExpr.scala index cca390e0..bcab4168 100644 --- a/parser/src/main/scala/aqua/parser/expr/FuncExpr.scala +++ b/parser/src/main/scala/aqua/parser/expr/FuncExpr.scala @@ -13,8 +13,14 @@ import cats.~> import aqua.parser.lift.Span import aqua.parser.lift.Span.{P0ToSpan, PToSpan} +trait Visibility +case object Default extends Visibility +case object Pub extends Visibility +case object Export extends Visibility + case class FuncExpr[F[_]]( - name: Name[F] + name: Name[F], + visibility: Visibility ) extends Expr[F](FuncExpr, name) { override def mapK[K[_]: Comonad](fk: F ~> K): FuncExpr[K] = @@ -25,5 +31,7 @@ object FuncExpr extends Expr.Prefix(` `.?) { override def continueWith: List[Expr.Lexem] = ArrowExpr :: Nil override val p: Parser[FuncExpr[Span.S]] = - (`func` *> ` ` *> Name.p).map(FuncExpr(_)) + (((`pub`.map(_ => Pub) | `export`.map(_ => Export)).?.with1 <* ` `) ~ (`func` *> ` ` *> Name.p)).map { + case (visibility, name) => FuncExpr(name, visibility.getOrElse(Default)) + } } diff --git a/parser/src/main/scala/aqua/parser/lexer/Token.scala b/parser/src/main/scala/aqua/parser/lexer/Token.scala index e58bd4cf..1d06b389 100644 --- a/parser/src/main/scala/aqua/parser/lexer/Token.scala +++ b/parser/src/main/scala/aqua/parser/lexer/Token.scala @@ -62,6 +62,8 @@ object Token { val `try`: P[Unit] = P.string("try") val `catch`: P[Unit] = P.string("catch") val `par`: P[Unit] = P.string("par") + val `pub`: P[Unit] = P.string("pub") + val `export`: P[Unit] = P.string("export") val `co`: P[Unit] = P.string("co") val `join`: P[Unit] = P.string("join") val `copy`: P[Unit] = P.string("copy")