Skip to content

Commit

Permalink
Updates for 0.11 (#49)
Browse files Browse the repository at this point in the history
* Updates for 0.11

* Update bower.json
  • Loading branch information
paf31 authored Apr 5, 2017
1 parent a826cdd commit f66c163
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 49 deletions.
12 changes: 2 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
language: node_js
dist: trusty
sudo: required
node_js: 6
env:
- PATH=$HOME/purescript:$PATH
node_js: stable
install:
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
- npm install -g bower
- npm install
- bower install
script:
- bower install --production
- npm run -s build
- bower install
- npm -s test
after_success:
- >-
test $TRAVIS_TAG &&
Expand Down
24 changes: 12 additions & 12 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
"package.json"
],
"dependencies": {
"purescript-arrays": "^3.0.0",
"purescript-either": "^2.0.0",
"purescript-foldable-traversable": "^2.0.0",
"purescript-identity": "^2.0.0",
"purescript-integers": "^2.0.0",
"purescript-lists": "^3.0.0",
"purescript-maybe": "^2.0.0",
"purescript-strings": "^2.0.0",
"purescript-transformers": "^2.0.0",
"purescript-unicode": "^2.0.0"
"purescript-arrays": "^4.0.0",
"purescript-either": "^3.0.0",
"purescript-foldable-traversable": "^3.0.0",
"purescript-identity": "^3.0.0",
"purescript-integers": "^3.0.0",
"purescript-lists": "^4.0.0",
"purescript-maybe": "^3.0.0",
"purescript-strings": "^3.0.0",
"purescript-transformers": "^3.0.0",
"purescript-unicode": "^3.0.0"
},
"devDependencies": {
"purescript-assert": "^2.0.0",
"purescript-console": "^2.0.0"
"purescript-assert": "^3.0.0",
"purescript-console": "^3.0.0"
}
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "pulp build --censor-lib --strict",
"test": "pulp test"
"build": "pulp build && pulp test"
},
"devDependencies": {
"pulp": "^9.0.1",
"purescript-psa": "^0.3.9",
"rimraf": "^2.5.0"
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.1",
"rimraf": "^2.5.4"
}
}
6 changes: 4 additions & 2 deletions src/Text/Parsing/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ module Text.Parsing.Parser
import Prelude
import Control.Alt (class Alt)
import Control.Lazy (defer, class Lazy)
import Control.Monad.Except (class MonadError, ExceptT(..), throwError, runExceptT, mapExceptT)
import Control.Monad.Error.Class (class MonadThrow, throwError)
import Control.Monad.Except (class MonadError, ExceptT(..), runExceptT, mapExceptT)
import Control.Monad.Rec.Class (class MonadRec)
import Control.Monad.State (runStateT, class MonadState, StateT(..), gets, evalStateT, mapStateT, modify)
import Control.Monad.Trans.Class (lift, class MonadTrans)
import Control.Monad.Trans.Class (class MonadTrans, lift)
import Control.MonadPlus (class Alternative, class MonadZero, class MonadPlus, class Plus)
import Data.Either (Either(..))
import Data.Identity (Identity)
Expand Down Expand Up @@ -78,6 +79,7 @@ derive newtype instance bindParserT :: Monad m => Bind (ParserT s m)
derive newtype instance monadParserT :: Monad m => Monad (ParserT s m)
derive newtype instance monadRecParserT :: MonadRec m => MonadRec (ParserT s m)
derive newtype instance monadStateParserT :: Monad m => MonadState (ParseState s) (ParserT s m)
derive newtype instance monadThrowParserT :: Monad m => MonadThrow ParseError (ParserT s m)
derive newtype instance monadErrorParserT :: Monad m => MonadError ParseError (ParserT s m)

instance altParserT :: Monad m => Alt (ParserT s m) where
Expand Down
9 changes: 4 additions & 5 deletions src/Text/Parsing/Parser/Combinators.purs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ option a p = p <|> pure a

-- | Optionally parse something, failing quietly.
optional :: forall m s a. Monad m => ParserT s m a -> ParserT s m Unit
optional p = (void p) <|> pure unit
optional p = void p <|> pure unit

-- | pure `Nothing` in the case where a parser fails without consuming input.
optionMaybe :: forall m s a. Monad m => ParserT s m a -> ParserT s m (Maybe a)
Expand Down Expand Up @@ -154,7 +154,7 @@ chainr1' p f a = (do f' <- f
pure $ f' a a') <|> pure a

-- | Parse one of a set of alternatives.
choice :: forall f m s a. (Foldable f, Monad m) => f (ParserT s m a) -> ParserT s m a
choice :: forall f m s a. Foldable f => Monad m => f (ParserT s m a) -> ParserT s m a
choice = foldl (<|>) empty

-- | Skip many instances of a phrase.
Expand All @@ -177,10 +177,9 @@ manyTill :: forall s a m e. Monad m => ParserT s m a -> ParserT s m e -> ParserT
manyTill p end = scan
where
scan = (end $> Nil)
<|> (do
x <- p
<|> do x <- p
xs <- scan
pure (x:xs))
pure (x:xs)

-- | Parse several phrases until the specified terminator matches, requiring at least one match.
many1Till :: forall s a m e. Monad m => ParserT s m a -> ParserT s m e -> ParserT s m (List a)
Expand Down
18 changes: 9 additions & 9 deletions src/Text/Parsing/Parser/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ instance stringLikeString :: StringLike String where
null = S.null

