Compiler -> Semantics

This commit is contained in:
dmitry 2021-03-19 11:18:52 +03:00
parent 9d2489ea14
commit 90abafc221
2 changed files with 7 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import aqua.generator.{Gen, ScriptGen}
import aqua.parser.Ast
import cats.data.ValidatedNel
import aqua.parser.lift.Span
import aqua.semantics.Semantics
import scala.collection.immutable.Queue
@ -12,11 +13,11 @@ object Aqua {
def parse(input: String): ValidatedNel[AquaError, Ast[Span.F]] =
Ast.fromString[Span.F](input)
def compile(input: String): ValidatedNel[AquaError, Gen] =
parse(input).andThen(ast => Compiler.compile(ast).leftMap(_.map(ts => CompilerError(ts._1.unit._1, ts._2))))
def validate(input: String): ValidatedNel[AquaError, Gen] =
parse(input).andThen(ast => Semantics.validate(ast).leftMap(_.map(ts => CompilerError(ts._1.unit._1, ts._2))))
def generate(input: String): ValidatedNel[AquaError, Queue[String]] =
compile(input).map {
validate(input).map {
case g: ScriptGen => g.generateAir
case _ => Queue.empty
}

View File

@ -1,9 +1,8 @@
package aqua
package aqua.semantics
import aqua.generator.Gen
import aqua.parser.lexer.Token
import aqua.parser.{Ast, Expr}
import aqua.semantics.ExprSem
import aqua.semantics.algebra.ReportError
import aqua.semantics.algebra.abilities.{AbilitiesAlgebra, AbilitiesInterpreter, AbilitiesState, AbilityOp}
import aqua.semantics.algebra.names.{NameOp, NamesAlgebra, NamesInterpreter, NamesState}
@ -21,7 +20,7 @@ import cats.syntax.semigroup._
import scala.collection.immutable.Queue
object Compiler {
object Semantics {
def folder[F[_], G[_]](implicit
A: AbilitiesAlgebra[F, G],
@ -83,7 +82,7 @@ object Compiler {
free.foldMap[State[CompilerState[F], *]](interpreter)
}
def compile[F[_]](ast: Ast[F]): ValidatedNel[(Token[F], String), Gen] =
def validate[F[_]](ast: Ast[F]): ValidatedNel[(Token[F], String), Gen] =
(transpile[F] _ andThen interpret[F])(ast)
.run(CompilerState[F]())
.map {