Skip to content

Commit cd1cc9c

Browse files
authored
Merge pull request #76 from joncfoo/update-for-0.12.0
Updates for purescript compiler v0.12.0
2 parents f8aa949 + 15281cf commit cd1cc9c

File tree

10 files changed

+92
-63
lines changed

10 files changed

+92
-63
lines changed

bower.json

+13-12
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@
2020
"package.json"
2121
],
2222
"dependencies": {
23-
"purescript-arrays": "^4.0.0",
24-
"purescript-either": "^3.0.0",
25-
"purescript-foldable-traversable": "^3.0.0",
26-
"purescript-identity": "^3.0.0",
27-
"purescript-integers": "^3.0.0",
28-
"purescript-lists": "^4.0.0",
29-
"purescript-maybe": "^3.0.0",
30-
"purescript-strings": "^3.0.0",
31-
"purescript-transformers": "^3.0.0",
32-
"purescript-unicode": "^3.0.0"
23+
"purescript-arrays": "^5.0.0",
24+
"purescript-either": "^4.0.0",
25+
"purescript-foldable-traversable": "^4.0.0",
26+
"purescript-identity": "^4.0.0",
27+
"purescript-integers": "^4.0.0",
28+
"purescript-lists": "^5.0.0",
29+
"purescript-maybe": "^4.0.0",
30+
"purescript-strings": "^4.0.0",
31+
"purescript-transformers": "^4.1.0",
32+
"purescript-unicode": "^4.0.0"
3333
},
3434
"devDependencies": {
35-
"purescript-assert": "^3.0.0",
36-
"purescript-console": "^3.0.0"
35+
"purescript-assert": "^4.0.0",
36+
"purescript-console": "^4.1.0",
37+
"purescript-psci-support": "^4.0.0"
3738
}
3839
}

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"build": "pulp build && pulp test"
66
},
77
"devDependencies": {
8-
"pulp": "^11.0.0",
9-
"purescript-psa": "^0.5.0",
10-
"purescript": "^0.11.1",
11-
"rimraf": "^2.5.4"
8+
"pulp": "^12.3.0",
9+
"purescript-psa": "^0.6.0",
10+
"purescript": "^0.12.0",
11+
"rimraf": "^2.6.2"
1212
}
1313
}

psc-package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "purescript-parsing",
3+
"set": "psc-0.12.0",
4+
"source": "https://github.com/purescript/package-sets.git",
5+
"depends": [
6+
"arrays",
7+
"either",
8+
"foldable-traversable",
9+
"identity",
10+
"integers",
11+
"lists",
12+
"maybe",
13+
"prelude",
14+
"psci-support",
15+
"strings",
16+
"transformers",
17+
"unicode"
18+
]
19+
}

src/Text/Parsing/Parser.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ module Text.Parsing.Parser
1616
) where
1717

1818
import Prelude
19+
1920
import Control.Alt (class Alt)
2021
import Control.Apply (lift2)
2122
import Control.Lazy (defer, class Lazy)
2223
import Control.Monad.Error.Class (class MonadThrow, throwError)
2324
import Control.Monad.Except (class MonadError, ExceptT(..), runExceptT, mapExceptT)
2425
import Control.Monad.Rec.Class (class MonadRec)
25-
import Control.Monad.State (runStateT, class MonadState, StateT(..), gets, evalStateT, mapStateT, modify)
26+
import Control.Monad.State (class MonadState, StateT(..), evalStateT, gets, mapStateT, modify_, runStateT)
2627
import Control.Monad.Trans.Class (class MonadTrans, lift)
2728
import Control.MonadPlus (class Alternative, class MonadZero, class MonadPlus, class Plus)
2829
import Data.Either (Either(..))
2930
import Data.Identity (Identity)
30-
import Data.Monoid (class Monoid, mempty)
3131
import Data.Newtype (class Newtype, unwrap, over)
3232
import Data.Tuple (Tuple(..))
3333
import Text.Parsing.Parser.Pos (Position, initialPos)
@@ -122,7 +122,7 @@ instance monadTransParserT :: MonadTrans (ParserT s) where
122122

123123
-- | Set the consumed flag.
124124
consume :: forall s m. Monad m => ParserT s m Unit
125-
consume = modify \(ParseState input pos _) ->
125+
consume = modify_ \(ParseState input pos _) ->
126126
ParseState input pos true
127127

