Skip to content

Commit

Permalink
scala, no scala.language.higherKinds import
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmius committed Feb 9, 2024
1 parent 156e33f commit 681524b
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 30 deletions.
7 changes: 7 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changes
=======

Version 0.5.2.0
---------------

* Scala target now recognises ``--no-higher-kinds-import``.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ https://bitbucket.org/Cosmius/gugugu/downloads/

installation
syntax
changes

Targets
-------
Expand Down
33 changes: 19 additions & 14 deletions docs/lang/scala.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Quick Start
--with-codec \
--with-server \
--with-client \
--no-higher-kinds-import \
;


Expand Down Expand Up @@ -452,40 +453,44 @@ Command Line Options
Usage: gugugu-scala (-i|--input INPUT) (-o|--output OUTPUT)
(-p|--package-prefix PACKAGE_PREFIX)
[-r|--runtime-package RUNTIME_PACKAGE] [--with-codec]
[--with-server] [--with-client] [--trans-module-code ARG]
[--trans-module-value ARG] [--trans-module-type ARG]
[--trans-func-code ARG] [--trans-func-value ARG]
[--trans-type-code ARG] [--trans-type-func ARG]
[--trans-field-code ARG] [--trans-field-value ARG]
[--trans-enum-code ARG] [--trans-enum-value ARG] [--version]
[--with-server] [--with-client] [--no-higher-kinds-import]
[--trans-module-code ARG] [--trans-module-value ARG]
[--trans-module-type ARG] [--trans-func-code ARG]
[--trans-func-value ARG] [--trans-type-code ARG]
[--trans-type-func ARG] [--trans-field-code ARG]
[--trans-field-value ARG] [--trans-enum-code ARG]
[--trans-enum-value ARG] [--version]

Available options:
-i,--input INPUT the directory containing the definition files
-o,--output OUTPUT the directory to put the generated sources
-p,--package-prefix PACKAGE_PREFIX
the package prefix, e.g. com.example.foo.generated
-r,--runtime-package RUNTIME_PACKAGE
location of gugugu runtime
package (default: "gugugu.lang.scala.runtime")
location of gugugu runtime package
(default: "gugugu.lang.scala.runtime")
--with-codec pass this flag to generate codecs, default to false
--with-server pass this flag to generate server, default to false,
implies with-codec
--with-client pass this flag to generate client, default to false,
implies with-codec
--no-higher-kinds-import pass this flag to disable import
scala.language.higherKinds, which is not necessary in
scala 2.13+
--trans-module-code ARG module name transformer for code (default: lower)
--trans-module-value ARG module name transformer for value (default: snake)
--trans-module-type ARG module name transformer for type of
client/server (default: id)
--trans-module-type ARG module name transformer for type of client/server
(default: id)
--trans-func-code ARG function name transformer for code (default: id)
--trans-func-value ARG function name transformer for value (default: snake)
--trans-type-code ARG type name transformer for code (default: id)
--trans-type-func ARG type name transformer in function (default: id)
--trans-field-code ARG record field name transformer for code (default: id)
--trans-field-value ARG record field name transformer for
value (default: snake)
--trans-field-value ARG record field name transformer for value
(default: snake)
--trans-enum-code ARG enum name transformer for code (default: id)
--trans-enum-value ARG enum name transformer for
value (default: upper-snake)
--trans-enum-value ARG enum name transformer for value
(default: upper-snake)
-h,--help Show this help text
--help-transformers list available name transformers
--version show version
1 change: 1 addition & 0 deletions examples/lang/scala/run-gugugu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ gugugu-scala \
--with-codec \
--with-server \
--with-client \
--no-higher-kinds-import \
--package-prefix=guguguexamples.definitions \
;
2 changes: 1 addition & 1 deletion hpack-common.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- &toplevel
version: 0.5.1.0
version: 0.5.2.0
license: BSD3
author: Cosmia Fu
copyright: 2019 Cosmia Fu
2 changes: 0 additions & 2 deletions lang/scala/runtime/client/ClientTransport.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import scala.language.higherKinds

