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

Commit 8f6f82b

Browse files
committed
Updates for 0.12
1 parent 1a7e40c commit 8f6f82b

File tree

13 files changed

+84
-86
lines changed

13 files changed

+84
-86
lines changed

bower.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
"package.json"
2323
],
2424
"dependencies": {
25-
"purescript-const": "^3.0.0",
26-
"purescript-functors": "^2.0.0",
27-
"purescript-lists": "^4.0.0",
28-
"purescript-parsing": "^4.0.0",
29-
"purescript-partial": "^1.2.0",
30-
"purescript-precise": "^2.0.0",
31-
"purescript-prelude": "^3.0.0",
32-
"purescript-sets": "^3.0.0",
33-
"purescript-strings": "^3.0.0",
34-
"purescript-strongcheck": "^3.0.0",
35-
"purescript-unicode": "^3.0.1",
36-
"purescript-validation": "^3.0.0",
37-
"purescript-datetime": "^3.0.0"
25+
"purescript-const": "^4.0.0",
26+
"purescript-datetime": "^4.0.0",
27+
"purescript-decimals": "^4.0.0",
28+
"purescript-functors": "^3.0.0",
29+
"purescript-lists": "^5.0.0",
30+
"purescript-ordered-collections": "^1.0.0",
31+
"purescript-parsing": "^5.0.1",
32+
"purescript-partial": "^2.0.0",
33+
"purescript-prelude": "^4.0.1",
34+
"purescript-strings": "^4.0.0",
35+
"purescript-strongcheck": "^4.1.1",
36+
"purescript-unicode": "^4.0.1",
37+
"purescript-validation": "^4.0.0"
3838
}
3939
}

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
"build": "pulp build -- --censor-lib --strict",
66
"test": "pulp test"
77
},
8+
"dependencies": {
9+
"decimal.js": "7.1.1"
10+
},
811
"devDependencies": {
9-
"pulp": "^11.0.0",
10-
"purescript": "^0.11.4",
11-
"purescript-psa": "^0.5.0",
12+
"pulp": "^12.3.0",
13+
"purescript": "^0.12.0",
14+
"purescript-psa": "^0.6.0",
1215
"rimraf": "^2.5.4"
1316
}
1417
}

src/Text/Markdown/SlamDown/Parser.purs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import Data.Foldable (any, all)
1111
import Data.List ((:))
1212
import Data.List as L
1313
import Data.Maybe as M
14-
import Data.Monoid (mempty)
15-
import Data.String as S
14+
import Data.String (Pattern(..), Replacement(..), drop, length, replace, split, take, trim) as S
15+
import Data.String.CodeUnits (countPrefix, dropWhile, singleton) as S
1616
import Data.String.Regex as RGX
1717
import Data.String.Regex.Unsafe as URX
1818
import Data.String.Regex.Flags as RXF
@@ -59,7 +59,7 @@ allChars p = all p <<< S.split (S.Pattern "")
5959

6060
removeNonIndentingSpaces String String
6161
removeNonIndentingSpaces s
62-
| S.count (isSpace <<< S.singleton) s < 4 = S.dropWhile (isSpace <<< S.singleton) s
62+
| S.countPrefix (isSpace <<< S.singleton) s < 4 = S.dropWhile (isSpace <<< S.singleton) s
6363
| otherwise = s
6464

6565
isRuleChar String Boolean
@@ -77,15 +77,15 @@ isRule s =
7777
isATXHeader String Boolean
7878
isATXHeader s =
7979
let
80-
level = S.count (\c → S.singleton c == "#") s
80+
level = S.countPrefix (\c → S.singleton c == "#") s
8181
rest = S.drop level s
8282
in
8383
level >= 1 && level <= 6 && S.take 1 rest == " "
8484

