From bb7d895d51250d631e3e4a568373a733198f4707 Mon Sep 17 00:00:00 2001 From: lemastero Date: Tue, 30 Apr 2024 12:39:45 +0200 Subject: [PATCH 1/3] handle identity function --- examples/adts.agda | 14 ++-- examples/adts.scala | 8 ++- src/Agda/Compiler/Scala/AgdaToScalaExpr.hs | 77 ++++++++++++++++++++-- src/Agda/Compiler/Scala/PrintScalaExpr.hs | 20 ++++-- src/Agda/Compiler/Scala/ScalaExpr.hs | 12 ++++ 5 files changed, 113 insertions(+), 18 deletions(-) diff --git a/examples/adts.agda b/examples/adts.agda index 5cc78bf..fd5dc9d 100644 --- a/examples/adts.agda +++ b/examples/adts.agda @@ -7,9 +7,13 @@ data Rgb : Set where Blue : Rgb {-# COMPILE AGDA2SCALA Rgb #-} --- simple sum type with arguments - sealed trait + case class +data Bool : Set where + True : Bool + False : Bool +{-# COMPILE AGDA2SCALA Bool #-} -data Color : Set where - Light : Rgb -> Color - Dark : Rgb -> Color -{-# COMPILE AGDA2SCALA Color #-} +-- trivial function with single argument + +idRgb : Rgb -> Rgb +idRgb x = x +{-# COMPILE AGDA2SCALA idRgb #-} diff --git a/examples/adts.scala b/examples/adts.scala index 38a893d..3aec2ae 100644 --- a/examples/adts.scala +++ b/examples/adts.scala @@ -5,6 +5,8 @@ case object Red extends Rgb case object Green extends Rgb case object Blue extends Rgb -sealed trait Color -case object Light extends Color -case object Dark extends Color +sealed trait Bool +case object True extends Bool +case object False extends Bool + +def idRgb(x: Rgb): Rgb = x diff --git a/src/Agda/Compiler/Scala/AgdaToScalaExpr.hs b/src/Agda/Compiler/Scala/AgdaToScalaExpr.hs index 285e015..e6a0485 100644 --- a/src/Agda/Compiler/Scala/AgdaToScalaExpr.hs +++ b/src/Agda/Compiler/Scala/AgdaToScalaExpr.hs @@ -13,21 +13,88 @@ import Agda.TypeChecking.Monad.Base ( Definition(..) ) import Agda.TypeChecking.Monad import Agda.TypeChecking.CompiledClause ( CompiledClauses(..), CompiledClauses'(..) ) -import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaExpr(..) ) +import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaType, FunBody, ScalaExpr(..), SeElem(..) ) compileDefn :: QName -> Defn -> ScalaExpr compileDefn defName theDef = case theDef of Datatype{dataCons = dataCons} -> compileDataType defName dataCons Function{funCompiled = funDef, funClauses = fc} -> - Unhandled "compileDefn Function" (show defName ++ "\n = \n" ++ show theDef) + compileFunction defName funDef fc RecordDefn(RecordData{_recFields = recFields, _recTel = recTel}) -> Unhandled "compileDefn RecordDefn" (show defName ++ "\n = \n" ++ show theDef) other -> Unhandled "compileDefn other" (show defName ++ "\n = \n" ++ show theDef) compileDataType :: QName -> [QName] -> ScalaExpr -compileDataType defName fields = SeAdt (showName defName) (map showName fields) +compileDataType defName fields = SeAdt (fromQName defName) (map fromQName fields) -showName :: QName -> ScalaName -showName = prettyShow . qnameName +compileFunction :: QName + -> Maybe CompiledClauses + -> [Clause] + -> ScalaExpr +compileFunction defName funDef fc = + SeFun + (fromQName defName) + [SeElem (compileFunctionArgument fc) (compileFunctionArgType fc)] -- TODO many function arguments + (compileFunctionResultType fc) + (compileFunctionBody funDef) + +compileFunctionArgument :: [Clause] -> ScalaName +compileFunctionArgument [] = "" +compileFunctionArgument [fc] = fromDeBruijnPattern (namedThing (unArg (head (namedClausePats fc)))) +compileFunctionArgument xs = error "unsupported compileFunctionArgument" ++ (show xs) -- show xs + +compileFunctionArgType :: [Clause] -> ScalaType +compileFunctionArgType [ Clause{clauseTel = ct} ] = fromTelescope ct +compileFunctionArgType xs = error "unsupported compileFunctionArgType" ++ (show xs) + +fromTelescope :: Telescope -> ScalaName +fromTelescope tel = case tel of + ExtendTel a _ -> fromDom a + other -> error ("unhandled fromType" ++ show other) + +fromDom :: Dom Type -> ScalaName +fromDom x = fromType (unDom x) + +compileFunctionResultType :: [Clause] -> ScalaType +compileFunctionResultType [Clause{clauseType = ct}] = fromMaybeType ct +compileFunctionResultType other = error ("unhandled compileFunctionResultType" ++ show other) + +fromMaybeType :: Maybe (Arg Type) -> ScalaName +fromMaybeType (Just argType) = fromArgType argType +fromMaybeType other = error ("unhandled fromMaybeType" ++ show other) + +fromArgType :: Arg Type -> ScalaName +fromArgType arg = fromType (unArg arg) + +fromType :: Type -> ScalaName +fromType t = case t of + a@(El _ ue) -> fromTerm ue + other -> error ("unhandled fromType" ++ show other) + +fromTerm :: Term -> ScalaName +fromTerm t = case t of + Def qname el -> fromQName qname + other -> error ("unhandled fromTerm" ++ show other) + +fromDeBruijnPattern :: DeBruijnPattern -> ScalaName +fromDeBruijnPattern d = case d of + VarP a b -> (dbPatVarName b) + a@(ConP x y z) -> show a + other -> error ("unhandled fromDeBruijnPattern" ++ show other) + +compileFunctionBody :: Maybe CompiledClauses -> FunBody +compileFunctionBody (Just funDef) = fromCompiledClauses funDef +compileFunctionBody funDef = error ("unhandled compileFunctionBody " ++ show funDef) + +fromCompiledClauses :: CompiledClauses -> FunBody +fromCompiledClauses cc = case cc of + (Done (x:xs) term) -> fromArgName x + other -> error ("unhandled fromCompiledClauses " ++ show other) + +fromArgName :: Arg ArgName -> FunBody +fromArgName = unArg + +fromQName :: QName -> ScalaName +fromQName = prettyShow . qnameName diff --git a/src/Agda/Compiler/Scala/PrintScalaExpr.hs b/src/Agda/Compiler/Scala/PrintScalaExpr.hs index 5f60318..61b3a36 100644 --- a/src/Agda/Compiler/Scala/PrintScalaExpr.hs +++ b/src/Agda/Compiler/Scala/PrintScalaExpr.hs @@ -7,7 +7,7 @@ module Agda.Compiler.Scala.PrintScalaExpr ( printScalaExpr , combineLines ) where -import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaExpr(..) ) +import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaExpr(..), SeElem(..), SeArgument ) printScalaExpr :: ScalaExpr -> String printScalaExpr def = case def of @@ -21,10 +21,20 @@ printScalaExpr def = case def of (SeAdt adtName adtCases) -> (printSealedTrait adtName) <> defsSeparator - <> unlines (map (printCaseObject adtName) adtCases) - (Unhandled name payload) -> "" -- for development comment out this and uncomment below - -- (Unhandled name payload) -> "TODO " ++ (show name) ++ " " ++ (show payload) - -- other -> "unsupported printScalaExpr " ++ (show other) + <> combineLines (map (printCaseObject adtName) adtCases) + <> defsSeparator + (SeFun fName args resType funBody) -> + "def" <> exprSeparator <> fName + <> "(" <> combineLines (map printFunArg args) <> ")" + <> ":" <> exprSeparator <> resType <> exprSeparator + <> "=" <> exprSeparator <> funBody + <> defsSeparator + (Unhandled "" payload) -> "" + (Unhandled name payload) -> "TODO " ++ (show name) ++ " " ++ (show payload) + other -> "unsupported printScalaExpr " ++ (show other) + +printFunArg :: SeArgument -> String +printFunArg (SeElem sName sType) = sName <> ":" <> exprSeparator <> sType printSealedTrait :: ScalaName -> String printSealedTrait adtName = "sealed trait" <> exprSeparator <> adtName diff --git a/src/Agda/Compiler/Scala/ScalaExpr.hs b/src/Agda/Compiler/Scala/ScalaExpr.hs index fe96d09..8eb697a 100644 --- a/src/Agda/Compiler/Scala/ScalaExpr.hs +++ b/src/Agda/Compiler/Scala/ScalaExpr.hs @@ -1,15 +1,27 @@ module Agda.Compiler.Scala.ScalaExpr ( ScalaName, + ScalaType, + SeArgument, ScalaExpr(..), + SeElem(..), + FunBody, unHandled ) where type ScalaName = String +type FunBody = String -- this should be some lambda expression +type ScalaType = String + +data SeElem = SeElem ScalaName ScalaType + deriving ( Show ) + +type SeArgument = SeElem {- Represent Scala language extracted from Agda compiler representation -} data ScalaExpr = SePackage ScalaName [ScalaExpr] | SeAdt ScalaName [ScalaName] + | SeFun ScalaName [SeArgument] ScalaType FunBody | Unhandled ScalaName String deriving ( Show ) From c5abcb6ff8cc55313f8ab09374a3601e8fdea05c Mon Sep 17 00:00:00 2001 From: lemastero Date: Tue, 30 Apr 2024 16:44:45 +0200 Subject: [PATCH 2/3] handle Records as sum types --- examples/adts.agda | 12 ++++++++- examples/adts.scala | 2 ++ src/Agda/Compiler/Scala/AgdaToScalaExpr.hs | 31 +++++++++++++++++----- src/Agda/Compiler/Scala/Backend.hs | 2 ++ src/Agda/Compiler/Scala/PrintScalaExpr.hs | 24 ++++++++++++----- src/Agda/Compiler/Scala/ScalaExpr.hs | 16 +++++------ test/PrintScalaExprTest.hs | 15 ++++++++--- 7 files changed, 75 insertions(+), 27 deletions(-) diff --git a/examples/adts.agda b/examples/adts.agda index fd5dc9d..b516473 100644 --- a/examples/adts.agda +++ b/examples/adts.agda @@ -1,6 +1,7 @@ module examples.adts where --- simple sum type no arguments - sealed trait + case objects +-- simple product type no arguments - sealed trait + case objects + data Rgb : Set where Red : Rgb Green : Rgb @@ -17,3 +18,12 @@ data Bool : Set where idRgb : Rgb -> Rgb idRgb x = x {-# COMPILE AGDA2SCALA idRgb #-} + +-- simple sum type - case class + +record RgbPair : Set where + constructor mkRgbPair + field + fst : Rgb + snd : Bool +{-# COMPILE AGDA2SCALA RgbPair #-} diff --git a/examples/adts.scala b/examples/adts.scala index 3aec2ae..d87c806 100644 --- a/examples/adts.scala +++ b/examples/adts.scala @@ -10,3 +10,5 @@ case object True extends Bool case object False extends Bool def idRgb(x: Rgb): Rgb = x + +final case class RgbPair(snd: Bool, fst: Rgb) diff --git a/src/Agda/Compiler/Scala/AgdaToScalaExpr.hs b/src/Agda/Compiler/Scala/AgdaToScalaExpr.hs index e6a0485..1b70741 100644 --- a/src/Agda/Compiler/Scala/AgdaToScalaExpr.hs +++ b/src/Agda/Compiler/Scala/AgdaToScalaExpr.hs @@ -5,15 +5,18 @@ module Agda.Compiler.Scala.AgdaToScalaExpr ( import Agda.Compiler.Backend ( funCompiled, funClauses, Defn(..), RecordData(..)) import Agda.Syntax.Abstract.Name ( QName ) import Agda.Syntax.Common.Pretty ( prettyShow ) -import Agda.Syntax.Common ( Arg(..), ArgName, Named(..) ) +import Agda.Syntax.Common ( Arg(..), ArgName, Named(..), NamedName, WithOrigin(..), Ranged(..) ) import Agda.Syntax.Internal ( - Clause(..), DeBruijnPattern, DBPatVar(..), Dom(..), unDom, PatternInfo(..), Pattern'(..), + Clause(..), DeBruijnPattern, DBPatVar(..), Dom(..), Dom'(..), unDom, PatternInfo(..), Pattern'(..), qnameName, qnameModule, Telescope, Tele(..), Term(..), Type, Type''(..) ) import Agda.TypeChecking.Monad.Base ( Definition(..) ) import Agda.TypeChecking.Monad import Agda.TypeChecking.CompiledClause ( CompiledClauses(..), CompiledClauses'(..) ) +import Agda.TypeChecking.Telescope ( teleNamedArgs, teleArgs, teleArgNames ) -import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaType, FunBody, ScalaExpr(..), SeElem(..) ) +import Agda.Syntax.Common.Pretty ( prettyShow ) + +import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaType, FunBody, ScalaExpr(..), SeVar(..) ) compileDefn :: QName -> Defn -> ScalaExpr compileDefn defName theDef = case theDef of @@ -22,12 +25,18 @@ compileDefn defName theDef = case theDef of Function{funCompiled = funDef, funClauses = fc} -> compileFunction defName funDef fc RecordDefn(RecordData{_recFields = recFields, _recTel = recTel}) -> - Unhandled "compileDefn RecordDefn" (show defName ++ "\n = \n" ++ show theDef) + compileRecord defName recFields recTel other -> Unhandled "compileDefn other" (show defName ++ "\n = \n" ++ show theDef) +compileRecord :: QName -> [Dom QName] -> Telescope -> ScalaExpr +compileRecord defName recFields recTel = SeProd (fromQName defName) (foldl varsFromTelescope [] recTel) + +varsFromTelescope :: [SeVar] -> Dom Type -> [SeVar] +varsFromTelescope xs dt = SeVar (nameFromDom dt) (fromDom dt) : xs + compileDataType :: QName -> [QName] -> ScalaExpr -compileDataType defName fields = SeAdt (fromQName defName) (map fromQName fields) +compileDataType defName fields = SeSum (fromQName defName) (map fromQName fields) compileFunction :: QName -> Maybe CompiledClauses @@ -36,7 +45,7 @@ compileFunction :: QName compileFunction defName funDef fc = SeFun (fromQName defName) - [SeElem (compileFunctionArgument fc) (compileFunctionArgType fc)] -- TODO many function arguments + [SeVar (compileFunctionArgument fc) (compileFunctionArgType fc)] -- TODO many function arguments (compileFunctionResultType fc) (compileFunctionBody funDef) @@ -49,11 +58,19 @@ compileFunctionArgType :: [Clause] -> ScalaType compileFunctionArgType [ Clause{clauseTel = ct} ] = fromTelescope ct compileFunctionArgType xs = error "unsupported compileFunctionArgType" ++ (show xs) -fromTelescope :: Telescope -> ScalaName +fromTelescope :: Telescope -> ScalaName -- TODO PP probably parent should be different, use fold on telescope above fromTelescope tel = case tel of ExtendTel a _ -> fromDom a other -> error ("unhandled fromType" ++ show other) +nameFromDom :: Dom Type -> ScalaName +nameFromDom dt = case (domName dt) of + Nothing -> error ("nameFromDom" ++ show dt) + Just a -> namedNameToStr a + +namedNameToStr :: NamedName -> ScalaName +namedNameToStr n = rangedThing (woThing n) + fromDom :: Dom Type -> ScalaName fromDom x = fromType (unDom x) diff --git a/src/Agda/Compiler/Scala/Backend.hs b/src/Agda/Compiler/Scala/Backend.hs index 71908d3..f0e63b0 100644 --- a/src/Agda/Compiler/Scala/Backend.hs +++ b/src/Agda/Compiler/Scala/Backend.hs @@ -131,6 +131,8 @@ scalaPostModule :: ScalaEnv scalaPostModule env modEnv isMain mName cdefs = do outDir <- compileDir compileLog $ "compiling " <> mkOutFile outDir + compileLog $ "scalaExprs " <> (show scalaExprs) + compileLog $ "fileContent " <> fileContent unless (all unHandled cdefs) $ liftIO $ writeFile (mkOutFile outDir) fileContent diff --git a/src/Agda/Compiler/Scala/PrintScalaExpr.hs b/src/Agda/Compiler/Scala/PrintScalaExpr.hs index 61b3a36..bbee11b 100644 --- a/src/Agda/Compiler/Scala/PrintScalaExpr.hs +++ b/src/Agda/Compiler/Scala/PrintScalaExpr.hs @@ -1,13 +1,13 @@ -{-# LANGUAGE OverloadedStrings #-} - module Agda.Compiler.Scala.PrintScalaExpr ( printScalaExpr , printCaseObject , printSealedTrait , printPackage + , printCaseClass , combineLines ) where -import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaExpr(..), SeElem(..), SeArgument ) +import Data.List ( intercalate ) +import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaExpr(..), SeVar(..)) printScalaExpr :: ScalaExpr -> String printScalaExpr def = case def of @@ -18,23 +18,33 @@ printScalaExpr def = case def of <> combineLines (map printScalaExpr defs) ) <> blankLine -- EOF - (SeAdt adtName adtCases) -> + (SeSum adtName adtCases) -> (printSealedTrait adtName) <> defsSeparator <> combineLines (map (printCaseObject adtName) adtCases) <> defsSeparator (SeFun fName args resType funBody) -> "def" <> exprSeparator <> fName - <> "(" <> combineLines (map printFunArg args) <> ")" + <> "(" <> combineLines (map printVar args) <> ")" <> ":" <> exprSeparator <> resType <> exprSeparator <> "=" <> exprSeparator <> funBody <> defsSeparator + (SeProd name args) -> printCaseClass name args (Unhandled "" payload) -> "" (Unhandled name payload) -> "TODO " ++ (show name) ++ " " ++ (show payload) other -> "unsupported printScalaExpr " ++ (show other) -printFunArg :: SeArgument -> String -printFunArg (SeElem sName sType) = sName <> ":" <> exprSeparator <> sType +printCaseClass :: ScalaName -> [SeVar] -> String +printCaseClass name args = "final case class" <> exprSeparator <> name <> "(" <> (printExpr args) <> ")" + +printVar :: SeVar -> String +printVar (SeVar sName sType) = sName <> ":" <> exprSeparator <> sType + +printExpr :: [SeVar] -> String +printExpr names = combineThem (map printVar names) + +combineThem :: [String] -> String +combineThem xs = intercalate ", " xs printSealedTrait :: ScalaName -> String printSealedTrait adtName = "sealed trait" <> exprSeparator <> adtName diff --git a/src/Agda/Compiler/Scala/ScalaExpr.hs b/src/Agda/Compiler/Scala/ScalaExpr.hs index 8eb697a..0cbd221 100644 --- a/src/Agda/Compiler/Scala/ScalaExpr.hs +++ b/src/Agda/Compiler/Scala/ScalaExpr.hs @@ -1,27 +1,25 @@ module Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaType, - SeArgument, ScalaExpr(..), - SeElem(..), + SeVar(..), FunBody, unHandled ) where type ScalaName = String -type FunBody = String -- this should be some lambda expression +type FunBody = String -- this should be some lambda expression type ScalaType = String -data SeElem = SeElem ScalaName ScalaType +data SeVar = SeVar ScalaName ScalaType deriving ( Show ) - -type SeArgument = SeElem -{- Represent Scala language extracted from Agda compiler representation -} +{- Represent Scala language extracted from internal Agda compiler representation -} data ScalaExpr = SePackage ScalaName [ScalaExpr] - | SeAdt ScalaName [ScalaName] - | SeFun ScalaName [SeArgument] ScalaType FunBody + | SeSum ScalaName [ScalaName] + | SeFun ScalaName [SeVar] ScalaType FunBody + | SeProd ScalaName [SeVar] | Unhandled ScalaName String deriving ( Show ) diff --git a/test/PrintScalaExprTest.hs b/test/PrintScalaExprTest.hs index 44c02af..4e117c0 100644 --- a/test/PrintScalaExprTest.hs +++ b/test/PrintScalaExprTest.hs @@ -7,8 +7,9 @@ import Agda.Compiler.Scala.PrintScalaExpr ( , printCaseObject , printPackage , combineLines + , printCaseClass ) -import Agda.Compiler.Scala.ScalaExpr ( ScalaExpr(..) ) +import Agda.Compiler.Scala.ScalaExpr ( ScalaExpr(..), SeVar(..) ) testPrintCaseObject :: Test testPrintCaseObject = TestCase @@ -41,15 +42,23 @@ testPrintScalaExpr = TestCase ) where moduleContent = [rgbAdt, blank, blank, blank, colorAdt, blank, blank] - rgbAdt = SeAdt "Rgb" ["Red","Green","Blue"] - colorAdt = SeAdt "Color" ["Light","Dark"] + rgbAdt = SeSum "Rgb" ["Red","Green","Blue"] + colorAdt = SeSum "Color" ["Light","Dark"] blank = Unhandled "" "" +testPrintCaseClass :: Test +testPrintCaseClass = TestCase + (assertEqual "printCaseClass" + "final case class RgbPair(snd: Bool, fst: Rgb)" + (printCaseClass "RgbPair" [SeVar "snd" "Bool", SeVar "fst" "Rgb"])) + + printScalaTests :: Test printScalaTests = TestList [ TestLabel "printCaseObject" testPrintCaseObject , TestLabel "printSealedTrait" testPrintSealedTrait , TestLabel "printPackage" testPrintPackage , TestLabel "combineLines" testCombineLines + , TestLabel "printCaseClass" testPrintCaseClass , TestLabel "printScalaExpr" testPrintScalaExpr ] From 9f31cec826928629d33ec7e88404fe7b85a4c091 Mon Sep 17 00:00:00 2001 From: lemastero Date: Tue, 30 Apr 2024 17:17:45 +0200 Subject: [PATCH 3/3] change module name interpret as object name not package name - fix CI --- examples/adts.scala | 3 ++- src/Agda/Compiler/Scala/Backend.hs | 2 -- src/Agda/Compiler/Scala/PrintScalaExpr.hs | 6 +++--- test/PrintScalaExprTest.hs | 14 +++++++------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/adts.scala b/examples/adts.scala index d87c806..1fc04f2 100644 --- a/examples/adts.scala +++ b/examples/adts.scala @@ -1,4 +1,4 @@ -package adts +object adts { sealed trait Rgb case object Red extends Rgb @@ -12,3 +12,4 @@ case object False extends Bool def idRgb(x: Rgb): Rgb = x final case class RgbPair(snd: Bool, fst: Rgb) +} diff --git a/src/Agda/Compiler/Scala/Backend.hs b/src/Agda/Compiler/Scala/Backend.hs index f0e63b0..71908d3 100644 --- a/src/Agda/Compiler/Scala/Backend.hs +++ b/src/Agda/Compiler/Scala/Backend.hs @@ -131,8 +131,6 @@ scalaPostModule :: ScalaEnv scalaPostModule env modEnv isMain mName cdefs = do outDir <- compileDir compileLog $ "compiling " <> mkOutFile outDir - compileLog $ "scalaExprs " <> (show scalaExprs) - compileLog $ "fileContent " <> fileContent unless (all unHandled cdefs) $ liftIO $ writeFile (mkOutFile outDir) fileContent diff --git a/src/Agda/Compiler/Scala/PrintScalaExpr.hs b/src/Agda/Compiler/Scala/PrintScalaExpr.hs index bbee11b..8c5b60c 100644 --- a/src/Agda/Compiler/Scala/PrintScalaExpr.hs +++ b/src/Agda/Compiler/Scala/PrintScalaExpr.hs @@ -12,8 +12,8 @@ import Agda.Compiler.Scala.ScalaExpr ( ScalaName, ScalaExpr(..), SeVar(..)) printScalaExpr :: ScalaExpr -> String printScalaExpr def = case def of (SePackage pName defs) -> - (printPackage pName) <> defsSeparator - <> ( + (printPackage pName) <> exprSeparator -- TODO this should be package + object + <> bracket ( blankLine -- between package declaration and first definition <> combineLines (map printScalaExpr defs) ) @@ -54,7 +54,7 @@ printCaseObject superName caseName = "case object" <> exprSeparator <> caseName <> exprSeparator <> "extends" <> exprSeparator <> superName printPackage :: ScalaName -> String -printPackage pName = "package" <> exprSeparator <> pName +printPackage pName = "object" <> exprSeparator <> pName bracket :: String -> String bracket str = "{\n" <> str <> "\n}" diff --git a/test/PrintScalaExprTest.hs b/test/PrintScalaExprTest.hs index 4e117c0..5ff38c5 100644 --- a/test/PrintScalaExprTest.hs +++ b/test/PrintScalaExprTest.hs @@ -23,11 +23,11 @@ testPrintSealedTrait = TestCase "sealed trait Color" (printSealedTrait "Color")) -testPrintPackage :: Test -testPrintPackage = TestCase - (assertEqual "printPackage" - "package adts" - (printPackage "adts")) +--testPrintPackage :: Test +--testPrintPackage = TestCase +-- (assertEqual "printPackage" +-- "package adts" +-- (printPackage "adts")) testCombineLines :: Test testCombineLines = TestCase @@ -38,7 +38,7 @@ testCombineLines = TestCase testPrintScalaExpr :: Test testPrintScalaExpr = TestCase (assertEqual "printScalaExpr" (printScalaExpr $ SePackage "adts" moduleContent) - "package adts\n\nsealed trait Rgb\ncase object Red extends Rgb\ncase object Green extends Rgb\ncase object Blue extends Rgb\n\nsealed trait Color\ncase object Light extends Color\ncase object Dark extends Color\n" + "object adts {\n\nsealed trait Rgb\ncase object Red extends Rgb\ncase object Green extends Rgb\ncase object Blue extends Rgb\n\nsealed trait Color\ncase object Light extends Color\ncase object Dark extends Color\n}\n" ) where moduleContent = [rgbAdt, blank, blank, blank, colorAdt, blank, blank] @@ -57,7 +57,7 @@ printScalaTests :: Test printScalaTests = TestList [ TestLabel "printCaseObject" testPrintCaseObject , TestLabel "printSealedTrait" testPrintSealedTrait - , TestLabel "printPackage" testPrintPackage +-- , TestLabel "printPackage" testPrintPackage , TestLabel "combineLines" testCombineLines , TestLabel "printCaseClass" testPrintCaseClass , TestLabel "printScalaExpr" testPrintScalaExpr