trait ClientTransport[F[_], G[_], M[_], RA, RB] {
def send[A, B]( name: QualName[String]
, fa: F[A]
Expand Down
2 changes: 0 additions & 2 deletions lang/scala/runtime/server/ServerCodecHandler.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import scala.language.higherKinds

trait ServerCodecHandler[F[_], G[_], M[_], RA, RB] {
def apply[A, B]( fr: F[RA]
, decodeA: RA => A
Expand Down
2 changes: 0 additions & 2 deletions lang/scala/runtime/server/ServerTransport.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import scala.language.higherKinds

trait ServerTransport[F[_], G[_], M[_], RA, RB] {
def ask( name: QualName[String]
, codecHandler: ServerCodecHandler[F, G, M, RA, RB]
Expand Down
22 changes: 15 additions & 7 deletions lang/scala/src/Gugugu/Lang/Scala.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ import Gugugu.Lang.Scala.SourceUtils
-- | Option for 'makeFiles'
data GuguguScalaOption
= GuguguScalaOption
{ packagePrefix :: [Text] -- ^ Package prefix
, runtimePkg :: [Text] -- ^ Gugugu runtime package
, withCodec :: Bool -- ^ True if generate codec
, withServer :: Bool -- ^ True if generate server
, withClient :: Bool -- ^ True if generate client
, nameTransformers :: GuguguNameTransformers -- ^ Name transformers
{ packagePrefix :: [Text]
-- ^ Package prefix
, runtimePkg :: [Text]
-- ^ Gugugu runtime package
, withCodec :: Bool
-- ^ True if generate codec
, withServer :: Bool
-- ^ True if generate server
, withClient :: Bool
-- ^ True if generate client
, noHigherKindsImport :: Bool
-- ^ False if import scala.language.higherKinds
, nameTransformers :: GuguguNameTransformers -- ^ Name transformers
}
deriving Show

Expand Down Expand Up @@ -447,7 +454,8 @@ makeTransport md@Module{..} = do
traitName <- mkModuleType md
let compilationUnit = CompilationUnit
{ cuPackage = QualId moduleCode
, cuPkgImports = [(QualId ("scala" :| ["language"]), ["higherKinds"])]
, cuPkgImports = if noHigherKindsImport then []
else [(QualId ("scala" :| ["language"]), ["higherKinds"])]
, cuTopStats = [TST traitDef, TSO objectDef]
}
path = pkgDir moduleCode </> (T.unpack traitName <> ".scala")
Expand Down
12 changes: 10 additions & 2 deletions lang/scala/src/Gugugu/Lang/Scala/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ guguguScalaMain = runExceptIO $ do
writeRuntimeFiles "codec" codecFiles
when (withClient opts || withServer opts) $ do
let transportFiles = transportCommonFiles
<> (if withServer opts then serverFiles else [])
<> (if withClient opts then clientFiles else [])
<> (if withServer opts then insertHigherKinds serverFiles else [])
<> (if withClient opts then insertHigherKinds clientFiles else [])
higherKindsImport = "import scala.language.higherKinds\n\n"
insertHigherKinds = if noHigherKindsImport opts then id else fmap $
\(name, content) -> (name, higherKindsImport <> content)
writeRuntimeFiles "transport" transportFiles
for_ (Map.toList fs) $ \(p, sf) ->
writeSrcCompToFile (outputDir </> p) sf
Expand All @@ -76,6 +79,11 @@ optParser = do
, help "location of gugugu runtime package"
]
~(withCodec, withServer, withClient) <- pWithCodecServerClient
noHigherKindsImport <- switch $ fold
[ long "no-higher-kinds-import"
, help
"pass this flag to disable import scala.language.higherKinds, which is not necessary in scala 2.13+"
]
nameTransformers <- guguguNameTransformers GuguguNameTransformers
{ transModuleCode = ToLower
, transModuleValue = ToSnake
Expand Down

0 comments on commit 681524b

Please sign in to comment.