8585
splitATXHeader String { level Int, contents String }
8686
splitATXHeader s =
8787
let
88-
level = S.count (\c → S.singleton c == "#") s
88+
level = S.countPrefix (\c → S.singleton c == "#") s
8989
contents = S.drop (level + 1) s
9090
in
9191
{ level: level
@@ -120,7 +120,7 @@ splitBlockquote ss =
120120
blockquoteContents s = S.drop (if S.take 2 s == "> " then 2 else 1) s
121121

122122
countLeadingSpaces String Int
123-
countLeadingSpaces = S.count (isSpace <<< S.singleton)
123+
countLeadingSpaces = S.countPrefix (isSpace <<< S.singleton)
124124

125125
isBulleted String Boolean
126126
isBulleted s =
@@ -139,7 +139,7 @@ isBulleted s =
139139
isOrderedListMarker String Boolean
140140
isOrderedListMarker s =
141141
let
142-
n = S.count (isDigit <<< S.singleton) s
142+
n = S.countPrefix (isDigit <<< S.singleton) s
143143
next = S.take 1 (S.drop n s)
144144
ls = countLeadingSpaces (S.drop (n + 1) s)
145145
in
@@ -149,14 +149,14 @@ listItemType ∷ String → SD.ListType
149149
listItemType s
150150
| isBulleted s = SD.Bullet (S.take 1 s)
151151
| otherwise =
152-
let n = S.count (isDigit <<< S.singleton) s
152+
let n = S.countPrefix (isDigit <<< S.singleton) s
153153
in SD.Ordered (S.take 1 (S.drop n s))
154154

155155
listItemIndent String Int
156156
listItemIndent s
157157
| isBulleted s = 1 + min 4 (countLeadingSpaces (S.drop 1 s))
158158
| otherwise =
159-
let n = S.count (isDigit <<< S.singleton) s
159+
let n = S.countPrefix (isDigit <<< S.singleton) s
160160
in n + 1 + min 4 (countLeadingSpaces (S.drop (n + 1) s))
161161

162162
isListItemLine String Boolean
@@ -210,7 +210,7 @@ splitIndentedChunks ss =
210210
isCodeFence String Boolean
211211
isCodeFence s = isSimpleFence s || (isEvaluatedCode s && isSimpleFence (S.drop 1 s))
212212
where
213-
isSimpleFence s' = S.count (isFenceChar <<< S.singleton) s' >= 3
213+
isSimpleFence s' = S.countPrefix (isFenceChar <<< S.singleton) s' >= 3
214214

215215
isEvaluatedCode String Boolean
216216
isEvaluatedCode s = S.take 1 s == "!"
@@ -243,7 +243,7 @@ splitCodeFence indent fence ss =
243243
}
244244
where
245245
isClosingFence String Boolean
246-
isClosingFence s = S.count (\c → S.singleton c == fence) (removeNonIndentingSpaces s) >= 3
246+
isClosingFence s = S.countPrefix (\c → S.singleton c == fence) (removeNonIndentingSpaces s) >= 3
247247

248248
removeIndentTo String String
249249
removeIndentTo s = S.drop (min indent (countLeadingSpaces s)) s

src/Text/Markdown/SlamDown/Parser/Inline.purs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ import Data.Bifunctor (lmap)
1515
import Data.Char.Unicode (isAlphaNum)
1616
import Data.Const (Const(..))
1717
import Data.DateTime as DT
18+
import Data.Decimal as D
1819
import Data.Either (Either(..))
1920
import Data.Enum (toEnum)
2021
import Data.Foldable (elem)
2122
import Data.Functor.Compose (Compose(..))
22-
import Data.HugeNum as HN
2323
import Data.Int as Int
2424
import Data.List as L
2525
import Data.Maybe as M
26-
import Data.String as S
26+
import Data.String (joinWith, trim) as S
27+
import Data.String.CodeUnits (fromCharArray, singleton, toCharArray) as S
2728
import Data.Traversable (traverse)
2829
import Data.Tuple (Tuple(..), fst, snd)
2930
import Data.Validation.Semigroup as V
@@ -93,7 +94,7 @@ hash = void $ PS.string "#"
9394
type TextParserKit
9495
= { plainText P.Parser String String
9596
, natural P.Parser String Int
96-
, decimal P.Parser String HN.HugeNum
97+
, decimal P.Parser String D.Decimal
9798
, numericPrefix P.Parser String Unit
9899
}
99100

@@ -278,7 +279,7 @@ inlines = L.many inline2 <* PS.eof
278279
M.Nothing → pure $ Right $ SD.TextBox $ SD.transTextBox (const $ Compose M.Nothing) template
279280
M.Just _ → do
280281
PU.skipSpaces
281-
mdef ← PC.optionMaybe $ PC.try $ parseTextBox (_ /= ')') (expr id) template
282+
mdef ← PC.optionMaybe $ PC.try $ parseTextBox (_ /= ')') (expr identity) template
282283
case mdef of
283284
M.Just def → do
284285
PU.skipSpaces
@@ -386,8 +387,8 @@ inlines = L.many inline2 <* PS.eof
386387
dropDown P.Parser String (SD.FormField a)
387388
dropDown = do
388389
let item = SD.stringValue <<< S.trim <$> manyOf \c → not $ c `elem` ['{','}',',','!','`','(',')']
389-
ls ← PU.braces $ expr id $ (PC.try (PU.skipSpaces *> item)) `PC.sepBy` (PU.skipSpaces *> PS.string ",")
390-
sel ← PC.optionMaybe $ PU.skipSpaces *> (PU.parens $ expr id $ item)
390+
ls ← PU.braces $ expr identity $ (PC.try (PU.skipSpaces *> item)) `PC.sepBy` (PU.skipSpaces *> PS.string ",")
391+
sel ← PC.optionMaybe $ PU.skipSpaces *> (PU.parens $ expr identity $ item)
391392
pure $ SD.DropDown sel ls
392393

