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

Fix other <|> breakage #164

merged 17 commits into from
Mar 24, 2022

Conversation

JordanMartinez
Copy link
Contributor

Description of the change

Follow up to #163. Relates to #161.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

@JordanMartinez
Copy link
Contributor Author

🏓 @thomashoneyman

@thomashoneyman
Copy link
Contributor

cc: @natefaubion is this how you would expect these operators to be changed?

@natefaubion
Copy link
Contributor

Oh hmm, 3 doesn't work because it's not an associative operator.

@natefaubion
Copy link
Contributor

natefaubion commented Mar 24, 2022

I think ideally, to retain the same kind of formatting as before. It would need to be 4, but then it conflicts with precedence of functor operators. Unfortunately <?> is incompatible with infixr, so I think infixl 2 is probably best then. <??> can be infixr though, and it should be infixr 3.

@@ -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 <~?>
infixr 3 withLazyErrorMessage as <~?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Order of arguments means this has to be infixl.

@@ -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 <?>
infixr 3 withErrorMessage as <?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Order of arguments means this needs to be infixl.

@natefaubion
Copy link
Contributor

Wow, operator precedence is hard. Nevermind, infixl things should be 4. This is fine and compatible with functor operators.

@natefaubion
Copy link
Contributor

Or to be super clear:

infixl 4 withErrorMessage as <?>
infixl 4 withLazyErrorMessage as <~?>
infixr 3 asErrorMessage as <??>

test/Main.purs Outdated
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.

@@ -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.

@JordanMartinez
Copy link
Contributor Author

@natefaubion Thoughts on the last formatting commit?

@natefaubion
Copy link
Contributor

natefaubion commented Mar 24, 2022

Tidy doesn't have an updated operator table, unfortunately. You could potentially generate one yourself.

test/Main.purs Outdated
skipMany1Rec (string "a") *> string "b"
parseTest "aaaabcd" "b"
$ skipMany1Rec (string "a")
*> string "b"
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened here?

@JordanMartinez
Copy link
Contributor Author

Adding one doesn't seem to help much either...

Text.Parsing.Indent.(<?/>) 12
Text.Parsing.Parser.Combinators.(<?>) 4
Text.Parsing.Parser.Combinators.(<??>) 3
Text.Parsing.Parser.Combinators.(<~?>) 4
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.

You need to add all spago sources.

Copy link
Contributor

Choose a reason for hiding this comment

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

ie, the operator tables don't inherit from the default set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh... I ran purs-tidy generate-operators "$(spago sources)" > .tidyoperators to get the above output.
After reading the above comment, I then tried what your readme says:

spago sources | xargs purs-tidy generate-operators > .tidyoperators

I still get the same thing.

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.

Maybe xargs behaves differently on your system? I just tried it and I get the full prelude in there.

Copy link
Contributor

Choose a reason for hiding this comment

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

@JordanMartinez JordanMartinez merged commit 54525df into purescript-contrib:main Mar 24, 2022
@JordanMartinez JordanMartinez deleted the fix-alt-stuff branch March 24, 2022 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants