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

Commit

Permalink
Merge pull request #73 from garyb/0.10-updates
Browse files Browse the repository at this point in the history
Update for PureScript 0.10
  • Loading branch information
garyb authored Nov 8, 2016
2 parents fe27025 + c1d24ce commit c326aae
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
dist: trusty
sudo: required
node_js: 6
node_js: stable
install:
- npm install -g bower
- npm install
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# purescript-markdown

[![Latest release](http://img.shields.io/bower/v/purescript-markdown.svg)](/~https://github.com/slamdata/purescript-markdown/releases)
[![Build Status](https://travis-ci.org/slamdata/purescript-markdown.svg?branch=master)](https://travis-ci.org/slamdata/purescript-markdown)
[![Dependency Status](https://www.versioneye.com/user/projects/578f7ce40ca92d004c89e13e/badge.svg?style=flat)](https://www.versioneye.com/user/projects/578f7ce40ca92d004c89e13e)
[![Latest release](http://img.shields.io/github/release/slamdata/purescript-markdown.svg)](/~https://github.com/slamdata/purescript-markdown/releases)
[![Build status](https://travis-ci.org/slamdata/purescript-markdown.svg?branch=master)](https://travis-ci.org/slamdata/purescript-markdown)

A Purescript library for parsing SlamData's dialect of Markdown, called *SlamDown*, which is mostly a safe, clean subset of CommonMark.

Expand Down
20 changes: 10 additions & 10 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
"package.json"
],
"dependencies": {
"purescript-const": "^1.0.0",
"purescript-functor-compose": "^0.1.0",
"purescript-hugenums": "^2.0.1",
"purescript-lists": "^1.0.1",
"purescript-parsing": "^1.0.0",
"purescript-const": "^2.0.0",
"purescript-functors": "^1.0.0",
"purescript-lists": "^3.2.0",
"purescript-parsing": "^3.0.0",
"purescript-partial": "^1.1.2",
"purescript-prelude": "^1.0.1",
"purescript-sets": "^1.0.0",
"purescript-strings": "^1.1.0",
"purescript-strongcheck": "^1.1.1",
"purescript-validation": "^1.0.0"
"purescript-precise": "^1.0.0",
"purescript-prelude": "^2.1.0",
"purescript-sets": "^2.0.0",
"purescript-strings": "^2.0.2",
"purescript-strongcheck": "^2.0.0",
"purescript-validation": "^2.0.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"devDependencies": {
"pulp": "^9.0.1",
"purescript": "^0.9.2",
"purescript": "^0.10.1",
"purescript-psa": "^0.3.9",
"rimraf": "^2.5.4"
}
Expand Down
11 changes: 6 additions & 5 deletions src/Text/Markdown/SlamDown/Eval.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import Control.Alt ((<|>))

import Data.Array as A
import Data.Const (Const(..))
import Data.Functor.Compose (Compose(..), decompose)
import Data.Identity (Identity(..), runIdentity)
import Data.Functor.Compose (Compose(..))
import Data.Identity (Identity(..))
import Data.List as L
import Data.Maybe as M
import Data.Newtype (unwrap)
import Data.String as S
import Data.Traversable as T

Expand Down Expand Up @@ -56,11 +57,11 @@ eval fs = everywhereM b i
evalTextBox SD.TextBox (Compose M.Maybe SD.Expr) m (M.Maybe (SD.TextBox Identity))
evalTextBox tb = T.sequence $ fs.textBox <$> asCode tb <|> pure <$> asLit tb
where
asLit = SD.traverseTextBox (decompose >>> (_ >>= SD.getLiteral) >>> map Identity)
asCode = SD.traverseTextBox (decompose >>> (_ >>= SD.getUnevaluated) >>> map Const)
asLit = SD.traverseTextBox (unwrap >>> (_ >>= SD.getLiteral) >>> map Identity)
asCode = SD.traverseTextBox (unwrap >>> (_ >>= SD.getUnevaluated) >>> map Const)

quoteTextBox SD.TextBox Identity SD.TextBox (Compose M.Maybe SD.Expr)
quoteTextBox = SD.transTextBox (runIdentity >>> SD.Literal >>> M.Just >>> Compose)
quoteTextBox = SD.transTextBox (unwrap >>> SD.Literal >>> M.Just >>> Compose)

f (SD.RadioButtons sel opts) = do
sel' ← evalExpr fs.value sel
Expand Down
6 changes: 3 additions & 3 deletions src/Text/Markdown/SlamDown/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ isDigit "9" = true
isDigit _ = false

allChars (String Boolean) String Boolean
allChars p = all p <<< S.split ""
allChars p = all p <<< S.split (S.Pattern "")

removeNonIndentingSpaces String String
removeNonIndentingSpaces s
Expand Down Expand Up @@ -367,11 +367,11 @@ validateSlamDown ∷ ∀ a. SD.SlamDownP a → V.V (Array String) (SD.SlamDownP
validateSlamDown (SD.SlamDown bls) = SD.SlamDown <$> traverse validateBlock bls

tabsToSpaces String String
tabsToSpaces = S.replace "\t" " "
tabsToSpaces = S.replace (S.Pattern "\t") (S.Replacement " ")

parseMd a. (SD.Value a) String Either String (SD.SlamDownP a)
parseMd s = map SD.SlamDown bs
where
lines = L.fromFoldable $ S.split "\n" $ S.replace "\r" "" $ tabsToSpaces s
lines = L.fromFoldable $ S.split (S.Pattern "\n") $ S.replace (S.Pattern "\r") (S.Replacement "") $ tabsToSpaces s
ctrs = parseContainers mempty lines
bs = parseBlocks ctrs
2 changes: 1 addition & 1 deletion src/Text/Markdown/SlamDown/Parser/Inline.purs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ parseInlines
Either String (L.List (SD.Inline a))
parseInlines s =
map consolidate
$ lmap (\(P.ParseError {message}) → message)
$ lmap P.parseErrorMessage
$ P.runParser (S.joinWith "\n" $ A.fromFoldable s) inlines

consolidate
Expand Down
14 changes: 3 additions & 11 deletions src/Text/Markdown/SlamDown/Parser/Utils.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Prelude
import Data.Either (fromRight)
import Data.String (singleton)
import Data.String.Regex as R
import Data.String.Regex.Flags as RF

import Partial.Unsafe (unsafePartial)

Expand All @@ -24,23 +25,14 @@ isWhitespace = R.test wsRegex <<< singleton
where
wsRegex R.Regex
wsRegex = unsafePartial fromRight $
R.regex "^\\s$" flags
R.regex "^\\s$" RF.noFlags

isEmailAddress String Boolean
isEmailAddress = R.test wsEmail
where
wsEmail R.Regex
wsEmail = unsafePartial fromRight $
R.regex """^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$""" flags

flags R.RegexFlags
flags =
{ unicode: false
, sticky: false
, multiline: false
, ignoreCase: false
, global: false
}
R.regex """^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$""" RF.noFlags

parens a. Parser String a Parser String a
parens p = string "(" *> skipSpaces *> p <* skipSpaces <* string ")"
Expand Down
11 changes: 6 additions & 5 deletions src/Text/Markdown/SlamDown/Pretty.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import Prelude

import Data.Array as A
import Data.Foldable (fold, elem)
import Data.Functor.Compose (Compose, decompose)
import Data.Functor.Compose (Compose)
import Data.HugeNum as HN
import Data.Identity (Identity(..))
import Data.List as L
import Data.Maybe as M
import Data.Monoid (mempty)
import Data.String as S
import Data.Newtype (unwrap)
import Data.Unfoldable as U

import Text.Markdown.SlamDown.Syntax as SD
Expand All @@ -35,7 +36,7 @@ overLines f = map f <<< L.concatMap lines

lines String L.List String
lines "" = mempty
lines s = L.fromFoldable $ S.split "\n" s
lines s = L.fromFoldable $ S.split (S.Pattern "\n") s

prettyPrintBlock a. (SD.Value a) SD.Block a L.List String
prettyPrintBlock bl =
Expand Down Expand Up @@ -102,7 +103,7 @@ prettyPrintInline il =
esc l <> star <> " = " <> prettyPrintFormElement e
where

esc s = M.maybe s (const $ "[" <> s <> "]") $ S.indexOf " " s
esc s = M.maybe s (const $ "[" <> s <> "]") $ S.indexOf (S.Pattern " ") s

printTarget SD.LinkTarget String
printTarget (SD.InlineLink url) = parens url
Expand All @@ -115,7 +116,7 @@ prettyPrintTextBoxValue t =
SD.PlainText (Identity def) → def
SD.Numeric (Identity def) →
let s = HN.toString def in
M.fromMaybe s $ S.stripSuffix "." $ HN.toString def
M.fromMaybe s $ S.stripSuffix (S.Pattern ".") $ HN.toString def
SD.Date (Identity def) → prettyPrintDate def
SD.Time prec (Identity def) → prettyPrintTime prec def
SD.DateTime prec (Identity def) → prettyPrintDateTime prec def
Expand Down Expand Up @@ -155,7 +156,7 @@ printIntPadded l i =
prettyPrintTextBox SD.TextBox (Compose M.Maybe SD.Expr) String
prettyPrintTextBox t =
prettyPrintTemplate t
<> M.maybe "" (\x → " (" <> prettyPrintDefault x <> ")") (SD.traverseTextBox decompose t)
<> M.maybe "" (\x → " (" <> prettyPrintDefault x <> ")") (SD.traverseTextBox unwrap t)
where
prettyPrintTemplate f. SD.TextBox f String
prettyPrintTemplate t =
Expand Down
2 changes: 1 addition & 1 deletion src/Text/Markdown/SlamDown/Syntax/Block.purs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ derive instance ordBlock ∷ (Ord a) ⇒ Ord (Block a)
-- | Nota bene: this does not generate any recursive structure
instance arbitraryBlock ∷ (SCA.Arbitrary a, Eq a) SCA.Arbitrary (Block a) where
arbitrary = do
k ← Gen.chooseInt 0.0 6.0
k ← Gen.chooseInt 0 6
case k of
0Paragraph <$> listOf SCA.arbitrary
1Header <$> SCA.arbitrary <*> listOf SCA.arbitrary
Expand Down
27 changes: 14 additions & 13 deletions src/Text/Markdown/SlamDown/Syntax/FormField.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ module Text.Markdown.SlamDown.Syntax.FormField
import Prelude

import Data.Array as A
import Data.Functor.Compose (Compose(..), decompose)
import Data.Identity (Identity(..), runIdentity)
import Data.Functor.Compose (Compose(..))
import Data.Identity (Identity(..))
import Data.List as L
import Data.Maybe as M
import Data.Newtype (unwrap)
import Data.Set as Set
import Data.Traversable as TR
import Data.Tuple (uncurry)
Expand All @@ -45,7 +46,7 @@ transFormField
FormFieldP f
~> FormFieldP g
transFormField eta =
runIdentity <<<
unwrap <<<
traverseFormField (eta >>> Identity)

traverseFormField
Expand All @@ -56,7 +57,7 @@ traverseFormField
h (FormFieldP g a)
traverseFormField eta field =
case field of
TextBox tb → TextBox <$> TB.traverseTextBox (decompose >>> TR.traverse eta >>> map Compose) tb
TextBox tb → TextBox <$> TB.traverseTextBox (unwrap >>> TR.traverse eta >>> map Compose) tb
RadioButtons sel ls → RadioButtons <$> eta sel <*> eta ls
CheckBoxes sel ls → CheckBoxes <$> eta sel <*> eta ls
DropDown sel ls → DropDown <$> TR.traverse eta sel <*> eta ls
Expand Down Expand Up @@ -156,7 +157,7 @@ unsafeElements =

instance arbitraryFormField ∷ (SCA.Arbitrary a, Eq a) SCA.Arbitrary (FormFieldP Expr a) where
arbitrary = do
k ← Gen.chooseInt 0.0 3.0
k ← Gen.chooseInt 0 3
case k of
0TextBox <<< TB.transTextBox getArbCompose <$> SCA.arbitrary
1do
Expand Down Expand Up @@ -189,7 +190,7 @@ instance arbitraryFormField ∷ (SCA.Arbitrary a, Eq a) ⇒ SCA.Arbitrary (FormF

instance arbitraryFormFieldIdentity ∷ (SCA.Arbitrary a, Eq a) SCA.Arbitrary (FormFieldP Identity a) where
arbitrary = do
k ← Gen.chooseInt 0.0 3.0
k ← Gen.chooseInt 0 3
case k of
0TextBox <<< TB.transTextBox (\(ArbCompose x) → Compose $ map getArbIdentity x) <$> SCA.arbitrary
1do
Expand Down Expand Up @@ -217,16 +218,16 @@ genMaybe gen = do
instance coarbitraryFormFieldIdentity ∷ (SCA.Coarbitrary a) SCA.Coarbitrary (FormFieldP Identity a) where
coarbitrary field =
case field of
TextBox tb → SCA.coarbitrary $ TB.transTextBox (decompose >>> map (runIdentity >>> ArbIdentity) >>> ArbCompose) tb
TextBox tb → SCA.coarbitrary $ TB.transTextBox (unwrap >>> map (unwrap >>> ArbIdentity) >>> ArbCompose) tb
RadioButtons x xs → \gen → do
SCA.coarbitrary (ArbIdentity $ runIdentity x) gen
SCA.coarbitrary (ArbIdentity $ runIdentity xs) gen
SCA.coarbitrary (ArbIdentity $ unwrap x) gen
SCA.coarbitrary (ArbIdentity $ unwrap xs) gen
CheckBoxes sel xs → \gen → do
SCA.coarbitrary (ArbIdentity $ runIdentity sel) gen
SCA.coarbitrary (ArbIdentity $ runIdentity xs) gen
SCA.coarbitrary (ArbIdentity $ unwrap sel) gen
SCA.coarbitrary (ArbIdentity $ unwrap xs) gen
DropDown mx xs → \gen → do
SCA.coarbitrary (ArbIdentity <<< runIdentity <$> mx) gen
SCA.coarbitrary (ArbIdentity $ runIdentity xs) gen
SCA.coarbitrary (ArbIdentity <<< unwrap <$> mx) gen
SCA.coarbitrary (ArbIdentity $ unwrap xs) gen

listOf1
f a
Expand Down
2 changes: 1 addition & 1 deletion src/Text/Markdown/SlamDown/Syntax/Inline.purs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ derive instance ordInline ∷ (Ord a) ⇒ Ord (Inline a)
-- | Nota bene: this does not generate any recursive structure
instance arbitraryInline ∷ (SCA.Arbitrary a, Eq a) SCA.Arbitrary (Inline a) where
arbitrary = do
k ← Gen.chooseInt 0.0 10.0
k ← Gen.chooseInt 0 10
case k of
0Str <$> SCA.arbitrary
1Entity <$> SCA.arbitrary
Expand Down
21 changes: 11 additions & 10 deletions src/Text/Markdown/SlamDown/Syntax/TextBox.purs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import Prelude

import Data.Function (on)
import Data.HugeNum as HN
import Data.Identity (Identity(..), runIdentity)
import Data.Identity (Identity(..))
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)

import Test.StrongCheck.Arbitrary as SCA
import Test.StrongCheck.Gen as Gen
Expand Down Expand Up @@ -56,9 +57,9 @@ instance showTimeValueP ∷ Show TimeValueP where

instance arbitraryTimeValuePSCA.Arbitrary TimeValueP where
arbitrary = do
hours ← Gen.chooseInt 0.0 12.0
minutes ← Gen.chooseInt 0.0 60.0
secs ← Gen.chooseInt 0.0 60.0
hours ← Gen.chooseInt 0 12
minutes ← Gen.chooseInt 0 60
secs ← Gen.chooseInt 0 60
b <- (_ < 0.5) <$> Gen.choose 0.0 1.0
let seconds = if b then Nothing else Just secs
pure $ TimeValueP { hours , minutes , seconds }
Expand Down Expand Up @@ -107,9 +108,9 @@ instance showDateValueP ∷ Show DateValueP where

instance arbitraryDateValuePSCA.Arbitrary DateValueP where
arbitrary = do
month ← Gen.chooseInt 0.0 12.0
day ← Gen.chooseInt 0.0 30.0
year ← Gen.chooseInt 0.0 3000.0
month ← Gen.chooseInt 0 12
day ← Gen.chooseInt 0 30
year ← Gen.chooseInt 0 3000
pure $ DateValueP { month , day, year }

instance coarbitraryDateValueP :: SCA.Coarbitrary DateValueP where
Expand Down Expand Up @@ -173,7 +174,7 @@ instance showTimePrecision :: Show TimePrecision where

instance arbitraryTimePrecisionSCA.Arbitrary TimePrecision where
arbitrary =
Gen.chooseInt 0.0 1.0 <#> case _ of
Gen.chooseInt 0 1 <#> case _ of
0Minutes
_ → Seconds

Expand All @@ -194,7 +195,7 @@ transTextBox
TextBox f
TextBox g
transTextBox eta =
runIdentity <<<
unwrap <<<
traverseTextBox (eta >>> Identity)

traverseTextBox
Expand Down Expand Up @@ -253,7 +254,7 @@ instance eqTextBox ∷ (Functor f, Eq (f String), Eq (f HN.HugeNum), Eq (f TimeV

instance arbitraryTextBox ∷ (Functor f, SCA.Arbitrary (f String), SCA.Arbitrary (f Number), SCA.Arbitrary (f TimeValueP), SCA.Arbitrary (f DateValueP), SCA.Arbitrary (f DateTimeValueP)) SCA.Arbitrary (TextBox f) where
arbitrary = do
i ← Gen.chooseInt 0.0 5.0
i ← Gen.chooseInt 0 5
case i of
0PlainText <$> SCA.arbitrary
1Numeric <<< map HN.fromNumber <$> SCA.arbitrary
Expand Down
7 changes: 4 additions & 3 deletions src/Text/Markdown/SlamDown/Traverse.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Prelude
import Data.Foldable as F
import Data.Identity as Id
import Data.Monoid (class Monoid)
import Data.Newtype (un)
import Data.Traversable as T

import Text.Markdown.SlamDown.Syntax as SD
Expand Down Expand Up @@ -48,7 +49,7 @@ everywhere
SD.SlamDownP a
SD.SlamDownP a
everywhere b i =
Id.runIdentity
un Id.Identity
<<< everywhereM (pure <<< b) (pure <<< i)

everywhereTopDownM
Expand Down Expand Up @@ -83,7 +84,7 @@ everywhereTopDown
SD.SlamDownP a
SD.SlamDownP a
everywhereTopDown b i =
Id.runIdentity <<<
un Id.Identity <<<
everywhereTopDownM
(pure <<< b)
(pure <<< i)
Expand Down Expand Up @@ -120,7 +121,7 @@ everything
SD.SlamDownP a
r
everything b i =
Id.runIdentity <<<
un Id.Identity <<<
everythingM
(pure <<< b)
(pure <<< i)
Loading

0 comments on commit c326aae

Please sign in to comment.