393394
other P.Parser String (SD.Inline a)
@@ -485,7 +486,7 @@ parseTextBox isPlainText eta template =
485486
M.Nothing
486487
pure M.Nothing
487488

488-
HN.fromString (ms <> "." <> M.fromMaybe "" ns)
489+
D.fromString (ms <> "." <> M.fromMaybe "" ns)
489490
# M.maybe (P.fail "Failed parsing decimal") pure
490491

491492
parsePlainTextValue =

src/Text/Markdown/SlamDown/Parser/References.purs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import Prelude
77
import Data.Array as A
88
import Data.Either as E
99
import Data.Maybe as M
10-
import Data.String as S
10+
import Data.String (trim) as S
11+
import Data.String.CodeUnits (fromCharArray) as S
1112

1213
import Text.Parsing.Parser as P
1314
import Text.Parsing.Parser.Combinators as PC

src/Text/Markdown/SlamDown/Parser/Utils.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Text.Markdown.SlamDown.Parser.Utils
1010
import Prelude
1111

1212
import Data.Either (fromRight)
13-
import Data.String (singleton)
13+
import Data.String.CodeUnits (singleton)
1414
import Data.String.Regex as R
1515
import Data.String.Regex.Flags as RF
1616

src/Text/Markdown/SlamDown/Pretty.purs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import Prelude
77

88
import Data.Array as A
99
import Data.DateTime as DT
10+
import Data.Decimal as D
1011
import Data.Foldable (fold, elem)
1112
import Data.Functor.Compose (Compose)
12-
import Data.HugeNum as HN
1313
import Data.Identity (Identity(..))
1414
import Data.List as L
1515
import Data.Maybe as M
1616
import Data.Enum (fromEnum)
17-
import Data.Monoid (mempty)
1817
import Data.Newtype (unwrap)
19-
import Data.String as S
18+
import Data.String (Pattern(..), indexOf, joinWith, length, split, stripSuffix) as S
19+
import Data.String.CodeUnits (fromCharArray) as S
2020
import Data.Unfoldable as U
2121

2222
import Text.Markdown.SlamDown.Syntax as SD
@@ -117,8 +117,8 @@ prettyPrintTextBoxValue t =
117117
case t of
118118
SD.PlainText (Identity def) → def
119119
SD.Numeric (Identity def) →
120-
let s = HN.toString def in
121-
M.fromMaybe s $ S.stripSuffix (S.Pattern ".") $ HN.toString def
120+
let s = D.toString def in
121+
M.fromMaybe s $ S.stripSuffix (S.Pattern ".") $ D.toString def
122122
SD.Date (Identity def) → prettyPrintDate def
123123
SD.Time prec (Identity def) → prettyPrintTime prec def
124124
SD.DateTime prec (Identity def) → prettyPrintDateTime prec def
@@ -174,11 +174,11 @@ prettyPrintTextBox t =
174174
prettyPrintDefault SD.TextBox SD.Expr String
175175
prettyPrintDefault =
176176
case _ of
177-
SD.PlainText def → prettyPrintExpr id id def
178-
SD.Numeric def → prettyPrintExpr id HN.toString def
179-
SD.Date def → prettyPrintExpr id prettyPrintDate def
180-
SD.Time prec def → prettyPrintExpr id (prettyPrintTime prec) def
181-
SD.DateTime prec def → prettyPrintExpr id (prettyPrintDateTime prec) def
177+
SD.PlainText def → prettyPrintExpr identity identity def
178+
SD.Numeric def → prettyPrintExpr identity D.toString def
179+
SD.Date def → prettyPrintExpr identity prettyPrintDate def
180+
SD.Time prec def → prettyPrintExpr identity (prettyPrintTime prec) def
181+
SD.DateTime prec def → prettyPrintExpr identity (prettyPrintDateTime prec) def
182182

183183

