Skip to content

Rename Text.Parsing.Parser to Parsing #169

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 3 commits into from
Mar 31, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Breaking changes:
`<|>` was made right associative. Decreasing these two operators
prevents a compiler error (i.e. `MixedAssociativityError`)
without causing issues with `<$>`.
- Rename module prefix from `Text.Parsing.Parser` to `Parsing` (#169 by @jamesdbrock)

New features:

Expand Down
6 changes: 3 additions & 3 deletions bench/Json/Parsing.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import Data.List (List)
import Data.Maybe (Maybe(..))
import Data.Number as Number
import Data.Tuple (Tuple(..))
import Text.Parsing.Parser (ParserT, fail)
import Text.Parsing.Parser.Combinators (between, choice, sepBy, try)
import Text.Parsing.Parser.String (regex, skipSpaces, string)
import Parsing (ParserT, fail)
import Parsing.Combinators (between, choice, sepBy, try)
import Parsing.String (regex, skipSpaces, string)

json :: forall m. Monad m => ParserT String m Json
json = defer \_ ->
Expand Down
6 changes: 3 additions & 3 deletions bench/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ import Effect.Console (log)
import Effect.Exception (throw)
import Effect.Unsafe (unsafePerformEffect)
import Performance.Minibench (benchWith)
import Text.Parsing.Parser (Parser, runParser, runParserT)
import Text.Parsing.Parser.String (string)
import Text.Parsing.Parser.String.Basic (digit)
import Parsing (Parser, runParser, runParserT)
import Parsing.String (string)
import Parsing.String.Basic (digit)
import StringParser as StringParser
import StringParser.CodePoints as StringParser.CodePoints
import StringParser.CodeUnits as StringParser.CodeUnits
Expand Down
4 changes: 2 additions & 2 deletions src/Text/Parsing/Parser.purs → src/Parsing.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Text.Parsing.Parser
module Parsing
( ParseError(..)
, parseErrorMessage
, parseErrorPosition
Expand Down Expand Up @@ -33,7 +33,7 @@ import Data.Identity (Identity)
import Data.Lazy as Lazy
import Data.Newtype (unwrap)
import Data.Tuple (Tuple(..), fst)
import Text.Parsing.Parser.Pos (Position, initialPos)
import Parsing.Pos (Position, initialPos)

-- | A parsing error, consisting of a message and position information.
data ParseError = ParseError String Position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
-- | return a parser `replicateA n p :: Parser s (Array a)` which will
-- | repeat parser `p` exactly `n` times. `replicateA n p` will only succeed
-- | if it can match parser `p` exactly `n` consecutive times.
module Text.Parsing.Parser.Combinators
module Parsing.Combinators
( (<?>)
, (<??>)
, (<~?>)
Expand Down Expand Up @@ -110,7 +110,7 @@ import Data.Tuple (Tuple(..))
import Data.Tuple.Nested (type (/\), (/\))
import Data.Unfoldable (replicateA)
import Data.Unfoldable1 (replicate1A)
import Text.Parsing.Parser (ParseError(..), ParseState(..), ParserT(..), fail)
import Parsing (ParseError(..), ParseState(..), ParserT(..), fail)

-- | Provide an error message in the case of failure.
withErrorMessage :: forall m s a. ParserT s m a -> String -> ParserT s m a
Expand Down
6 changes: 3 additions & 3 deletions src/Text/Parsing/Parser/Expr.purs → src/Parsing/Expr.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- | [__Text.Parsec.Expr__](https://hackage.haskell.org/package/parsec/docs/Text-Parsec-Expr.html)
-- | module.

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

data Assoc = AssocNone | AssocLeft | AssocRight

Expand Down
28 changes: 11 additions & 17 deletions src/Text/Parsing/Parser/Indent.purs → src/Parsing/Indent.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
-- | a sequence of lines need to be /folded/ to a single line. An example
-- | is MIME headers. Line folding based binding separation is used in
-- | Haskell as well.
module Text.Parsing.Indent
module Parsing.Indent
( IndentParser
, runIndent
, withBlock
Expand Down Expand Up @@ -61,25 +61,20 @@ import Prelude

import Control.Alt ((<|>))
import Control.Apply (lift2)
import Control.Monad.State (State, evalState, gets)
import Control.Monad.State (State, evalState)
import Control.Monad.State.Trans (get, put)
import Control.Monad.Trans.Class (lift)
import Data.List (List(..), many)
import Data.Maybe (Maybe(..))
import Text.Parsing.Parser (ParseState(ParseState), ParserT, fail)
import Text.Parsing.Parser.Combinators (option, optionMaybe)
import Text.Parsing.Parser.Pos (Position(..), initialPos)
import Text.Parsing.Parser.String (oneOf, string)
import Parsing (ParserT, fail, position)
import Parsing.Combinators (option, optionMaybe)
import Parsing.Pos (Position(..), initialPos)
import Parsing.String (oneOf, string)

-- | Indentation sensitive parser type. Usually @ m @ will
-- | be @ Identity @ as with any @ ParserT @
type IndentParser s a = ParserT s (State Position) a

-- | @ getPosition @ returns current position
-- | should probably be added to Text.Parsing.Parser.Pos
getPosition :: forall m s. ParserT s m Position
getPosition = gets \(ParseState _ pos _) -> pos

-- | simple helper function to avoid typ-problems with MonadState instance
get' :: forall s. IndentParser s Position
get' = do
Expand All @@ -102,7 +97,6 @@ setSourceLine (Position { line: _, column: c }) l = Position { line: l, column:
biAp :: forall a b c. (a -> b) -> (b -> b -> c) -> a -> a -> c
biAp f c v1 v2 = c (f v1) (f v2)

-- | @ many1 @ should prabably be inside Text.Parsing.Parser.Combinators
many1 :: forall s m a. ParserT s m a -> ParserT s m (List a)
many1 p = lift2 Cons p (many p)

Expand All @@ -127,7 +121,7 @@ withBlock' = withBlock (flip const)
-- | Parses only when indented past the level of the reference
indented :: forall s. IndentParser s Unit
indented = do
pos <- getPosition
pos <- position
s <- get'
if biAp sourceColumn (<=) pos s then fail "not indented"
else do
Expand All @@ -137,7 +131,7 @@ indented = do
-- | Same as `indented`, but does not change internal state
indented' :: forall s. IndentParser s Unit
indented' = do
pos <- getPosition
pos <- position
s <- get'
if biAp sourceColumn (<=) pos s then fail "not indented" else pure unit

Expand All @@ -148,7 +142,7 @@ sameOrIndented = sameLine <|> indented
-- | Parses only on the same line as the reference
sameLine :: forall s. IndentParser s Unit
sameLine = do
pos <- getPosition
pos <- position
s <- get'
if biAp sourceLine (==) pos s then pure unit else fail "over one line"

Expand All @@ -168,15 +162,15 @@ block p = withPos $ do
withPos :: forall s a. IndentParser s a -> IndentParser s a
withPos x = do
a <- get'
p <- getPosition
p <- position
r <- put' p *> x
put' a *> pure r

-- | Ensures the current indentation level matches that of the reference
checkIndent :: forall s. IndentParser s Unit
checkIndent = do
s <- get'
p <- getPosition
p <- position
if biAp sourceColumn (==) p s then pure unit else fail "indentation doesn't match"

-- | Run the result of an indentation sensitive parse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- | This module is a port of the Haskell
-- | [__Text.Parsec.Language__](https://hackage.haskell.org/package/parsec/docs/Text-Parsec-Language.html)
-- | module.
module Text.Parsing.Parser.Language
module Parsing.Language
( haskellDef
, haskell
, emptyDef
Expand All @@ -12,10 +12,10 @@ module Text.Parsing.Parser.Language
import Prelude

import Control.Alt ((<|>))
import Text.Parsing.Parser (ParserT)
import Text.Parsing.Parser.String (char, oneOf)
import Text.Parsing.Parser.String.Basic (alphaNum, letter)
import Text.Parsing.Parser.Token (GenLanguageDef(..), LanguageDef, TokenParser, makeTokenParser, unGenLanguageDef)
import Parsing (ParserT)
import Parsing.String (char, oneOf)
import Parsing.String.Basic (alphaNum, letter)
import Parsing.Token (GenLanguageDef(..), LanguageDef, TokenParser, makeTokenParser, unGenLanguageDef)

-----------------------------------------------------------
-- Styles: haskellStyle, javaStyle
Expand Down
2 changes: 1 addition & 1 deletion src/Text/Parsing/Parser/Pos.purs → src/Parsing/Pos.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Text.Parsing.Parser.Pos where
module Parsing.Pos where

import Prelude

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
-- | The other primitive parsers, which return `CodePoint` and `String` types,
-- | can parse the full Unicode character set. All of the primitive parsers
-- | in this module can be used together.
module Text.Parsing.Parser.String
module Parsing.String
( string
, eof
, rest
Expand Down Expand Up @@ -60,9 +60,9 @@ import Data.Tuple (Tuple(..), fst)
import Partial.Unsafe (unsafePartial)
import Prim.Row (class Nub, class Union)
import Record (merge)
import Text.Parsing.Parser (ParseError(..), ParseState(..), ParserT(..), fail)
import Text.Parsing.Parser.Combinators ((<?>), (<~?>))
import Text.Parsing.Parser.Pos (Position(..))
import Parsing (ParseError(..), ParseState(..), ParserT(..), fail)
import Parsing.Combinators ((<?>), (<~?>))
import Parsing.Pos (Position(..))

-- | Match “end-of-file,” the end of the input stream.
eof :: forall m. ParserT String m Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
-- | Note: In the future, the
-- | __noneOf__, __noneOfCodePoints__, __oneOf__, __oneOfCodePoints__, __skipSpaces__, __whiteSpace__
-- | should be moved into this module and removed from the
-- | __Text.Parsing.Parser.String__ module, because they are not primitive parsers.
module Text.Parsing.Parser.String.Basic
-- | __Parsing.String__ module, because they are not primitive parsers.
module Parsing.String.Basic
( digit
, hexDigit
, octDigit
Expand All @@ -15,7 +15,7 @@ module Text.Parsing.Parser.String.Basic
, alphaNum
, intDecimal
, number
, module Text.Parsing.Parser.String
, module Parsing.String
) where

import Prelude
Expand All @@ -28,10 +28,10 @@ import Data.Number as Data.Number
import Data.String (CodePoint)
import Data.String.CodePoints (codePointFromChar)
import Data.Tuple (Tuple(..))
import Text.Parsing.Parser (ParserT, fail)
import Text.Parsing.Parser.Combinators (choice, skipMany, (<?>))
import Text.Parsing.Parser.String (noneOf, noneOfCodePoints, oneOf, oneOfCodePoints, skipSpaces, whiteSpace)
import Text.Parsing.Parser.String as Parser.String
import Parsing (ParserT, fail)
import Parsing.Combinators (choice, skipMany, (<?>))
import Parsing.String (noneOf, noneOfCodePoints, oneOf, oneOfCodePoints, skipSpaces, whiteSpace)
import Parsing.String as Parser.String

-- | Parse a digit. Matches any char that satisfies `Data.CodePoint.Unicode.isDecDigit`.
digit :: forall m. ParserT String m Char
Expand Down
22 changes: 11 additions & 11 deletions src/Text/Parsing/Parser/Token.purs → src/Parsing/Token.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- | [__Text.Parsec.Token__](https://hackage.haskell.org/package/parsec/docs/Text-Parsec-Token.html)
-- | module.

module Text.Parsing.Parser.Token
module Parsing.Token
( token
, when
, match
Expand All @@ -17,7 +17,7 @@ module Text.Parsing.Parser.Token
, TokenParser
, GenTokenParser
, makeTokenParser
, module Text.Parsing.Parser.String.Basic
, module Parsing.String.Basic
) where

import Prelude hiding (between, when)
Expand All @@ -43,12 +43,12 @@ import Data.String.CodeUnits (singleton, toChar) as CodeUnits
import Data.String.CodeUnits as SCU
import Data.String.Unicode as Unicode
import Data.Tuple (Tuple(..))
import Text.Parsing.Parser (ParseState(..), ParserT, consume, fail)
import Text.Parsing.Parser.Combinators (between, choice, notFollowedBy, option, sepBy, sepBy1, skipMany, skipMany1, try, tryRethrow, (<?>), (<??>))
import Text.Parsing.Parser.Pos (Position)
import Text.Parsing.Parser.String (char, noneOf, oneOf, satisfy, satisfyCodePoint, string)
import Text.Parsing.Parser.String.Basic as Basic
import Text.Parsing.Parser.String.Basic (digit, hexDigit, octDigit, upper, space, letter, alphaNum)
import Parsing (ParseState(..), ParserT, consume, fail)
import Parsing.Combinators (between, choice, notFollowedBy, option, sepBy, sepBy1, skipMany, skipMany1, try, tryRethrow, (<?>), (<??>))
import Parsing.Pos (Position)
import Parsing.String (char, noneOf, oneOf, satisfy, satisfyCodePoint, string)
import Parsing.String.Basic as Basic
import Parsing.String.Basic (digit, hexDigit, octDigit, upper, space, letter, alphaNum)

-- | A parser which returns the first token in the stream.
token :: forall m a. (a -> Position) -> ParserT (List a) m a
Expand Down Expand Up @@ -338,8 +338,8 @@ type GenTokenParser s m =
-- | ```purescript
-- | module Main where
-- |
-- | import Text.Parsing.Parser.Language (haskellDef)
-- | import Text.Parsing.Parser.Token (makeTokenParser)
-- | import Parsing.Language (haskellDef)
-- | import Parsing.Token (makeTokenParser)
-- |
-- | -- The parser
-- | expr = parens expr
Expand Down Expand Up @@ -688,7 +688,7 @@ makeTokenParser (LanguageDef languageDef) =
zeroNumber =
char '0'
*> (hexadecimal <|> octal <|> decimal <|> pure 0)
<?> ""
<?> ""

decimal :: ParserT String m Int
decimal = number 10 Basic.digit
Expand Down
40 changes: 21 additions & 19 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import Effect (Effect)
import Effect.Console (logShow)
import Partial.Unsafe (unsafePartial)
import Test.Assert (assert')
import Text.Parsing.Parser (ParseError(..), Parser, ParserT, fail, parseErrorMessage, parseErrorPosition, position, region, runParser)
import Text.Parsing.Parser.Combinators (between, chainl, chainl1Rec, chainlRec, chainr1Rec, chainrRec, choice, endBy1, endBy1Rec, endByRec, many1Rec, many1TillRec, many1TillRec_, many1Till_, manyTillRec, manyTillRec_, manyTill_, notFollowedBy, optionMaybe, sepBy1, sepBy1Rec, sepByRec, sepEndBy1Rec, sepEndByRec, skipMany1Rec, skipManyRec, try, (<?>), (<??>), (<~?>))
import Text.Parsing.Parser.Expr (Assoc(..), Operator(..), buildExprParser)
import Text.Parsing.Parser.Language (haskellDef, haskellStyle, javaStyle)
import Text.Parsing.Parser.Pos (Position(..), initialPos)
import Text.Parsing.Parser.String (anyChar, anyCodePoint, char, eof, noneOfCodePoints, oneOfCodePoints, regex, rest, satisfy, string, takeN, whiteSpace)
import Text.Parsing.Parser.String.Basic (intDecimal, number, letter)
import Text.Parsing.Parser.Token (TokenParser, makeTokenParser, match, token, when)
import Text.Parsing.Parser.Token as Parser.Token
import Parsing (ParseError(..), Parser, ParserT, fail, parseErrorMessage, parseErrorPosition, position, region, runParser)
import Parsing.Combinators (between, chainl, chainl1Rec, chainlRec, chainr1Rec, chainrRec, choice, endBy1, endBy1Rec, endByRec, many1Rec, many1TillRec, many1TillRec_, many1Till_, manyTillRec, manyTillRec_, manyTill_, notFollowedBy, optionMaybe, sepBy1, sepBy1Rec, sepByRec, sepEndBy1Rec, sepEndByRec, skipMany1Rec, skipManyRec, try, (<?>), (<??>), (<~?>))
import Parsing.Expr (Assoc(..), Operator(..), buildExprParser)
import Parsing.Language (haskellDef, haskellStyle, javaStyle)
import Parsing.Pos (Position(..), initialPos)
import Parsing.String (anyChar, anyCodePoint, char, eof, noneOfCodePoints, oneOfCodePoints, regex, rest, satisfy, string, takeN, whiteSpace)
import Parsing.String.Basic (intDecimal, number, letter)
import Parsing.Token (TokenParser, makeTokenParser, match, token, when)
import Parsing.Token as Parser.Token

parens :: forall m a. ParserT String m a -> ParserT String m a
parens = between (string "(") (string ")")
Expand Down Expand Up @@ -694,10 +694,10 @@ main = do
<|> const "" <$> string " " <?> "7"
<* string " "
$> ""
<?> "8"
<?> "8"
*> string " "
$> ""
<?> "9"
<?> "9"
, fail "test <~?>"
, string " " <~?> \_ -> "21"
, string " " <|> string " " <~?> \_ -> "22"
Expand All @@ -707,21 +707,23 @@ main = do
<|> const "" <$> string " " <~?> (\_ -> "27")
<* string " "
$> ""
<~?> (\_ -> "28")
<~?> (\_ -> "28")
Copy link
Contributor

@natefaubion natefaubion Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to update the tidy-operators file. That's why all this formatting changed.

*> string " "
$> ""
<~?> \_ -> "29"
<~?> \_ -> "29"
, fail "test <??>"
, "41" <??> string " "
, "42" <??> string " " <|> string " "
, "43" <??> string " " <|> "44" <??> string " "
, "45" <??> "" <$ string " "
<|> "46"
<??> string " " $> ""
<|> "47"
<??> const "" <$> string " "
<* ("48" <??> string " ")
*> ("49" <??> string " ")
<|>
"46"
<??> string " " $> ""
<|>
"47"
<??> const "" <$> string " "
<* ("48" <??> string " ")
*> ("49" <??> string " ")
]
)
"no"
Expand Down