-- | Match end-of-file.
eof :: forall s m. (StringLike s, Monad m) => ParserT s m Unit
eof :: forall s m. StringLike s => Monad m => ParserT s m Unit
eof = do
input <- gets \(ParseState input _ _) -> input
unless (null input) (fail "Expected EOF")

-- | Match the specified string.
string :: forall s m. (StringLike s, Monad m) => String -> ParserT s m String
string :: forall s m. StringLike s => Monad m => String -> ParserT s m String
string str = do
input <- gets \(ParseState input _ _) -> input
case indexOf (wrap str) input of
Expand All @@ -48,7 +48,7 @@ string str = do
_ -> fail ("Expected " <> show str)

-- | Match any character.
anyChar :: forall s m. (StringLike s, Monad m) => ParserT s m Char
anyChar :: forall s m. StringLike s => Monad m => ParserT s m Char
anyChar = do
input <- gets \(ParseState input _ _) -> input
case uncons input of
Expand All @@ -61,30 +61,30 @@ anyChar = do
pure head

-- | Match a character satisfying the specified predicate.
satisfy :: forall s m. (StringLike s, Monad m) => (Char -> Boolean) -> ParserT s m Char
satisfy :: forall s m. StringLike s => Monad m => (Char -> Boolean) -> ParserT s m Char
satisfy f = try do
c <- anyChar
if f c then pure c
else fail $ "Character '" <> singleton c <> "' did not satisfy predicate"

-- | Match the specified character
char :: forall s m. (StringLike s, Monad m) => Char -> ParserT s m Char
char :: forall s m. StringLike s => Monad m => Char -> ParserT s m Char
char c = satisfy (_ == c) <?> ("Expected " <> show c)

-- | Match a whitespace character.
whiteSpace :: forall s m. (StringLike s, Monad m) => ParserT s m String
whiteSpace :: forall s m. StringLike s => Monad m => ParserT s m String
whiteSpace = do
cs <- many $ satisfy \c -> c == '\n' || c == '\r' || c == ' ' || c == '\t'
pure $ fromCharArray cs

-- | Skip whitespace characters.
skipSpaces :: forall s m. (StringLike s, Monad m) => ParserT s m Unit
skipSpaces :: forall s m. StringLike s => Monad m => ParserT s m Unit
skipSpaces = void whiteSpace

-- | Match one of the characters in the array.
oneOf :: forall s m. (StringLike s, Monad m) => Array Char -> ParserT s m Char
oneOf :: forall s m. StringLike s => Monad m => Array Char -> ParserT s m Char
oneOf ss = satisfy (flip elem ss) <?> ("Expected one of " <> show ss)

-- | Match any character not in the array.
noneOf :: forall s m. (StringLike s, Monad m) => Array Char -> ParserT s m Char
noneOf :: forall s m. StringLike s => Monad m => Array Char -> ParserT s m Char
noneOf ss = satisfy (flip notElem ss) <?> ("Expected none of " <> show ss)
2 changes: 1 addition & 1 deletion src/Text/Parsing/Parser/Token.purs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ when tokpos f = try $ do
pure a

-- | Match the specified token at the head of the stream.
match :: forall a m. (Monad m, Eq a) => (a -> Position) -> a -> ParserT (List a) m a
match :: forall a m. Monad m => Eq a => (a -> Position) -> a -> ParserT (List a) m a
match tokpos tok = when tokpos (_ == tok)

type LanguageDef = GenLanguageDef String Identity
Expand Down
10 changes: 5 additions & 5 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ parens = between (string "(") (string ")")

nested :: forall m. Monad m => ParserT String m Int
nested = fix \p -> (do
string "a"
_ <- string "a"
pure 0) <|> ((+) 1) <$> parens p

parseTest :: forall s a eff. (Show a, Eq a) => s -> a -> Parser s a -> Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
parseTest :: forall s a eff. Show a => Eq a => s -> a -> Parser s a -> Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
parseTest input expected p = case runParser input p of
Right actual -> do
assert' ("expected: " <> show expected <> ", actual: " <> show actual) (expected == actual)
logShow actual
Left err -> assert' ("error: " <> show err) false

parseErrorTestPosition :: forall s a eff. (Show a) => Parser s a -> s -> Position -> Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
parseErrorTestPosition :: forall s a eff. Show a => Parser s a -> s -> Position -> Eff (console :: CONSOLE, assert :: ASSERT | eff) Unit
parseErrorTestPosition p input expected = case runParser input p of
Right _ -> assert' "error: ParseError expected!" false
Left err -> do
Expand Down Expand Up @@ -69,7 +69,7 @@ exprTest = buildExprParser [ [ Infix (string "/" >>= \_ -> pure (/)) AssocRight
manySatisfyTest :: Parser String String
manySatisfyTest = do
r <- some $ satisfy (\s -> s /= '?')
char '?'
_ <- char '?'
pure (fromCharArray r)

data TestToken = A | B
Expand Down Expand Up @@ -427,7 +427,7 @@ main = do
parseTest "(((a)))" 3 nested
parseTest "aaa" (Cons "a" (Cons "a" (Cons "a" Nil))) $ many (string "a")
parseTest "(ab)" (Just "b") $ parens do
string "a"
_ <- string "a"
optionMaybe $ string "b"
parseTest "a,a,a" (Cons "a" (Cons "a" (Cons "a" Nil))) $ string "a" `sepBy1` string ","
parseTest "a,a,a," (Cons "a" (Cons "a" (Cons "a" Nil))) $ do
Expand Down

0 comments on commit f66c163

Please sign in to comment.