184184
prettyPrintFormElement a. (SD.Value a) SD.FormField a String
@@ -200,8 +200,8 @@ prettyPrintFormElement el =
200200
SD.CheckBoxes (SD.Unevaluated bs) (SD.Unevaluated ls) →
201201
"[!`" <> bs <> "`] !`" <> ls <> "`"
202202
SD.DropDown sel lbls →
203-
braces (prettyPrintExpr id (A.fromFoldable >>> map SD.renderValue >>> S.joinWith ", ") lbls)
204-
<> M.maybe "" (parens <<< prettyPrintExpr id SD.renderValue) sel
203+
braces (prettyPrintExpr identity (A.fromFoldable >>> map SD.renderValue >>> S.joinWith ", ") lbls)
204+
<> M.maybe "" (parens <<< prettyPrintExpr identity SD.renderValue) sel
205205
_ → "Unsupported form element"
206206

207207
prettyPrintExpr a. (String String) (a String) SD.Expr a String

src/Text/Markdown/SlamDown/Syntax.purs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ module Text.Markdown.SlamDown.Syntax
1010
import Prelude
1111

1212
import Data.List as L
13-
import Data.Monoid (class Monoid, mempty)
1413
import Test.StrongCheck.Arbitrary as SCA
1514
import Test.StrongCheck.Gen as Gen
1615

17-
import Text.Markdown.SlamDown.Syntax.Block as SDB
18-
import Text.Markdown.SlamDown.Syntax.FormField as SDF
19-
import Text.Markdown.SlamDown.Syntax.Inline as SDI
16+
import Text.Markdown.SlamDown.Syntax.Block (Block(..), CodeBlockType(..), ListType(..)) as SDB
17+
import Text.Markdown.SlamDown.Syntax.FormField (class Value, Expr(..), FormField, FormFieldP(..), TextBox(..), TimePrecision(..), getLiteral, getUnevaluated, renderValue, stringValue, transFormField, transTextBox, traverseFormField, traverseTextBox) as SDF
18+
import Text.Markdown.SlamDown.Syntax.Inline (Inline(..), LinkTarget(..)) as SDI
2019

2120
-- | `SlamDownP` is the type of SlamDown abstract syntax trees which take values in `a`.
2221
data SlamDownP a = SlamDown (L.List (SDB.Block a))

src/Text/Markdown/SlamDown/Syntax/FormField.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import Partial.Unsafe (unsafePartial)
3131
import Test.StrongCheck.Arbitrary as SCA
3232
import Test.StrongCheck.Gen as Gen
3333

34-
import Text.Markdown.SlamDown.Syntax.TextBox as TB
35-
import Text.Markdown.SlamDown.Syntax.Value as Value
34+
import Text.Markdown.SlamDown.Syntax.TextBox (TextBox(..), TimePrecision(..), transTextBox, traverseTextBox) as TB
35+
import Text.Markdown.SlamDown.Syntax.Value (class Value, renderValue, stringValue) as Value
3636