128128
-- | Returns the current position in the stream.

src/Text/Parsing/Parser/Combinators.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ import Text.Parsing.Parser (ParseState(..), ParserT(..), ParseError(..), fail)
3636
withErrorMessage :: forall m s a. Monad m => ParserT s m a -> String -> ParserT s m a
3737
withErrorMessage p msg = p <|> fail ("Expected " <> msg)
3838

39-
infix 3 withErrorMessage as <?>
39+
infixl 3 withErrorMessage as <?>
4040

4141
-- | Flipped `(<?>)`.
4242
asErrorMessage :: forall m s a. Monad m => String -> ParserT s m a -> ParserT s m a
4343
asErrorMessage = flip (<?>)
4444

45-
infix 3 asErrorMessage as <??>
45+
infixl 3 asErrorMessage as <??>
4646

4747
-- | Wrap a parser with opening and closing markers.
4848
-- |

src/Text/Parsing/Parser/Expr.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ makeParser term ops = do
6363
prefixOp = choice accum.prefix <?> ""
6464
postfixOp = choice accum.postfix <?> ""
6565

66-
postfixP = postfixOp <|> pure id
67-
prefixP = prefixOp <|> pure id
66+
postfixP = postfixOp <|> pure identity
67+
prefixP = prefixOp <|> pure identity
6868

6969
splitOp :: forall m s a. Operator m s a -> SplitAccum m s a -> SplitAccum m s a
7070
splitOp (Infix op AssocNone) accum = accum { nassoc = op : accum.nassoc }

src/Text/Parsing/Parser/Indent.purs

+4-4
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,16 @@ infixl 12 indentOp as <?/>
204204

205205
-- | Parses with surrounding brackets
206206
indentBrackets :: forall a. IndentParser String a -> IndentParser String a
207-
indentBrackets p = withPos $ pure id <-/> symbol "[" <+/> p <-/> symbol "]"
207+
indentBrackets p = withPos $ pure identity <-/> symbol "[" <+/> p <-/> symbol "]"
208208

209209
-- | Parses with surrounding angle brackets
210210
indentAngles :: forall a. IndentParser String a -> IndentParser String a
211-
indentAngles p = withPos $ pure id <-/> symbol "<" <+/> p <-/> symbol ">"
211+
indentAngles p = withPos $ pure identity <-/> symbol "<" <+/> p <-/> symbol ">"
212212

213213
-- | Parses with surrounding braces
214214
indentBraces :: forall a. IndentParser String a -> IndentParser String a
215-
indentBraces p = withPos $ pure id <-/> symbol "{" <+/> p <-/> symbol "}"
215+
indentBraces p = withPos $ pure identity <-/> symbol "{" <+/> p <-/> symbol "}"
216216

217217
-- | Parses with surrounding parentheses
218218
indentParens :: forall a. IndentParser String a -> IndentParser String a
219-
indentParens p = withPos $ pure id <-/> symbol "(" <+/> p <-/> symbol ")"
219+
indentParens p = withPos $ pure identity <-/> symbol "(" <+/> p <-/> symbol ")"

src/Text/Parsing/Parser/String.purs

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
module Text.Parsing.Parser.String where
44

5-
import Data.String as S
6-
import Control.Monad.State (modify, gets)
5+
import Prelude hiding (between)
6+
7+
import Control.Monad.State (gets, modify_)
78
import Data.Array (many)
89
import Data.Foldable (elem, notElem)
910
import Data.Maybe (Maybe(..))
1011
import Data.Newtype (wrap)
11-
import Data.String (Pattern, fromCharArray, length, singleton)
12+
import Data.String (Pattern, length)
13+
import Data.String as S
14+
import Data.String.CodeUnits as SCU
1215
import Text.Parsing.Parser (ParseState(..), ParserT, fail)
1316
import Text.Parsing.Parser.Combinators (tryRethrow, (<?>))
1417
import Text.Parsing.Parser.Pos (updatePosString)
15-
import Prelude hiding (between)
1618

1719
-- | This class exists to abstract over streams which support the string-like
1820
-- | operations which this modules needs.
@@ -23,7 +25,7 @@ class StringLike s where
2325
uncons :: s -> Maybe { head :: Char, tail :: s }
2426

