Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parsing v7.0.0 no StringLike class #76

Merged
merged 2 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Notable changes to this project are documented in this file. The format is based

Breaking changes:

- Upgrade to parsing v7.0.0, replace all `StringLike` constraints with `String` type (#76 by @jamesdbrock)

New features:

Bugfixes:
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"purescript-fixed-points": "^6.0.0",
"purescript-lists": "^6.0.0",
"purescript-numbers": "^8.0.0",
"purescript-parsing": "^6.0.0",
"purescript-parsing": "^7.0.0",
"purescript-prelude": "^5.0.0",
"purescript-transformers": "^5.0.0"
},
Expand Down
1 change: 1 addition & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210722/packages.dhall sha256:1ceb43aa59436bf5601bac45f6f3781c4e1f0e4c2b8458105b018e5ed8c30f8c

in upstream
with parsing.version = "v7.0.0"
10 changes: 5 additions & 5 deletions src/Data/Formatter/Parser/Number.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ import Data.Maybe (Maybe(..))
import Data.Number (fromString)
import Data.Foldable (foldMap)

parseInteger ∷ ∀ s m. Monad m ⇒ PS.StringLike s ⇒ P.ParserT s m Int
parseInteger ∷ ∀ m. Monad m ⇒ P.ParserT String m Int
parseInteger = some parseDigit <#> foldDigits

parseMaybeInteger ∷ ∀ s m. Monad m ⇒ PS.StringLike s ⇒ P.ParserT s m (Maybe Int)
parseMaybeInteger ∷ ∀ m. Monad m ⇒ P.ParserT String m (Maybe Int)
parseMaybeInteger = PC.optionMaybe parseInteger

parseFractional ∷ ∀ s m. Monad m ⇒ PS.StringLike s ⇒ P.ParserT s m Number
parseFractional ∷ ∀ m. Monad m ⇒ P.ParserT String m Number
parseFractional = do
digitStr <- (some parseDigit) <#> (foldMap show >>> ("0." <> _))
case fromString digitStr of
Just n -> pure n
Nothing -> P.fail ("Not a number: " <> digitStr)

parseNumber ∷ ∀ s m. Monad m ⇒ PS.StringLike s ⇒ P.ParserT s m Number
parseNumber ∷ ∀ m. Monad m ⇒ P.ParserT String m Number
parseNumber = (+)
<$> (parseInteger <#> toNumber)
<*> (PC.option 0.0 $ PC.try $ PS.oneOf ['.', ','] *> parseFractional)


parseDigit ∷ ∀ s m. Monad m ⇒ PS.StringLike s ⇒ P.ParserT s m Int
parseDigit ∷ ∀ m. Monad m ⇒ P.ParserT String m Int
parseDigit = PC.try $ PS.char `oneOfAs`
[ Tuple '0' 0
, Tuple '1' 1
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Formatter/Parser/Utils.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Data.Either (Either)
oneOfAs ∷ ∀ c s m f a b. Functor f ⇒ Foldable f ⇒ Monad m ⇒ (a → ParserT s m b) → f (Tuple a c) → ParserT s m c
oneOfAs p xs = PC.choice $ (\(Tuple s r) → p s $> r) <$> xs

runP ∷ ∀ s a. PS.StringLike s ⇒ Parser s a → s → Either String a
runP ∷ ∀ a. Parser String a → String → Either String a
runP p s = lmap printError $ runParser s (p <* PS.eof)

printError ∷ ParseError → String
Expand Down