3737
data FormFieldP f a
3838
= TextBox (TB.TextBox (Compose M.Maybe f))
@@ -102,7 +102,7 @@ instance eqFormField ∷ (Functor f, Eq (f a), Eq (TB.TextBox (Compose M.Maybe f
102102
case _, _ of
103103
TextBox tb1, TextBox tb2 → tb1 == tb2
104104
RadioButtons sel1 ls1, RadioButtons sel2 ls2 → sel1 == sel2 && ls1 == ls2
105-
CheckBoxes sel1 ls1, CheckBoxes sel2 ls2 → (Set.fromFoldable <$> sel1 == Set.fromFoldable <$> sel2) && ls1 == ls2
105+
CheckBoxes sel1 ls1, CheckBoxes sel2 ls2 → ((Set.fromFoldable <$> sel1) == (Set.fromFoldable <$> sel2)) && ls1 == ls2
106106
DropDown sel1 ls1, DropDown sel2 ls2 → sel1 == sel2 && ls1 == ls2
107107
_, _ → false
108108

@@ -155,7 +155,7 @@ unsafeElements ∷ ∀ a. L.List a → Gen.Gen a
155155
unsafeElements =
156156
Gen.elements
157157
<$> (unsafePartial M.fromJust <<< L.head)
158-
<*> id
158+
<*> identity
159159

160160
instance arbitraryFormField ∷ (SCA.Arbitrary a, Eq a) SCA.Arbitrary (FormFieldP Expr a) where
161161
arbitrary = do

src/Text/Markdown/SlamDown/Syntax/TextBox.purs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ module Text.Markdown.SlamDown.Syntax.TextBox
88
import Prelude
99

1010
import Data.DateTime as DT
11-
import Data.HugeNum as HN
11+
import Data.Decimal as D
12+
import Data.Eq (class Eq1)
1213
import Data.Identity (Identity(..))
1314
import Data.Newtype (unwrap)
15+
import Data.Ord (class Ord1)
1416

1517
import Test.StrongCheck.Arbitrary as SCA
1618
import Test.StrongCheck.Data.ArbDateTime as ADT
@@ -39,7 +41,7 @@ instance coarbitraryTimePrecision ∷ SCA.Coarbitrary TimePrecision where
3941

4042
data TextBox f
4143
= PlainText (f String)
42-
| Numeric (f HN.HugeNum)
44+
| Numeric (f D.Decimal)
4345
| Date (f DT.Date)
4446
| Time TimePrecision (f DT.Time)
4547
| DateTime TimePrecision (f DT.DateTime)
@@ -60,23 +62,23 @@ traverseTextBox eta = case _ of
6062
Time prec def → Time prec <$> eta def
6163
DateTime prec def → DateTime prec <$> eta def
6264

63-
instance showTextBox ∷ (Functor f, Show (f String), Show (f HN.HugeNum), Show (f DT.Time), Show (f DT.Date), Show (f DT.DateTime)) Show (TextBox f) where
65+
instance showTextBox ∷ (Functor f, Show (f String), Show (f D.Decimal), Show (f DT.Time), Show (f DT.Date), Show (f DT.DateTime)) Show (TextBox f) where
6466
show = case _ of
6567
PlainText def → "(PlainText " <> show def <> ")"
6668
Numeric def → "(Numeric " <> show def <> ")"
6769
Date def → "(Date " <> show def <> ")"
6870
Time prec def → "(Time " <> show prec <> " " <> show def <> ")"
6971
DateTime prec def → "(DateTime " <> show prec <> " " <> show def <> ")"
7072

71-
derive instance eqTextBox ∷ (Functor f, Eq (f String), Eq (f HN.HugeNum), Eq (f DT.Time), Eq (f DT.Date), Eq (f DT.DateTime)) Eq (TextBox f)
72-
derive instance ordTextBox ∷ (Functor f, Ord (f String), Ord (f HN.HugeNum), Ord (f DT.Time), Ord (f DT.Date), Ord (f DT.DateTime)) Ord (TextBox f)
73+
derive instance eqTextBox ∷ (Functor f, Eq (f String), Eq (f D.Decimal), Eq (f DT.Time), Eq (f DT.Date), Eq (f DT.DateTime), Eq1 f) Eq (TextBox f)
74+
derive instance ordTextBox ∷ (Functor f, Ord (f String), Ord (f D.Decimal), Ord (f DT.Time), Ord (f DT.Date), Ord (f DT.DateTime), Ord1 f) Ord (TextBox f)
7375

7476
instance arbitraryTextBox ∷ (Functor f, SCA.Arbitrary (f String), SCA.Arbitrary (f Number), SCA.Arbitrary (f ADT.ArbTime), SCA.Arbitrary (f ADT.ArbDate), SCA.Arbitrary (f ADT.ArbDateTime)) SCA.Arbitrary (TextBox f) where
7577
arbitrary = do
7678
i ← Gen.chooseInt 0 5
7779
case i of
7880
0PlainText <$> SCA.arbitrary
79-
1Numeric <<< map HN.fromNumber <$> SCA.arbitrary
81+
1Numeric <<< map D.fromNumber <$> SCA.arbitrary
8082
2Date <<< map ADT.runArbDate <$> SCA.arbitrary
8183
3Time <$> SCA.arbitrary <*> (map (eraseMillis <<< ADT.runArbTime) <$> SCA.arbitrary)
8284
4DateTime <$> SCA.arbitrary <*> (map (DT.modifyTime eraseMillis <<< ADT.runArbDateTime) <$> SCA.arbitrary)
@@ -86,7 +88,7 @@ instance coarbitraryTextBox ∷ (Functor f, SCA.Coarbitrary (f String), SCA.Coar
8688
coarbitrary =
8789
case _ of
8890
PlainText d -> SCA.coarbitrary d
89-
Numeric d -> SCA.coarbitrary $ HN.toNumber <$> d
91+
Numeric d -> SCA.coarbitrary $ D.toNumber <$> d
9092
Date d -> SCA.coarbitrary (ADT.ArbDate <$> d)
9193
Time prec d -> do
9294
_ ← SCA.coarbitrary prec

0 commit comments

Comments
 (0)