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

Commit 488cc6e

Browse files
authored
Merge pull request #20 from garyb/ejson-bump
Update for Int -> HugeInt change in EJson
2 parents 8e7c8f8 + c0a6d28 commit 488cc6e

19 files changed

+38
-152
lines changed

bower.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
"package.json"
1616
],
1717
"dependencies": {
18-
"purescript-prelude": "^3.0.0",
18+
"purescript-prelude": "^3.1.0",
1919
"purescript-matryoshka": "^0.3.0",
2020
"purescript-pathy": "^4.0.0",
21-
"purescript-profunctor": "^3.0.0",
21+
"purescript-profunctor": "^3.2.0",
2222
"purescript-profunctor-lenses": "^3.2.0",
23-
"purescript-ejson": "^9.0.0",
24-
"purescript-argonaut-codecs": "^3.0.1"
23+
"purescript-ejson": "^10.0.0",
24+
"purescript-argonaut-codecs": "^3.1.0",
25+
"purescript-strongcheck": "^3.1.0"
2526
},
2627
"devDependencies": {
2728
"purescript-argonaut": "^3.0.0",
File renamed without changes.

src/SqlSquare/Constructors.purs renamed to src/SqlSquared/Constructors.purs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ module SqlSquared.Constructors where
33
import Prelude
44

55
import Data.Array as Arr
6-
import Data.Json.Extended.Signature (EJsonF(..), EJsonMap(..))
76
import Data.Foldable as F
7+
import Data.HugeInt as HI
88
import Data.HugeNum as HN
9+
import Data.Json.Extended.Signature (EJsonF(..), EJsonMap(..))
910
import Data.List as L
1011
import Data.Map as Map
1112
import Data.Maybe (Maybe(..))
12-
1313
import Matryoshka (class Corecursive, embed)
14-
1514
import SqlSquared.Signature as Sig
1615
import SqlSquared.Utils ((∘))
1716

@@ -25,7 +24,7 @@ null ∷ ∀ t. Corecursive t (Sig.SqlF EJsonF) ⇒ t
2524
null = embed $ Sig.Literal Null
2625

2726
int t. Corecursive t (Sig.SqlF EJsonF) Int t
28-
int = embed ∘ Sig.LiteralInteger
27+
int = embed ∘ Sig.LiteralIntegerHI.fromInt
2928

3029
num t. Corecursive t (Sig.SqlF EJsonF) Number t
3130
num = embed ∘ Sig.LiteralDecimalHN.fromNumber

src/SqlSquare/Lenses.purs renamed to src/SqlSquared/Lenses.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module SqlSquared.Lenses where
22

33
import Prelude
44

5+
import Data.HugeInt as HI
56
import Data.HugeNum as HN
67
import Data.Json.Extended as EJ
78
import Data.Lens (Prism', prism', Lens', lens, Iso')
@@ -241,7 +242,7 @@ _IntLiteral
241242
t
242243
. Recursive t (S.SqlF EJ.EJsonF)
243244
Corecursive t (S.SqlF EJ.EJsonF)
244-
Prism' t Int
245+
Prism' t HI.HugeInt
245246
_IntLiteral = prism' (embed ∘ S.LiteralEJ.Integer) $ project ⋙ case _ of
246247
S.Literal (EJ.Integer r) → M.Just r
247248
_ → M.Nothing
File renamed without changes.

src/SqlSquare/Parser/Tokenizer.purs renamed to src/SqlSquared/Parser/Tokenizer.purs

Lines changed: 9 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@ module SqlSquared.Parser.Tokenizer
77
import Prelude
88

99
import Control.Alt ((<|>))
10-
1110
import Data.Array as A
12-
import Data.Int as Int
11+
import Data.Char as Ch
1312
import Data.Either (Either)
14-
import Data.Maybe (Maybe(..), isJust)
15-
import Data.Foldable as F
13+
import Data.HugeInt as HI
1614
import Data.HugeNum as HN
17-
import Data.Char as Ch
15+
import Data.Json.Extended.Signature.Parse as EJP
16+
import Data.Maybe (isJust)
1817
import Data.String as S
19-
2018
import SqlSquared.Utils ((∘))
21-
2219
import Text.Parsing.Parser as P
2320
import Text.Parsing.Parser.Combinators as PC
24-
import Text.Parsing.Parser.Token as PT
2521
import Text.Parsing.Parser.String as PS
22+
import Text.Parsing.Parser.Token as PT
2623

2724
data Literal
2825
= String String
29-
| Integer Int
26+
| Integer HI.HugeInt
3027
| Decimal HN.HugeNum
3128

3229
derive instance eqTokenLitEq Literal
@@ -202,121 +199,13 @@ notQuotedIdent = do
202199
else pure str
203200

204201
stringLit m. Monad m P.ParserT String m Token
205-
stringLit =
206-
map (LitString)
207-
$ PC.between (PS.string "\"") (PS.string "\"")
208-
$ map S.fromCharArray
209-
$ A.many stringChar
210-
where
211-
stringChar = PC.try stringEscape <|> stringLetter
212-
stringLetter = PS.satisfy (not ∘ eq '"')
213-
stringEscape = PS.string "\\\"" $> '"'
202+
stringLit = LitString <$> EJP.parseStringLiteral
214203

215204
numLit m. Monad m P.ParserT String m Token
216-
numLit = map (LitDecimal) parseDecimal
205+
numLit = LitDecimal <$> EJP.parseDecimalLiteral
217206

218207
intLit m. Monad m P.ParserT String m Token
219-
intLit = map (LitInteger) parseIntLiteral
220-
221-
parseIntLiteral m. Monad m P.ParserT String m Int
222-
parseIntLiteral = parseSigned parseNat
223-
224-
parseDecimal m. Monad m P.ParserT String m HN.HugeNum
225-
parseDecimal = parseHugeNum <|> parseScientific
226-
227-
parseHugeNum m. Monad m P.ParserT String m HN.HugeNum
228-
parseHugeNum = do
229-
chars ←
230-
map S.fromCharArray
231-
$ A.many
232-
$ PS.oneOf
233-
$ digits
234-
<> [ '-', '.' ]
235-
case HN.fromString chars of
236-
Just num → pure num
237-
NothingP.fail $ "Failed to parse decimal: " <> chars
238-
239-
parseDigit m. Monad m P.ParserT String m Int
240-
parseDigit =
241-
PC.choice
242-
[ 0 <$ PS.string "0"
243-
, 1 <$ PS.string "1"
244-
, 2 <$ PS.string "2"
245-
, 3 <$ PS.string "3"
246-
, 4 <$ PS.string "4"
247-
, 5 <$ PS.string "5"
248-
, 6 <$ PS.string "6"
249-
, 7 <$ PS.string "7"
250-
, 8 <$ PS.string "8"
251-
, 9 <$ PS.string "9"
252-
]
253-
254-
parseScientific m. Monad m P.ParserT String m HN.HugeNum
255-
parseScientific =
256-
parseSigned parsePositiveScientific
257-
258-
parseNat
259-
m
260-
. Monad m
261-
P.ParserT String m Int
262-
parseNat =
263-
A.some parseDigit
264-
<#> F.foldl (\a i → a * 10 + i) 0
265-
266-
parseNegative
267-
m a
268-
. Monad m
269-
Ring a
270-
P.ParserT String m a
271-
P.ParserT String m a
272-
parseNegative p =
273-
PS.string "-"
274-
*> PS.skipSpaces
275-
*> p
276-
<#> negate
277-
278-
parsePositive
279-
m a
280-
. Monad m
281-
Ring a
282-
P.ParserT String m a
283-
P.ParserT String m a
284-
parsePositive p =
285-
PC.optional (PS.string "+" *> PS.skipSpaces)
286-
*> p
287-
288-
parseSigned
289-
m a
290-
. Monad m
291-
Ring a
292-
P.ParserT String m a
293-
P.ParserT String m a
294-
parseSigned p = parseNegative p <|> parsePositive p
295-
296-
parseExponent
297-
m
298-
. Monad m
299-
P.ParserT String m Int
300-
parseExponent =
301-
(PS.string "e" <|> PS.string "E")
302-
*> parseIntLiteral
303-
304-
parsePositiveScientific m. Monad m P.ParserT String m HN.HugeNum
305-
parsePositiveScientific = do
306-
let ten = HN.fromNumber 10.0
307-
lhs ← PC.try $ fromInt <$> parseNat <* PS.string "."
308-
rhs ← A.many parseDigit <#> F.foldr (\d f → divNum (f + fromInt d) ten) zero
309-
exp ← parseExponent
310-
pure $ (lhs + rhs) * HN.pow ten exp
311-
312-
where
313-
fromInt = HN.fromNumber <<< Int.toNumber
314-
315-
-- TODO: remove when HugeNum adds division
316-
divNum a b =
317-
HN.fromNumber $
318-
HN.toNumber a / HN.toNumber b
319-
208+
intLit = LitInteger <$> EJP.parseHugeIntLiteral
320209

321210
keyword m. Monad m P.ParserT String m Token
322211
keyword = map Kw $ PC.choice $ map (PC.try ∘ parseKeyWord) keywords
@@ -329,7 +218,6 @@ parseKeyWord s =
329218
c ← PC.try $ PS.oneOf [ Ch.toUpper ch, Ch.toLower ch ]
330219
pure $ A.snoc acc c
331220

332-
333221
tokens m. Monad m P.ParserT String m (Array Token)
334222
tokens = do
335223
PS.skipSpaces

src/SqlSquare/Signature.purs renamed to src/SqlSquared/Signature.purs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,38 @@ module SqlSquared.Signature
4343

4444
import Prelude
4545

46+
import Control.Monad.Gen as MGen
4647
import Data.Argonaut as J
4748
import Data.Array as A
4849
import Data.Either as E
4950
import Data.Eq (class Eq1, eq1)
5051
import Data.Foldable as F
51-
import Data.Json.Extended as EJ
52+
import Data.HugeInt as HI
53+
import Data.HugeNum as HN
5254
import Data.Int as Int
53-
import Data.List as L
55+
import Data.Json.Extended as EJ
5456
import Data.List ((:))
55-
import Data.HugeNum as HN
57+
import Data.List as L
5658
import Data.Maybe (Maybe(..))
5759
import Data.Monoid (mempty)
5860
import Data.Newtype (class Newtype)
61+
import Data.NonEmpty ((:|))
5962
import Data.Ord (class Ord1, compare1)
6063
import Data.String as S
64+
import Data.String.Gen as GenS
6165
import Data.Traversable as T
62-
6366
import Matryoshka (Algebra, CoalgebraM, class Corecursive, embed)
64-
65-
import SqlSquared.Utils (type (×), (×), (∘), (⋙))
66-
6767
import SqlSquared.Signature.BinaryOperator as BO
6868
import SqlSquared.Signature.Case as CS
6969
import SqlSquared.Signature.GroupBy as GB
70+
import SqlSquared.Signature.Ident as ID
7071
import SqlSquared.Signature.JoinType as JT
7172
import SqlSquared.Signature.OrderBy as OB
7273
import SqlSquared.Signature.OrderType as OT
7374
import SqlSquared.Signature.Projection as PR
7475
import SqlSquared.Signature.Relation as RL
7576
import SqlSquared.Signature.UnaryOperator as UO
76-
import SqlSquared.Signature.Ident as ID
77-
77+
import SqlSquared.Utils (type (×), (×), (∘), (⋙))
7878
import Test.StrongCheck.Arbitrary as SC
7979
import Test.StrongCheck.Gen as Gen
8080

@@ -915,11 +915,11 @@ genSql n
915915
genLeaf t. GenSql t
916916
genLeaf =
917917
map (embed ∘ Literal)
918-
$ Gen.oneOf (pure $ EJ.Null)
919-
[ map EJ.Boolean SC.arbitrary
920-
, map EJ.Integer SC.arbitrary
921-
, map EJ.Decimal $ map HN.fromNumber SC.arbitrary
922-
, map EJ.String SC.arbitrary
918+
$ MGen.oneOf $ pure EJ.Null :|
919+
[ EJ.Boolean <$> MGen.chooseBool
920+
, EJ.Integer <<< HI.fromInt <$> MGen.chooseInt (-1000000) 1000000
921+
, EJ.Decimal <<< HN.fromNumber <$> MGen.chooseFloat (-1000000.0) 1000000.0
922+
, EJ.String <$> GenS.genUnicodeString
923923
]
924924

925925
genLetP t. Int GenSql t
File renamed without changes.

test/src/Argonaut.purs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,26 @@ import Data.Argonaut (JCursor(..), jsonParser)
88
import Data.Argonaut as JS
99
import Data.Either (fromRight)
1010
import Data.Foldable as F
11+
import Data.HugeInt as HI
12+
import Data.Json.Extended.Signature (EJsonF(..))
1113
import Data.List ((:))
1214
import Data.List as L
1315
import Data.Maybe (Maybe(..))
1416
import Data.Set as Set
1517
import Data.Tuple (Tuple, fst)
16-
import Data.Json.Extended.Signature (EJsonF(..))
17-
18+
import Matryoshka (ana, elgotPara, Coalgebra, ElgotAlgebra)
19+
import Partial.Unsafe (unsafePartial)
1820
import SqlSquared as S
1921
import SqlSquared.Utils ((×), (∘), (⋙))
20-
21-
import Matryoshka (ana, elgotPara, Coalgebra, ElgotAlgebra)
22-
2322
import Test.Unit (suite, test, TestSuite)
2423
import Test.Unit.Assert as Assert
2524

26-
import Partial.Unsafe (unsafePartial)
27-
2825
data UnfoldableJC = JC JCursor | S String | I Int
2926

3027
jcCoalgebra Coalgebra (S.SqlF EJsonF) UnfoldableJC
3128
jcCoalgebra = case _ of
3229
S s → S.Ident s
33-
I i → S.Literal (Integer i)
30+
I i → S.Literal (Integer (HI.fromInt i))
3431
JC cursor → case cursor of
3532
JCursorTopS.Splice Nothing
3633
JIndex i c → S.Binop { op: S.IndexDeref, lhs: JC c, rhs: I i }

0 commit comments

Comments
 (0)