Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 0e6fdf4

Browse files
authored
removed argonaut encode/decode, updated for PS@0.12 (#45)
1 parent 34d6fd9 commit 0e6fdf4

21 files changed

+73
-687
lines changed

bower.json

+8-12
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515
"package.json"
1616
],
1717
"dependencies": {
18-
"purescript-prelude": "^3.1.0",
19-
"purescript-matryoshka": "^0.3.0",
20-
"purescript-pathy": "^5.0.0",
21-
"purescript-profunctor": "^3.2.0",
22-
"purescript-profunctor-lenses": "^3.2.0",
23-
"purescript-ejson": "^10.0.1",
24-
"purescript-argonaut-codecs": "^3.1.0"
18+
"purescript-prelude": "^4.0.1",
19+
"purescript-matryoshka": "^0.4.0",
20+
"purescript-pathy": "^6.0.0",
21+
"purescript-profunctor-lenses": "^4.0.0",
22+
"purescript-ejson": "^11.0.0"
2523
},
2624
"devDependencies": {
27-
"purescript-argonaut": "^3.0.0",
28-
"purescript-debug": "^3.0.0",
29-
"purescript-quickcheck": "^4.4.0",
30-
"purescript-search": "^3.0.0",
31-
"purescript-test-unit": "^11.0.0"
25+
"purescript-quickcheck": "^5.0.0",
26+
"purescript-test-unit": "^14.0.0",
27+
"purescript-argonaut": "^4.0.1"
3228
}
3329
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"test": "pulp test"
66
},
77
"dependencies": {
8-
"pulp": "^11.0.0",
9-
"purescript": "^0.11.4",
10-
"purescript-psa": "^0.5.1"
8+
"pulp": "^12.2.0",
9+
"purescript": "^0.12.0",
10+
"purescript-psa": "^0.6.0"
1111
}
1212
}

src/SqlSquared.purs

+4-30
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ module SqlSquared
55
, print
66
, printQuery
77
, printModule
8-
, encodeJson
9-
, encodeJsonQuery
10-
, encodeJsonModule
11-
, decodeJson
12-
, decodeJsonQuery
13-
, decodeJsonModule
148
, genSql
159
, genSqlQuery
1610
, genSqlModule
@@ -24,16 +18,14 @@ import Prelude
2418

2519
import Control.Monad.Gen as Gen
2620
import Control.Monad.Rec.Class (class MonadRec)
27-
import Data.Argonaut as J
28-
import Data.Either (Either)
2921
import Data.Functor.Mu (Mu)
3022
import Data.Json.Extended as EJ
3123
import Data.Traversable (traverse)
3224
import Matryoshka (cata, anaM)
33-
import SqlSquared.Constructors as Constructors
34-
import SqlSquared.Lenses as Lenses
35-
import SqlSquared.Parser as Parser
36-
import SqlSquared.Signature as Sig
25+
import SqlSquared.Constructors (array, as, binop, bool, buildSelect, groupBy, having, hugeNum, ident, int, invokeFunction, let_, map_, match, null, num, pars, projection, select, set, splice, string, switch, then_, unop, vari, when) as Constructors
26+
import SqlSquared.Lenses (_ArrayLiteral, _Binop, _BoolLiteral, _Case, _DecimalLiteral, _ExprRelation, _GroupBy, _Ident, _IntLiteral, _InvokeFunction, _JoinRelation, _Let, _Literal, _MapLiteral, _Match, _NullLiteral, _OrderBy, _Parens, _Projection, _Select, _SetLiteral, _Splice, _StringLiteral, _Switch, _TableRelation, _Unop, _Vari, _VariRelation, _alias, _aliasName, _args, _bindTo, _cases, _clause, _cond, _else, _expr, _filter, _groupBy, _having, _ident, _in, _isDistinct, _joinType, _keys, _left, _lhs, _name, _op, _orderBy, _projections, _relations, _rhs, _right, _tablePath) as Lenses
27+
import SqlSquared.Parser (Literal(..), PositionedToken, Token(..), TokenStream, parse, parseModule, parseQuery, prettyParse, printToken, tokenize) as Parser
28+
import SqlSquared.Signature (type (×), BinaryOperator(..), BinopR, Case(..), ExprRelR, FunctionDeclR, GroupBy(..), InvokeFunctionR, JoinRelR, JoinType(..), LetR, MatchR, OrderBy(..), OrderType(..), Projection(..), Relation(..), SelectR, SqlDeclF(..), SqlF(..), SqlModuleF(..), SqlQueryF(..), SwitchR, TableRelR, UnaryOperator(..), UnopR, VariRelR, binopFromString, binopToString, genBinaryOperator, genCase, genGroupBy, genJoinType, genOrderBy, genOrderType, genProjection, genRelation, genSqlDeclF, genSqlF, genSqlModuleF, genSqlQueryF, genUnaryOperator, joinTypeFromString, orderTypeFromString, printBinaryOperator, printCase, printGroupBy, printIdent, printJoinType, printOrderBy, printOrderType, printProjection, printRelation, printSqlDeclF, printSqlF, printSqlModuleF, printSqlQueryF, printUnaryOperator, unopFromString, unopToString, (×), (∘), (⋙)) as Sig
3729

3830
type Sql = Mu (Sig.SqlF EJ.EJsonF)
3931

@@ -50,24 +42,6 @@ printQuery = Sig.printSqlQueryF <<< map print
5042
printModule SqlModule String
5143
printModule = Sig.printSqlModuleF <<< map print
5244

