-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from ccap/next
Code gen overhaul
- Loading branch information
Showing
54 changed files
with
4,187 additions
and
1,781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
/test/generated/* | ||
package-lock.json | ||
yarn.lock | ||
.metals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
trailingComma: es5 | ||
bracketSpacing: true | ||
tabWidth: 2 | ||
singleQuote: true | ||
insertPragma: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,52 @@ | ||
|
||
|
||
let upstream = | ||
https://github.com/purescript/package-sets/releases/download/psc-0.13.5-20191215/packages.dhall sha256:fdc5d54cd54213000100fbc13c90dce01668a73fe528d8662430558df3411bee | ||
https://github.com/purescript/package-sets/releases/download/psc-0.13.8/packages.dhall sha256:0e95ec11604dc8afc1b129c4d405dcc17290ce56d7d0665a0ff15617e32bbf03 | ||
|
||
let overrides = {=} | ||
|
||
let additions = | ||
{ boxes = | ||
{ dependencies = | ||
[ "profunctor" | ||
, "prelude" | ||
, "stringutils" | ||
, "generics-rep" | ||
, "strings" | ||
] | ||
, repo = "https://github.com/cdepillabout/purescript-boxes.git" | ||
, version = "v2.0.1" | ||
} | ||
, postgresql-client = | ||
{ dependencies = | ||
[ "aff" | ||
, "argonaut" | ||
, "arrays" | ||
, "assert" | ||
, "bifunctors" | ||
, "bytestrings" | ||
, "console" | ||
, "datetime" | ||
, "decimals" | ||
, "effect" | ||
, "either" | ||
, "exceptions" | ||
, "foldable-traversable" | ||
, "foreign" | ||
, "foreign-generic" | ||
, "foreign-object" | ||
, "js-date" | ||
, "lists" | ||
, "maybe" | ||
, "newtype" | ||
, "nullable" | ||
, "prelude" | ||
, "psci-support" | ||
, "test-unit" | ||
, "transformers" | ||
, "tuples" | ||
] | ||
, repo = "https://github.com/pbrant/purescript-postgresql-client.git" | ||
, version = "7188cd732eb7981910915fb5e8ab8b158abda95b" -- #update-dependencies | ||
} | ||
} | ||
{ boxes = | ||
{ dependencies = | ||
[ "profunctor" | ||
, "prelude" | ||
, "stringutils" | ||
, "generics-rep" | ||
, "strings" | ||
] | ||
, repo = "https://github.com/cdepillabout/purescript-boxes.git" | ||
, version = "v2.0.1" | ||
} | ||
, postgresql-client = | ||
{ dependencies = | ||
[ "aff" | ||
, "argonaut" | ||
, "arrays" | ||
, "assert" | ||
, "bifunctors" | ||
, "bytestrings" | ||
, "console" | ||
, "datetime" | ||
, "decimals" | ||
, "effect" | ||
, "either" | ||
, "exceptions" | ||
, "foldable-traversable" | ||
, "foreign" | ||
, "foreign-generic" | ||
, "foreign-object" | ||
, "js-date" | ||
, "lists" | ||
, "maybe" | ||
, "newtype" | ||
, "nullable" | ||
, "prelude" | ||
, "psci-support" | ||
, "test-unit" | ||
, "transformers" | ||
, "tuples" | ||
] | ||
, repo = "https://github.com/pbrant/purescript-postgresql-client.git" | ||
, version = "7188cd732eb7981910915fb5e8ab8b158abda95b" | ||
} | ||
} | ||
|
||
in upstream // overrides // additions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
scala: test.Cycle1 | ||
purs: Test.Cycle1 | ||
|
||
import Cycle2 | ||
|
||
type X: Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
scala: test.Cycle2 | ||
purs: Test.Cycle2 | ||
|
||
import Cycle3 | ||
|
||
type X: Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
scala: test.Cycle3 | ||
purs: Test.Cycle3 | ||
|
||
import Cycle1 | ||
|
||
type X: Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
scala: test.Imported | ||
purs: Test.Imported | ||
|
||
type X: Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
scala: test.TypeErrors | ||
purs: Test.TypeErrors | ||
|
||
import Imported | ||
|
||
type Dup1: Int | ||
type Dup1: String | ||
|
||
type Rec: { | ||
dup1: Int | ||
dup1: String | ||
} | ||
|
||
type Sum: [ | ||
| Dup1 | ||
| Dup1 | ||
] | ||
|
||
type X: Y | ||
type Z: Imported.Q | ||
type Q: Bar.M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
module Ccap.Codegen.Ast | ||
( Constructor(..) | ||
, Module(..) | ||
, RecordProp(..) | ||
, ScalaDecoderType(..) | ||
, TRef | ||
, TopType(..) | ||
, Type(..) | ||
, TypeDecl(..) | ||
, TypeOrParam(..) | ||
, isRecord | ||
, noArgConstructorNames | ||
, typeDeclName | ||
, typeDeclTopType | ||
) where | ||
|
||
import Prelude | ||
import Ccap.Codegen.Cst as Cst | ||
import Data.Array.NonEmpty (NonEmptyArray) | ||
import Data.Generic.Rep (class Generic) | ||
import Data.Generic.Rep.Show (genericShow) | ||
import Data.Maybe (Maybe(..)) | ||
import Data.Traversable (traverse) | ||
import Data.Tuple (Tuple) | ||
|
||
newtype Module | ||
= Module | ||
{ types :: NonEmptyArray TypeDecl | ||
, imports :: Array Module | ||
, exports :: Cst.Exports | ||
, name :: Cst.ModuleName | ||
} | ||
|
||
newtype TypeDecl | ||
= TypeDecl | ||
{ name :: String | ||
, topType :: TopType | ||
, annots :: Array Cst.Annotation | ||
, isPrimary :: Boolean | ||
, params :: Array Cst.TypeParam | ||
, scalaDecoderType :: Maybe ScalaDecoderType | ||
} | ||
|
||
data TopType | ||
= Type Type | ||
| Wrap Type | ||
| Record (NonEmptyArray RecordProp) | ||
| Sum (NonEmptyArray Constructor) | ||
|
||
data Type | ||
= Primitive Cst.Primitive | ||
| Ref TRef | ||
| Array TypeOrParam | ||
| Option TypeOrParam | ||
|
||
data TypeOrParam | ||
= TType Type | ||
| TParam Cst.TypeParam | ||
|
||
type TRef | ||
= { decl :: Maybe (Tuple Module TypeDecl) | ||
, typ :: String | ||
, params :: Array TypeOrParam | ||
, isPrimaryRef :: Boolean | ||
} | ||
|
||
type RecordProp | ||
= { name :: String | ||
, typ :: TypeOrParam | ||
, annots :: Array Cst.Annotation | ||
} | ||
|
||
data Constructor | ||
= NoArg Cst.ConstructorName | ||
| WithArgs Cst.ConstructorName (NonEmptyArray TypeOrParam) | ||
|
||
isRecord :: TopType -> Boolean | ||
isRecord = case _ of | ||
Record _ -> true | ||
_ -> false | ||
|
||
-- | Get the type name of a type declaration. | ||
typeDeclName :: TypeDecl -> String | ||
typeDeclName (TypeDecl { name }) = name | ||
|
||
-- | Get the top most type of a type declaration. | ||
typeDeclTopType :: TypeDecl -> TopType | ||
typeDeclTopType (TypeDecl { topType }) = topType | ||
|
||
noArgConstructorNames :: NonEmptyArray Constructor -> Maybe (NonEmptyArray String) | ||
noArgConstructorNames = | ||
traverse | ||
( case _ of | ||
NoArg (Cst.ConstructorName n) -> Just n | ||
WithArgs _ _ -> Nothing | ||
) | ||
|
||
data ScalaDecoderType | ||
= Field | ||
| Form | ||
|
||
-- Instances here to avoid cluttering the above | ||
derive instance eqScalaDecoderType :: Eq ScalaDecoderType | ||
|
||
derive instance genericScalaDecoderType :: Generic ScalaDecoderType _ | ||
|
||
instance showScalaDecoderType :: Show ScalaDecoderType where | ||
show t = genericShow t | ||
|
||
derive instance eqModule :: Eq Module | ||
|
||
derive instance genericModule :: Generic Module _ | ||
|
||
instance showModule :: Show Module where | ||
show t = genericShow t | ||
|
||
derive instance eqTypeOrParam :: Eq TypeOrParam | ||
|
||
derive instance genericTypeOrParam :: Generic TypeOrParam _ | ||
|
||
instance showTypeOrParam :: Show TypeOrParam where | ||
show t = genericShow t | ||
|
||
derive instance eqConstructor :: Eq Constructor | ||
|
||
derive instance genericConstructor :: Generic Constructor _ | ||
|
||
instance showConstructor :: Show Constructor where | ||
show t = genericShow t | ||
|
||
derive instance eqType :: Eq Type | ||
|
||
derive instance genericType :: Generic Type _ | ||
|
||
instance showType :: Show Type where | ||
show t = genericShow t | ||
|
||
derive instance eqTopType :: Eq TopType | ||
|
||
derive instance genericTopType :: Generic TopType _ | ||
|
||
instance showTopType :: Show TopType where | ||
show = genericShow | ||
|
||
derive instance eqTypeDecl :: Eq TypeDecl | ||
|
||
derive instance genericTypeDecl :: Generic TypeDecl _ | ||
|
||
instance showTypeDecl :: Show TypeDecl where | ||
show = genericShow |
Oops, something went wrong.