Skip to content

Re-export main API from single module and remove Text.Parsing prefix per #78 #89

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

Merged
merged 8 commits into from
Mar 8, 2022
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 @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:
- 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.
- Fix semantics of endBy and sepEndBy parser combinators (#84 by @chtenb)
- Issue #78: Remove the Text.Parsing prefix from the modules (#89 by @chtenb)

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

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

Expand Down
6 changes: 3 additions & 3 deletions bench/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import Data.List.Types (List)
import Effect (Effect)
import Effect.Console (log)
import Performance.Minibench (benchWith)
import Text.Parsing.StringParser (Parser, runParser)
import Text.Parsing.StringParser.CodePoints as StringParser.CodePoints
import Text.Parsing.StringParser.CodeUnits as StringParser.CodeUnits
import StringParser.Parser (Parser, runParser)
import StringParser.CodePoints as StringParser.CodePoints
import StringParser.CodeUnits as StringParser.CodeUnits

string23_100 :: String
string23_100 = fold $ replicate 100 "23"
Expand Down
9 changes: 9 additions & 0 deletions src/StringParser.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module StringParser
( module StringParser.Parser
, module StringParser.Combinators
, module StringParser.CodePoints
) where

import StringParser.Parser (ParseError, Parser(..), Pos, PosString, fail, printParserError, runParser, unParser)
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, (<?>))
import StringParser.CodePoints (alphaNum, anyChar, anyCodePoint, anyDigit, anyLetter, char, codePoint, eof, lowerCaseChar, noneOf, oneOf, regex, satisfy, satisfyCodePoint, skipSpaces, string, upperCaseChar, whiteSpace)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- | These functions will be much slower than the `CodeUnits` alternatives, but
-- | will behave correctly in the presence of Unicode characters made up of
-- | multiple code units.
module Text.Parsing.StringParser.CodePoints
module StringParser.CodePoints
( eof
, anyChar
, anyCodePoint
Expand Down Expand Up @@ -39,9 +39,9 @@ import Data.String.CodePoints as SCP
import Data.String.CodeUnits as SCU
import Data.String.Regex as Regex
import Data.String.Regex.Flags (noFlags)
import Text.Parsing.StringParser (Parser(..), fail)
import Text.Parsing.StringParser.CodeUnits as CodeUnitsParser
import Text.Parsing.StringParser.Combinators (try, many, (<?>))
import StringParser.Parser (Parser(..), fail)
import StringParser.CodeUnits as CodeUnitsParser
import StringParser.Combinators (try, many, (<?>))

-- | Match the end of the file.
eof :: Parser Unit
Expand Down Expand Up @@ -157,7 +157,7 @@ regex :: String -> Parser String
regex pat =
case Regex.regex pattern noFlags of
Left _ ->
fail $ "Text.Parsing.StringParser.String.regex': illegal regex " <> pat
fail $ "StringParser.String.regex': illegal regex " <> pat
Right r ->
matchRegex r
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- | These functions will be much faster than the `CodePoints` alternatives, but
-- | will behave incorrectly when dealing with Unicode characters that consist
-- | of multiple code units.
module Text.Parsing.StringParser.CodeUnits
module StringParser.CodeUnits
( eof
, anyChar
, anyDigit
Expand Down Expand Up @@ -34,8 +34,8 @@ import Data.String.CodeUnits (charAt, singleton)
import Data.String.CodeUnits as SCU
import Data.String.Regex as Regex
import Data.String.Regex.Flags (noFlags)
import Text.Parsing.StringParser (Parser(..), fail)
import Text.Parsing.StringParser.Combinators (try, many, (<?>))
import StringParser.Parser (Parser(..), fail)
import StringParser.Combinators (try, many, (<?>))

-- | Match the end of the file.
eof :: Parser Unit
Expand Down Expand Up @@ -124,7 +124,7 @@ regex :: String -> Parser String
regex pat =
case Regex.regex pattern noFlags of
Left _ ->
fail $ "Text.Parsing.StringParser.String.regex': illegal regex " <> pat
fail $ "StringParser.String.regex': illegal regex " <> pat
Right r ->
matchRegex r
where
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- | This module defines combinators for building string parsers.
module Text.Parsing.StringParser.Combinators
module StringParser.Combinators
( try
, lookAhead
, tryAhead
Expand Down Expand Up @@ -40,7 +40,7 @@ import Data.List.NonEmpty (NonEmptyList(..))
import Data.List.NonEmpty as NEL
import Data.Maybe (Maybe(..))
import Data.NonEmpty ((:|))
import Text.Parsing.StringParser (Parser(..), fail)
import StringParser.Parser (Parser(..), fail)

-- | `try p` means: run `p` but do not consume input in case of failure.
try :: forall a. Parser a -> Parser a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- | This module defines helper functions for defining parsers using operator tables.

module Text.Parsing.StringParser.Expr
module StringParser.Expr
( Assoc(..)
, Operator(..)
, OperatorTable()
Expand All @@ -12,8 +12,8 @@ import Prelude
import Control.Alt ((<|>))
import Data.Foldable (foldl, foldr)
import Data.List (List(..))
import Text.Parsing.StringParser (Parser)
import Text.Parsing.StringParser.Combinators (choice, (<?>))
import StringParser.Parser (Parser)
import StringParser.Combinators (choice, (<?>))

-- | Operator associativity types.
data Assoc = AssocNone | AssocLeft | AssocRight
Expand Down Expand Up @@ -57,7 +57,7 @@ buildExprParser operators simpleExpr = do
<|> lassocP x lassocOp prefixP term postfixP
<|> nassocP x nassocOp prefixP term postfixP
<|> pure x
<?> "operator"
<?> "operator"

splitOp :: forall b. Operator b -> SplitAccum b -> SplitAccum b
splitOp (Infix op AssocNone) accum = accum { nassoc = Cons op accum.nassoc }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- | This module defines the `Parser` type of string parsers, and its instances.

module Text.Parsing.StringParser where
module StringParser.Parser where

import Prelude

Expand Down
4 changes: 1 addition & 3 deletions test/BasicSpecs.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import Effect.Class.Console (log)
import Partial.Unsafe (unsafePartial)
import Test.Assert (assert')
import Test.Utils (AnyParser(..), mkAnyParser)
import Text.Parsing.StringParser (Parser, runParser)
import Text.Parsing.StringParser.CodePoints (anyChar, anyCodePoint, anyDigit, anyLetter, char, codePoint, eof, skipSpaces, string)
import Text.Parsing.StringParser.Combinators (try, tryAhead, between, chainl, chainl1, endBy, endBy1, lookAhead, many, many1, manyTill, many1Till, optionMaybe, sepBy, sepBy1, sepEndBy, sepEndBy1)
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)

type TestInputs = { successes :: Array String, failures :: Array String }
type TestCase = { name :: String, parser :: AnyParser, inputs :: TestInputs }
Expand Down
8 changes: 4 additions & 4 deletions test/CodePoints.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import Data.Unfoldable (replicate)
import Effect (Effect)
import Effect.Class.Console (log)
import Test.Assert (assert', assert)
import Text.Parsing.StringParser (ParseError, Parser(..), PosString, runParser)
import Text.Parsing.StringParser.CodePoints (anyDigit, char, eof, string, anyChar, regex)
import Text.Parsing.StringParser.Combinators (try, many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between)
import Text.Parsing.StringParser.Expr (Assoc(..), Operator(..), buildExprParser)
import StringParser.Parser (ParseError, Parser(..), PosString, runParser)
import StringParser.CodePoints (anyDigit, char, eof, string, anyChar, regex)
import StringParser.Combinators (try, many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between)
import StringParser.Expr (Assoc(..), Operator(..), buildExprParser)

parens :: forall a. Parser a -> Parser a
parens = between (string "(") (string ")")
Expand Down
8 changes: 4 additions & 4 deletions test/CodeUnits.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import Data.Unfoldable (replicate)
import Effect (Effect)
import Effect.Class.Console (log)
import Test.Assert (assert', assert)
import Text.Parsing.StringParser (Parser, runParser)
import Text.Parsing.StringParser.CodeUnits (anyDigit, eof, string, anyChar, regex)
import Text.Parsing.StringParser.Combinators (try, many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between)
import Text.Parsing.StringParser.Expr (Assoc(..), Operator(..), buildExprParser)
import StringParser.Parser (Parser, runParser)
import StringParser.CodeUnits (anyDigit, eof, string, anyChar, regex)
import StringParser.Combinators (try, many1, endBy1, sepBy1, optionMaybe, many, manyTill, many1Till, chainl, fix, between)
import StringParser.Expr (Assoc(..), Operator(..), buildExprParser)

parens :: forall a. Parser a -> Parser a
parens = between (string "(") (string ")")
Expand Down
26 changes: 12 additions & 14 deletions test/Examples.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Text.Parsing.StringParser.Examples where
module StringParser.Examples where

import Prelude hiding (between)

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

-- Serves only to make this file runnable
main :: Effect Unit
Expand Down Expand Up @@ -95,14 +93,14 @@ extractWords = do
( many1
( string " " <?> "Failed to match space as a separator"
<|> string "'"
<?> "Failed to match single-quote char as a separator"
<?> "Failed to match single-quote char as a separator"
<|> string ","
<?> "Failed to match comma as a separator"
<?> "Failed to match comma as a separator"
<|> string "?"
<?> "Failed to match question mark as a separator"
<?> "Failed to match question mark as a separator"
<|> string "."
<?> "Failed to match period as a separator"
<?> "Could not find a character that separated the content..."
<?> "Failed to match period as a separator"
<?> "Could not find a character that separated the content..."
)
)

Expand All @@ -113,12 +111,12 @@ badExtractWords = do
( many1
( string " " <?> "Failed to match space as a separator"
<|> string "'"
<?> "Failed to match single-quote char as a separator"
<?> "Failed to match single-quote char as a separator"
<|> string ","
<?> "Failed to match comma as a separator"
-- <|> string "?" <?> "Failed to match question mark as a separator"
-- <|> string "." <?> "Failed to match period as a separator"
<?> "Could not find a character that separated the content..."
<?> "Failed to match comma as a separator"
-- <|> string "?" <?> "Failed to match question mark as a separator"
-- <|> string "." <?> "Failed to match period as a separator"
<?> "Could not find a character that separated the content..."
)
)
-- short for 'end of file' or 'end of content'
Expand Down
2 changes: 1 addition & 1 deletion test/Utils.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Test.Utils where

import Text.Parsing.StringParser (Parser)
import StringParser.Parser (Parser)

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

Expand Down