53-
encodeJson Sql J.Json
54-
encodeJson = cata $ Sig.encodeJsonSqlF EJ.encodeJsonEJsonF
55-
56-
encodeJsonQuery SqlQuery J.Json
57-
encodeJsonQuery = Sig.encodeJsonSqlQueryF <<< map encodeJson
58-
59-
encodeJsonModule SqlModule J.Json
60-
encodeJsonModule = Sig.encodeJsonSqlModuleF <<< map encodeJson
61-
62-
decodeJson J.Json Either String Sql
63-
decodeJson = anaM $ Sig.decodeJsonSqlF EJ.decodeJsonEJsonF
64-
65-
decodeJsonQuery J.Json Either String SqlQuery
66-
decodeJsonQuery = traverse decodeJson <=< Sig.decodeJsonSqlQueryF
67-
68-
decodeJsonModule J.Json Either String SqlModule
69-
decodeJsonModule = traverse decodeJson <=< Sig.decodeJsonSqlModuleF
70-
7145
genSql m. Gen.MonadGen m MonadRec m m Sql
7246
genSql = Gen.sized $ anaM (Sig.genSqlF EJ.arbitraryEJsonF)
7347

src/SqlSquared/Parser.purs

+8-10
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,24 @@ import Control.Lazy (defer)
1313
import Control.Monad.Error.Class (catchError)
1414
import Control.Monad.State (get, put)
1515
import Control.MonadZero (guard)
16-
1716
import Data.Array as A
1817
import Data.Bifunctor (lmap)
1918
import Data.Either as E
2019
import Data.Foldable as F
20+
import Data.Json.Extended as EJ
2121
import Data.List ((:))
2222
import Data.List as L
2323
import Data.Maybe (Maybe(..), fromMaybe, isJust)
2424
import Data.NonEmpty ((:|))
25-
import Data.Json.Extended as EJ
26-
import Data.Tuple (Tuple(..), uncurry)
27-
import SqlSquared.Path as Pt
2825
import Data.String as S
29-
26+
import Data.String.CodeUnits as SCU
27+
import Data.Tuple (Tuple(..), uncurry)
28+
import Matryoshka (class Corecursive, embed)
3029
import SqlSquared.Constructors as C
3130
import SqlSquared.Parser.Tokenizer (Token(..), TokenStream, PositionedToken, tokenize, Literal(..), printToken)
31+
import SqlSquared.Path as Pt
3232
import SqlSquared.Signature as Sig
3333
import SqlSquared.Utils ((∘), type (×), (×))
34-
import Matryoshka (class Corecursive, embed)
35-
3634
import Text.Parsing.Parser as P
3735
import Text.Parsing.Parser.Combinators as PC
3836
import Text.Parsing.Parser.Pos as PP
@@ -75,7 +73,7 @@ prettyParse parser input =
7573
lmap printError (parser input)
7674
where
7775
padLeft n s =
78-
S.fromCharArray (A.replicate (n - S.length s) ' ') <> s
76+
SCU.fromCharArray (A.replicate (n - S.length s) ' ') <> s
7977

8078
printError parseError =
8179
let
@@ -86,7 +84,7 @@ prettyParse parser input =
8684
line = A.take 1 $ A.drop (pos.line - 1) lines
8785
post = A.take 3 $ A.drop pos.line lines
8886
nums = A.mapWithIndex (\n l → padLeft 4 (show (n + pos.line - (A.length pre))) <> " | " <> l) (pre <> line <> post)
89-
pointer = pure $ S.fromCharArray (A.replicate (pos.column - 1 + 7) '-') <> "^ " <> message
87+
pointer = pure $ SCU.fromCharArray (A.replicate (pos.column - 1 + 7) '-') <> "^ " <> message
9088
in
9189
S.joinWith "\n" $ A.take (A.length pre + 1) nums <> pointer <> A.drop 3 nums
9290

@@ -471,7 +469,7 @@ negatableSuffix = do
471469
n ← PC.optionMaybe $ keyword "not"
472470
pure $ isJust n
473471
suffix ← betweenSuffix <|> inSuffix <|> likeSuffix
474-
pure \e → (if inv then _NOT else id) $ suffix e
472+
pure \e → (if inv then _NOT else identity) $ suffix e
475473

476474
betweenSuffix m t. SqlParser m t (t t)
477475
betweenSuffix = do

src/SqlSquared/Parser/Tokenizer.purs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import Data.Int as Int
2121
import Data.Json.Extended.Signature.Parse as EJP
2222
import Data.Maybe (Maybe(..))
2323
import Data.Set as Set
24-
import Data.String as S
24+
import Data.String (length, toUpper, toLower) as S
25+
import Data.String.CodeUnits (fromCharArray, drop, singleton) as S
2526
import Data.Traversable (sequence)
2627
import SqlSquared.Utils ((∘))
2728
import Text.Parsing.Parser as P
@@ -259,9 +260,9 @@ charLit = PS.char '\'' *> charAtom <* PS.char '\''
259260

260261
hexEscape = do
261262
hex ← S.fromCharArray <$> sequence (A.replicate 4 PT.hexDigit)
262-
case Int.fromStringAs Int.hexadecimal hex of
263+
case Int.fromStringAs Int.hexadecimal hex >>= Char.fromCharCode of
263264
NothingP.fail "Expected character escape sequence"
264-
Just i → pure $ Char.fromCharCode i
265+
Just i → pure i
265266

266267
positioned m. Monad m P.ParserT String m Token P.ParserT String m PositionedToken
267268
positioned m = do

0 commit comments

Comments
 (0)