2527
instance stringLikeString :: StringLike String where
26-
uncons = S.uncons
28+
uncons = SCU.uncons
2729
drop = S.drop
2830
indexOf = S.indexOf
2931
null = S.null
@@ -40,7 +42,7 @@ string str = do
4042
input <- gets \(ParseState input _ _) -> input
4143
case indexOf (wrap str) input of
4244
Just 0 -> do
43-
modify \(ParseState _ position _) ->
45+
modify_ \(ParseState _ position _) ->
4446
ParseState (drop (length str) input)
4547
(updatePosString position str)
4648
true
@@ -54,9 +56,9 @@ anyChar = do
5456
case uncons input of
5557
Nothing -> fail "Unexpected EOF"
5658
Just { head, tail } -> do
57-
modify \(ParseState _ position _) ->
59+
modify_ \(ParseState _ position _) ->
5860
ParseState tail
59-
(updatePosString position (singleton head))
61+
(updatePosString position (SCU.singleton head))
6062
true
6163
pure head
6264

@@ -65,7 +67,7 @@ satisfy :: forall s m. StringLike s => Monad m => (Char -> Boolean) -> ParserT s
6567
satisfy f = tryRethrow do
6668
c <- anyChar
6769
if f c then pure c
68-
else fail $ "Character '" <> singleton c <> "' did not satisfy predicate"
70+
else fail $ "Character '" <> SCU.singleton c <> "' did not satisfy predicate"
6971

7072
-- | Match the specified character
7173
char :: forall s m. StringLike s => Monad m => Char -> ParserT s m Char
@@ -75,7 +77,7 @@ char c = satisfy (_ == c) <?> show c
7577
whiteSpace :: forall s m. StringLike s => Monad m => ParserT s m String
7678
whiteSpace = do
7779
cs <- many $ satisfy \c -> c == '\n' || c == '\r' || c == ' ' || c == '\t'
78-
pure $ fromCharArray cs
80+
pure $ SCU.fromCharArray cs
7981

8082
-- | Skip whitespace characters.
8183
skipSpaces :: forall s m. StringLike s => Monad m => ParserT s m Unit

src/Text/Parsing/Parser/Token.purs

+23-17
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,30 @@ module Text.Parsing.Parser.Token
2121
)
2222
where
2323

24-
import Data.Array as Array
25-
import Data.Char.Unicode as Unicode
26-
import Data.List as List
24+
import Prelude hiding (when,between)
25+
2726
import Control.Lazy (fix)
28-
import Control.Monad.State (modify, gets)
27+
import Control.Monad.State (gets, modify_)
2928
import Control.MonadPlus (guard, (<|>))
29+
import Data.Array as Array
3030
import Data.Char (fromCharCode, toCharCode)
3131
import Data.Char.Unicode (digitToInt, isAlpha, isAlphaNum, isDigit, isHexDigit, isOctDigit, isSpace, isUpper)
32+
import Data.Char.Unicode as Unicode
3233
import Data.Either (Either(..))
3334
import Data.Foldable (foldl, foldr)
3435
import Data.Identity (Identity)
3536
import Data.Int (toNumber)
3637
import Data.List (List(..))
38+
import Data.List as List
3739
import Data.Maybe (Maybe(..), maybe)
38-
import Data.String (toCharArray, null, toLower, fromCharArray, singleton, uncons)
40+
import Data.String (null, toLower)
41+
import Data.String.CodeUnits as SCU
3942
import Data.Tuple (Tuple(..))
4043
import Math (pow)
4144
import Text.Parsing.Parser (ParseState(..), ParserT, fail)
4245
import Text.Parsing.Parser.Combinators (skipMany1, try, tryRethrow, skipMany, notFollowedBy, option, choice, between, sepBy1, sepBy, (<?>), (<??>))
4346
import Text.Parsing.Parser.Pos (Position)
4447
import Text.Parsing.Parser.String (satisfy, oneOf, noneOf, string, char)
45-
import Prelude hiding (when,between)
4648

4749
-- | Create a parser which Returns the first token in the stream.
4850
token :: forall m a. Monad m => (a -> Position) -> ParserT (List a) m a
@@ -51,7 +53,7 @@ token tokpos = do
5153
case List.uncons input of
5254
Nothing -> fail "Unexpected EOF"
5355
Just { head, tail } -> do
54-
modify \(ParseState _ position _) ->
56+
modify_ \(ParseState _ position _) ->
5557
ParseState tail (tokpos head) true
5658
pure head
5759

