Skip to content

Fix other <|> breakage #164

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 17 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Cache PureScript dependencies
uses: actions/cache@v2
with:
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}-2
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this change about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It busted CI cache, so that it would get the master version of control where <|> is right-associative. Without it, it uses the old cache where <|> is still left-associative.

path: |
.spago
output
Expand Down
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:
- Update project and deps to PureScript v0.15.0 (#160 by @JordanMartinez)
- Drop deprecated `MonadZero` instance (#160 by @JordanMartinez)
- Make `<?>` right-associative and increase prec from 3 to 2 (#163 by @JordanMartinez)
- Make `<??>` right-associative (#164 by @JordanMartinez)
- Drop `<?>` and `<~?>` prec from 3 to 4 (#163, #164 by @JordanMartinez)

`<|>` was made right associative. `<?>` was likewise changed to prevent a
possible error and its precedence was increased so that `foo <|> bar <?> "err msg"`
works without parenthesis around `"err msg"` part.
`<|>` was made right associative. Decreasing these two operators
prevents a compiler error (i.e. `MixedAssociativityError`)
without causing issues with `<$>`.

New features:

Expand Down
6 changes: 3 additions & 3 deletions src/Text/Parsing/Parser/Combinators.purs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ import Text.Parsing.Parser (ParseError(..), ParseState(..), ParserT(..), fail)
withErrorMessage :: forall m s a. Monad m => ParserT s m a -> String -> ParserT s m a
withErrorMessage p msg = p <|> fail ("Expected " <> msg)

infixr 2 withErrorMessage as <?>
infixl 4 withErrorMessage as <?>

-- | Provide an error message in the case of failure, but lazily. This is handy
-- | in cases where constructing the error message is expensive, so it's
Expand All @@ -132,13 +132,13 @@ infixr 2 withErrorMessage as <?>
withLazyErrorMessage :: forall m s a. Monad m => ParserT s m a -> (Unit -> String) -> ParserT s m a
withLazyErrorMessage p msg = p <|> defer \_ -> fail ("Expected " <> msg unit)

infixl 3 withLazyErrorMessage as <~?>
infixl 4 withLazyErrorMessage as <~?>

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

infixl 3 asErrorMessage as <??>
infixr 3 asErrorMessage as <??>

-- | Wrap a parser with opening and closing markers.
-- |
Expand Down
40 changes: 39 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Effect.Console (logShow)
import Partial.Unsafe (unsafePartial)
import Test.Assert (assert')
import Text.Parsing.Parser (ParseError(..), Parser, ParserT, parseErrorMessage, parseErrorPosition, position, region, runParser)
import Text.Parsing.Parser.Combinators (between, chainl, chainl1Rec, chainlRec, chainr1Rec, chainrRec, endBy1, endBy1Rec, endByRec, many1Rec, many1TillRec, many1TillRec_, many1Till_, manyTillRec, manyTillRec_, manyTill_, notFollowedBy, optionMaybe, sepBy1, sepBy1Rec, sepByRec, sepEndBy1Rec, sepEndByRec, skipMany1Rec, skipManyRec, try)
import Text.Parsing.Parser.Combinators (between, chainl, chainl1Rec, chainlRec, chainr1Rec, chainrRec, 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)
Expand Down Expand Up @@ -671,6 +671,44 @@ main = do
parseTest "-6.0" (-6.0) number
parseTest "+6.0" (6.0) number

-- test from issue #161
parseErrorTestMessage
(string " " <?> "failure")
"no"
"Expected failure"
parseErrorTestMessage
(string " " <|> string "-" <?> "failure")
"no"
"Expected failure"
parseErrorTestMessage
(string " " <?> "bad" <|> string "-" <?> "failure")
"no"
"Expected failure"
parseErrorTestMessage
(string " " <~?> \_ -> "failure")
"no"
"Expected failure"
parseErrorTestMessage
(string " " <|> string "-" <~?> \_ -> "failure")
"no"
"Expected failure"
parseErrorTestMessage
(string " " <~?> (\_ -> "bad") <|> string "-" <~?> \_ -> "failure")
"no"
"Expected failure"
parseErrorTestMessage
("failure" <??> string " ")
"no"
"Expected failure"
parseErrorTestMessage
("failure" <??> string " " <|> string "-")
"no"
"Expected failure"
parseErrorTestMessage
(string "x" <|> "failure" <??> string " " <|> "bad" <??> string "-")
"no"
"Expected failure"
Copy link
Contributor

@natefaubion natefaubion Mar 24, 2022

Choose a reason for hiding this comment

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

It might be helpful to have a <$> test in here just in case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added <* in there, too, and then got a little carried away.


-- we can't test "NaN" with `parseTest` because nan doesn't compare equal
case runParser "NaN" number of
Right actual -> do
Expand Down