Skip to content

Commit 6397fae

Browse files
authored
Re-export main API from single module and remove Text.Parsing prefix per #78 (#89)
* Move existing StringParser module to Parser * Re-export other modules in main API * Remove Text.Parsing prefex per #78
1 parent efbe004 commit 6397fae

File tree

13 files changed

+52
-45
lines changed

13 files changed

+52
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88
- Issue #77: Fix CodePoint parser quadratic performance (#83 by @chtenb). The parser now tracks the remaining unparsed substring. This change is breaking, but will trigger compile errors in all places where this definition is used.
99
- Fix semantics of endBy and sepEndBy parser combinators (#84 by @chtenb)
10+
- Issue #78: Remove the Text.Parsing prefix from the modules (#89 by @chtenb)
1011

1112
New features:
1213
- Introduce code point parsers `anyCodePoint`, `codePoint'` and `satisfyCodePoint` (#88 by @chtenb)
@@ -21,6 +22,7 @@ Other improvements:
2122
- Added `purs-tidy` formatter (#76 by @thomashoneyman)
2223
- Add a benchmark module (#79 by @chtenb)
2324
- Run slowest tests last and print status updates (#72)
25+
- Re-export the main API from a single module (StringParser) (#89 by @chtenb)
2426

2527
## [v6.0.1](https://github.com/purescript-contrib/purescript-string-parsers/releases/tag/v6.0.1) - 2021-05-11
2628

bench/Main.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import Data.List.Types (List)
1515
import Effect (Effect)
1616
import Effect.Console (log)
1717
import Performance.Minibench (benchWith)
18-
import Text.Parsing.StringParser (Parser, runParser)
19-
import Text.Parsing.StringParser.CodePoints as StringParser.CodePoints
20-
import Text.Parsing.StringParser.CodeUnits as StringParser.CodeUnits
18+
import StringParser.Parser (Parser, runParser)
19+
import StringParser.CodePoints as StringParser.CodePoints
20+
import StringParser.CodeUnits as StringParser.CodeUnits
2121

2222
string23_100 :: String
2323
string23_100 = fold $ replicate 100 "23"

src/StringParser.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module StringParser
2+
( module StringParser.Parser
3+
, module StringParser.Combinators
4+
, module StringParser.CodePoints
5+
) where
6+
7+
import StringParser.Parser (ParseError, Parser(..), Pos, PosString, fail, printParserError, runParser, unParser)
8+
import StringParser.Combinators (assertConsume, between, chainl, chainl1, chainr, chainr1, choice, endBy, endBy1, fix, lookAhead, many, many1, many1Till, manyTill, option, optionMaybe, optional, sepBy, sepBy1, sepEndBy, sepEndBy1, try, tryAhead, withError, (<?>))
9+
import StringParser.CodePoints (alphaNum, anyChar, anyCodePoint, anyDigit, anyLetter, char, codePoint, eof, lowerCaseChar, noneOf, oneOf, regex, satisfy, satisfyCodePoint, skipSpaces, string, upperCaseChar, whiteSpace)

src/Text/Parsing/StringParser/CodePoints.purs renamed to src/StringParser/CodePoints.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- | These functions will be much slower than the `CodeUnits` alternatives, but
44
-- | will behave correctly in the presence of Unicode characters made up of
55
-- | multiple code units.
6-
module Text.Parsing.StringParser.CodePoints
6+
module StringParser.CodePoints
77
( eof
88
, anyChar
99
, anyCodePoint
@@ -39,9 +39,9 @@ import Data.String.CodePoints as SCP
3939
import Data.String.CodeUnits as SCU
4040
import Data.String.Regex as Regex
4141
import Data.String.Regex.Flags (noFlags)
42-
import Text.Parsing.StringParser (Parser(..), fail)
43-
import Text.Parsing.StringParser.CodeUnits as CodeUnitsParser
44-
import Text.Parsing.StringParser.Combinators (try, many, (<?>))
42+
import StringParser.Parser (Parser(..), fail)
43+
import StringParser.CodeUnits as CodeUnitsParser
44+
import StringParser.Combinators (try, many, (<?>))
4545

4646
-- | Match the end of the file.
4747
eof :: Parser Unit
@@ -157,7 +157,7 @@ regex :: String -> Parser String
157157
regex pat =
158158
case Regex.regex pattern noFlags of
159159
Left _ ->
160-
fail $ "Text.Parsing.StringParser.String.regex': illegal regex " <> pat
160+
fail $ "StringParser.String.regex': illegal regex " <> pat
161161
Right r ->
162162
matchRegex r
163163
where

src/Text/Parsing/StringParser/CodeUnits.purs renamed to src/StringParser/CodeUnits.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- | These functions will be much faster than the `CodePoints` alternatives, but
44
-- | will behave incorrectly when dealing with Unicode characters that consist
55
-- | of multiple code units.
6-
module Text.Parsing.StringParser.CodeUnits
6+
module StringParser.CodeUnits
77
( eof
88
, anyChar
99
, anyDigit
@@ -34,8 +34,8 @@ import Data.String.CodeUnits (charAt, singleton)
3434
import Data.String.CodeUnits as SCU
3535
import Data.String.Regex as Regex
3636
import Data.String.Regex.Flags (noFlags)
37-
import Text.Parsing.StringParser (Parser(..), fail)
38-
import Text.Parsing.StringParser.Combinators (try, many, (<?>))
37+
import StringParser.Parser (Parser(..), fail)
38+
import StringParser.Combinators (try, many, (<?>))
3939

4040
-- | Match the end of the file.
4141
eof :: Parser Unit
@@ -124,7 +124,7 @@ regex :: String -> Parser String
124124
regex pat =
125125
case Regex.regex pattern noFlags of
126126
Left _ ->
127-
fail $ "Text.Parsing.StringParser.String.regex': illegal regex " <> pat
127+
fail $ "StringParser.String.regex': illegal regex " <> pat
128128
Right r ->
129129
matchRegex r
130130
where

src/Text/Parsing/StringParser/Combinators.purs renamed to src/StringParser/Combinators.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- | This module defines combinators for building string parsers.
2-
module Text.Parsing.StringParser.Combinators
2+
module StringParser.Combinators
33
( try
44
, lookAhead
55
, tryAhead
@@ -40,7 +40,7 @@ import Data.List.NonEmpty (NonEmptyList(..))
4040
import Data.List.NonEmpty as NEL
4141
import Data.Maybe (Maybe(..))
4242
import Data.NonEmpty ((:|))
43-
import Text.Parsing.StringParser (Parser(..), fail)
43+
import StringParser.Parser (Parser(..), fail)
4444

4545
-- | `try p` means: run `p` but do not consume input in case of failure.
4646
try :: forall a. Parser a -> Parser a

src/Text/Parsing/StringParser/Expr.purs renamed to src/StringParser/Expr.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- | This module defines helper functions for defining parsers using operator tables.
22

3-
module Text.Parsing.StringParser.Expr
3+
module StringParser.Expr
44
( Assoc(..)
55
, Operator(..)
66
, OperatorTable()
@@ -12,8 +12,8 @@ import Prelude
1212
import Control.Alt ((<|>))
1313
import Data.Foldable (foldl, foldr)
1414
import Data.List (List(..))
15-
import Text.Parsing.StringParser (Parser)
16-
import Text.Parsing.StringParser.Combinators (choice, (<?>))
15+
import StringParser.Parser (Parser)
16+
import StringParser.Combinators (choice, (<?>))
1717

1818
-- | Operator associativity types.
1919
data Assoc = AssocNone | AssocLeft | AssocRight
@@ -57,7 +57,7 @@ buildExprParser operators simpleExpr = do
5757
<|> lassocP x lassocOp prefixP term postfixP
5858
<|> nassocP x nassocOp prefixP term postfixP
5959
<|> pure x
60-
<?> "operator"
60+
<?> "operator"
6161

6262
splitOp :: forall b. Operator b -> SplitAccum b -> SplitAccum b
6363
splitOp (Infix op AssocNone) accum = accum { nassoc = Cons op accum.nassoc }

src/Text/Parsing/StringParser.purs renamed to src/StringParser/Parser.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- | This module defines the `Parser` type of string parsers, and its instances.
22

3-
module Text.Parsing.StringParser where
3+
module StringParser.Parser where
44

55
import Prelude
66

test/BasicSpecs.purs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import Effect.Class.Console (log)
1515
import Partial.Unsafe (unsafePartial)
1616
import Test.Assert (assert')
1717
import Test.Utils (AnyParser(..), mkAnyParser)
18-
import Text.Parsing.StringParser (Parser, runParser)
19-
import Text.Parsing.StringParser.CodePoints (anyChar, anyCodePoint, anyDigit, anyLetter, char, codePoint, eof, skipSpaces, string)
20-
import Text.Parsing.StringParser.Combinators (try, tryAhead, between, chainl, chainl1, endBy, endBy1, lookAhead, many, many1, manyTill, many1Till, optionMaybe, sepBy, sepBy1, sepEndBy, sepEndBy1)
18+
import StringParser (Parser, anyChar, anyCodePoint, anyDigit, anyLetter, between, chainl, chainl1, char, codePoint, endBy, endBy1, eof, lookAhead, many, many1, many1Till, manyTill, optionMaybe, runParser, sepBy, sepBy1, sepEndBy, sepEndBy1, skipSpaces, string, try, tryAhead)
2119

2220
type TestInputs = { successes :: Array String, failures :: Array String }
2321
type TestCase = { name :: String, parser :: AnyParser, inputs :: TestInputs }

test/CodePoints.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import Data.Unfoldable (replicate)
1515
import Effect (Effect)
1616
import Effect.Class.Console (log)
1717
import Test.Assert (assert', assert)
18-
import Text.Parsing.StringParser (ParseError, Parser(..), PosString, runParser)
19-
import Text.Parsing.StringParser.CodePoints (anyDigit, char, eof, string, anyChar, regex)
20-
import Text.Parsing.StringParser.Combinators (try, many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between)
21-
import Text.Parsing.StringParser.Expr (Assoc(..), Operator(..), buildExprParser)
18+
import StringParser.Parser (ParseError, Parser(..), PosString, runParser)
19+
import StringParser.CodePoints (anyDigit, char, eof, string, anyChar, regex)
20+
import StringParser.Combinators (try, many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between)
21+
import StringParser.Expr (Assoc(..), Operator(..), buildExprParser)
2222

2323
parens :: forall a. Parser a -> Parser a
2424
parens = between (string "(") (string ")")

test/CodeUnits.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import Data.Unfoldable (replicate)
1515
import Effect (Effect)
1616
import Effect.Class.Console (log)
1717
import Test.Assert (assert', assert)
18-
import Text.Parsing.StringParser (Parser, runParser)
19-
import Text.Parsing.StringParser.CodeUnits (anyDigit, eof, string, anyChar, regex)
20-
import Text.Parsing.StringParser.Combinators (try, many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between)
21-
import Text.Parsing.StringParser.Expr (Assoc(..), Operator(..), buildExprParser)
18+
import StringParser.Parser (Parser, runParser)
19+
import StringParser.CodeUnits (anyDigit, eof, string, anyChar, regex)
20+
import StringParser.Combinators (try, many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between)
21+
import StringParser.Expr (Assoc(..), Operator(..), buildExprParser)
2222

2323
parens :: forall a. Parser a -> Parser a
2424
parens = between (string "(") (string ")")

test/Examples.purs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Text.Parsing.StringParser.Examples where
1+
module StringParser.Examples where
22

33
import Prelude hiding (between)
44

@@ -8,9 +8,7 @@ import Data.Foldable (fold, foldl, sum)
88
import Data.List.Types (NonEmptyList)
99
import Effect (Effect)
1010
import Effect.Console (log, logShow)
11-
import Text.Parsing.StringParser (Parser, fail, runParser, unParser)
12-
import Text.Parsing.StringParser.CodePoints (anyChar, char, eof, regex, skipSpaces, string)
13-
import Text.Parsing.StringParser.Combinators (between, lookAhead, endBy1, many, many1, sepBy1, (<?>))
11+
import StringParser (Parser, anyChar, between, char, endBy1, eof, fail, lookAhead, many, many1, regex, runParser, sepBy1, skipSpaces, string, unParser, (<?>))
1412

1513
-- Serves only to make this file runnable
1614
main :: Effect Unit
@@ -95,14 +93,14 @@ extractWords = do
9593
( many1
9694
( string " " <?> "Failed to match space as a separator"
9795
<|> string "'"
98-
<?> "Failed to match single-quote char as a separator"
96+
<?> "Failed to match single-quote char as a separator"
9997
<|> string ","
100-
<?> "Failed to match comma as a separator"
98+
<?> "Failed to match comma as a separator"
10199
<|> string "?"
102-
<?> "Failed to match question mark as a separator"
100+
<?> "Failed to match question mark as a separator"
103101
<|> string "."
104-
<?> "Failed to match period as a separator"
105-
<?> "Could not find a character that separated the content..."
102+
<?> "Failed to match period as a separator"
103+
<?> "Could not find a character that separated the content..."
106104
)
107105
)
108106

@@ -113,12 +111,12 @@ badExtractWords = do
113111
( many1
114112
( string " " <?> "Failed to match space as a separator"
115113
<|> string "'"
116-
<?> "Failed to match single-quote char as a separator"
114+
<?> "Failed to match single-quote char as a separator"
117115
<|> string ","
118-
<?> "Failed to match comma as a separator"
119-
-- <|> string "?" <?> "Failed to match question mark as a separator"
120-
-- <|> string "." <?> "Failed to match period as a separator"
121-
<?> "Could not find a character that separated the content..."
116+
<?> "Failed to match comma as a separator"
117+
-- <|> string "?" <?> "Failed to match question mark as a separator"
118+
-- <|> string "." <?> "Failed to match period as a separator"
119+
<?> "Could not find a character that separated the content..."
122120
)
123121
)
124122
-- short for 'end of file' or 'end of content'

test/Utils.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Test.Utils where
22

3-
import Text.Parsing.StringParser (Parser)
3+
import StringParser.Parser (Parser)
44

55
newtype AnyParser = AnyParser (forall r. (forall a. Parser a -> r) -> r)
66

0 commit comments

Comments
 (0)