@@ -397,7 +399,7 @@ makeTokenParser (LanguageDef languageDef)
397399
go :: ParserT String m String
398400
go = do
399401
maybeChars <- between (char '"') (char '"' <?> "end of string") (List.many stringChar)
400-
pure $ fromCharArray $ List.toUnfoldable $ foldr folder Nil maybeChars
402+
pure $ SCU.fromCharArray $ List.toUnfoldable $ foldr folder Nil maybeChars
401403

402404
folder :: Maybe Char -> List Char -> List Char
403405
folder Nothing chars = chars
@@ -432,7 +434,9 @@ makeTokenParser (LanguageDef languageDef)
432434
charControl = do
433435
_ <- char '^'
434436
code <- upper
435-
pure <<< fromCharCode $ toCharCode code - toCharCode 'A' + 1
437+
case fromCharCode (toCharCode code - toCharCode 'A' + 1) of
438+
Just c -> pure c
439+
Nothing -> fail "invalid character code (should not happen)"
436440

437441
charNum :: ParserT String m Char
438442
charNum = do
@@ -441,7 +445,9 @@ makeTokenParser (LanguageDef languageDef)
441445
<|> ( char 'x' *> number 16 hexDigit )
442446
if code > 0x10FFFF
443447
then fail "invalid escape sequence"
444-
else pure $ fromCharCode code
448+
else case fromCharCode code of
449+
Just c -> pure c
450+
Nothing -> fail "invalid character code (should not happen)"
445451

446452
charEsc :: ParserT String m Char
447453
charEsc = choice (map parseEsc escMap)
@@ -567,8 +573,8 @@ makeTokenParser (LanguageDef languageDef)
567573

568574
sign :: forall a . (Ring a) => ParserT String m (a -> a)
569575
sign = (char '-' $> negate)
570-
<|> (char '+' $> id)
571-
<|> pure id
576+
<|> (char '+' $> identity)
577+
<|> pure identity
572578

573579
nat :: ParserT String m Int
574580
nat = zeroNumber <|> decimal
@@ -624,7 +630,7 @@ makeTokenParser (LanguageDef languageDef)
624630
go = do
625631
c <- languageDef.opStart
626632
cs <- Array.many languageDef.opLetter
627-
pure $ singleton c <> fromCharArray cs
633+
pure $ SCU.singleton c <> SCU.fromCharArray cs
628634

629635
isReservedOp :: String -> Boolean
630636
isReservedOp name = isReserved (Array.sort languageDef.reservedOpNames) name
@@ -645,7 +651,7 @@ makeTokenParser (LanguageDef languageDef)
645651
| otherwise = walk name $> name
646652
where
647653
walk :: String -> ParserT String m Unit
648-
walk name' = case uncons name' of
654+
walk name' = case SCU.uncons name' of
649655
Nothing -> pure unit
650656
Just { head: c, tail: cs } -> (caseChar c <?> msg) *> walk cs
651657

@@ -675,7 +681,7 @@ makeTokenParser (LanguageDef languageDef)
675681
go = do
676682
c <- languageDef.identStart
677683
cs <- Array.many languageDef.identLetter
678-
pure $ singleton c <> fromCharArray cs
684+
pure $ SCU.singleton c <> SCU.fromCharArray cs
679685

680686

681687
-----------------------------------------------------------
@@ -757,7 +763,7 @@ inCommentMulti langDef@(LanguageDef languageDef) =
757763
<?> "end of comment"
758764
where
759765
startEnd :: Array Char
760-
startEnd = toCharArray languageDef.commentEnd <> toCharArray languageDef.commentStart
766+
startEnd = SCU.toCharArray languageDef.commentEnd <> SCU.toCharArray languageDef.commentStart
761767

762768
inCommentSingle :: forall m . Monad m => GenLanguageDef String m -> ParserT String m Unit
763769
inCommentSingle (LanguageDef languageDef) =
@@ -767,7 +773,7 @@ inCommentSingle (LanguageDef languageDef) =
767773
<?> "end of comment"
768774
where
769775
startEnd :: Array Char
770-
startEnd = toCharArray languageDef.commentEnd <> toCharArray languageDef.commentStart
776+
startEnd = SCU.toCharArray languageDef.commentEnd <> SCU.toCharArray languageDef.commentStart
771777

772778
-------------------------------------------------------------------------
773779
-- Helper functions that should maybe go in Text.Parsing.Parser.String --

0 commit comments

Comments
 (0)