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 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: 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!.github
!.editorconfig
!.tidyrc.json
!.tidyoperators

output
generated-docs
Expand Down
231 changes: 231 additions & 0 deletions .tidyoperators
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
Control.Alt.($>) 4
Control.Alt.(<#>) 1
Control.Alt.(<$) 4
Control.Alt.(<$>) 4
Control.Alt.(<@>) 4
Control.Alt.(<|>) 3
Control.Alternative.($>) 4
Control.Alternative.(*>) 4
Control.Alternative.(<#>) 1
Control.Alternative.(<$) 4
Control.Alternative.(<$>) 4
Control.Alternative.(<*) 4
Control.Alternative.(<*>) 4
Control.Alternative.(<@>) 4
Control.Alternative.(<|>) 3
Control.Applicative.($>) 4
Control.Applicative.(*>) 4
Control.Applicative.(<#>) 1
Control.Applicative.(<$) 4
Control.Applicative.(<$>) 4
Control.Applicative.(<*) 4
Control.Applicative.(<*>) 4
Control.Applicative.(<@>) 4
Control.Apply.($>) 4
Control.Apply.(*>) 4
Control.Apply.(<#>) 1
Control.Apply.(<$) 4
Control.Apply.(<$>) 4
Control.Apply.(<*) 4
Control.Apply.(<*>) 4
Control.Apply.(<@>) 4
Control.Biapply.(*>>) 4
Control.Biapply.(<<$>>) 4
Control.Biapply.(<<*) 4
Control.Biapply.(<<*>>) 4
Control.Bind.($>) 4
Control.Bind.(*>) 4
Control.Bind.(<#>) 1
Control.Bind.(<$) 4
Control.Bind.(<$>) 4
Control.Bind.(<*) 4
Control.Bind.(<*>) 4
Control.Bind.(<=<) 1
Control.Bind.(<@>) 4
Control.Bind.(=<<) 1
Control.Bind.(>=>) 1
Control.Bind.(>>=) 1
Control.Category.(<<<) 9
Control.Category.(>>>) 9
Control.Comonad.($>) 4
Control.Comonad.(<#>) 1
Control.Comonad.(<$) 4
Control.Comonad.(<$>) 4
Control.Comonad.(<<=) 1
Control.Comonad.(<@>) 4
Control.Comonad.(=<=) 1
Control.Comonad.(=>=) 1
Control.Comonad.(=>>) 1
Control.Extend.($>) 4
Control.Extend.(<#>) 1
Control.Extend.(<$) 4
Control.Extend.(<$>) 4
Control.Extend.(<<=) 1
Control.Extend.(<@>) 4
Control.Extend.(=<=) 1
Control.Extend.(=>=) 1
Control.Extend.(=>>) 1
Control.Monad.($>) 4
Control.Monad.(*>) 4
Control.Monad.(<#>) 1
Control.Monad.(<$) 4
Control.Monad.(<$>) 4
Control.Monad.(<*) 4
Control.Monad.(<*>) 4
Control.Monad.(<=<) 1
Control.Monad.(<@>) 4
Control.Monad.(=<<) 1
Control.Monad.(>=>) 1
Control.Monad.(>>=) 1
Control.MonadPlus.($>) 4
Control.MonadPlus.(*>) 4
Control.MonadPlus.(<#>) 1
Control.MonadPlus.(<$) 4
Control.MonadPlus.(<$>) 4
Control.MonadPlus.(<*) 4
Control.MonadPlus.(<*>) 4
Control.MonadPlus.(<=<) 1
Control.MonadPlus.(<@>) 4
Control.MonadPlus.(<|>) 3
Control.MonadPlus.(=<<) 1
Control.MonadPlus.(>=>) 1
Control.MonadPlus.(>>=) 1
Control.Plus.($>) 4
Control.Plus.(<#>) 1
Control.Plus.(<$) 4
Control.Plus.(<$>) 4
Control.Plus.(<@>) 4
Control.Plus.(<|>) 3
Control.Semigroupoid.(<<<) 9
Control.Semigroupoid.(>>>) 9
Data.Array.(!!) 8
Data.Array.(..) 8
Data.Array.(:) 6
Data.Array.(\\) 5
Data.Array.NonEmpty.(!!) 8
Data.Array.NonEmpty.(..) 8
Data.Array.NonEmpty.(:) 6
Data.Array.NonEmpty.(\\) 5
Data.BooleanAlgebra.(&&) 3
Data.BooleanAlgebra.(||) 2
Data.Bounded.(<) 4
Data.Bounded.(<=) 4
Data.Bounded.(>) 4
Data.Bounded.(>=) 4
Data.CommutativeRing.(*) 7
Data.CommutativeRing.(+) 6
Data.CommutativeRing.(-) 6
Data.DivisionRing.(*) 7
Data.DivisionRing.(+) 6
Data.DivisionRing.(-) 6
Data.Either.Nested.(\/) type 6
Data.Either.Nested.(\/) 6
Data.Eq.(/=) 4
Data.Eq.(==) 4
Data.EuclideanRing.(*) 7
Data.EuclideanRing.(+) 6
Data.EuclideanRing.(-) 6
Data.EuclideanRing.(/) 7
Data.Field.(*) 7
Data.Field.(+) 6
Data.Field.(-) 6
Data.Field.(/) 7
Data.Function.(#) 1
Data.Function.($) 0
Data.Function.(<<<) 9
Data.Function.(>>>) 9
Data.Functor.($>) 4
Data.Functor.(<#>) 1
Data.Functor.(<$) 4
Data.Functor.(<$>) 4
Data.Functor.(<@>) 4
Data.Functor.Contravariant.(>#<) 4
Data.Functor.Contravariant.(>$<) 4
Data.Functor.Coproduct.Nested.(<\/>) type 6
Data.Functor.Coproduct.Nested.(<\/>) 6
Data.Functor.Product.Nested.(</\>) type 6
Data.Functor.Product.Nested.(</\>) 6
Data.HeytingAlgebra.(&&) 3
Data.HeytingAlgebra.(||) 2
Data.Int.Bits.(.&.) 10
Data.Int.Bits.(.^.) 10
Data.Int.Bits.(.|.) 10
Data.List.(!!) 8
Data.List.(..) 8
Data.List.(:) 6
Data.List.(\\) 5
Data.List.Lazy.(!!) 8
Data.List.Lazy.(..) 8
Data.List.Lazy.(:) 6
Data.List.Lazy.(\\) 5
Data.List.Lazy.NonEmpty.(:) 6
Data.List.Lazy.Types.(:) 6
Data.List.NonEmpty.(!!) 8
Data.List.NonEmpty.(:) 6
Data.List.Types.(:) 6
Data.Monoid.(<>) 5
Data.NaturalTransformation.(~>) type 4
Data.NonEmpty.(:|) 5
Data.Number.Approximate.(~=) 4
Data.Number.Approximate.(≅) 4
Data.Number.Approximate.(≇) 4
Data.Ord.(<) 4
Data.Ord.(<=) 4
Data.Ord.(>) 4
Data.Ord.(>=) 4
Data.Profunctor.Choice.(+++) 2
Data.Profunctor.Choice.(|||) 2
Data.Profunctor.Strong.(&&&) 3
Data.Profunctor.Strong.(***) 3
Data.Ring.(*) 7
Data.Ring.(+) 6
Data.Ring.(-) 6
Data.Semigroup.(<>) 5
Data.Semiring.(*) 7
Data.Semiring.(+) 6
Data.Tuple.Nested.(/\) type 6
Data.Tuple.Nested.(/\) 6
Math.(%) 7
Prelude.(~>) type 4
Prelude.(#) 1
Prelude.($) 0
Prelude.($>) 4
Prelude.(&&) 3
Prelude.(*) 7
Prelude.(*>) 4
Prelude.(+) 6
Prelude.(-) 6
Prelude.(/) 7
Prelude.(/=) 4
Prelude.(<) 4
Prelude.(<#>) 1
Prelude.(<$) 4
Prelude.(<$>) 4
Prelude.(<*) 4
Prelude.(<*>) 4
Prelude.(<<<) 9
Prelude.(<=) 4
Prelude.(<=<) 1
Prelude.(<>) 5
Prelude.(<@>) 4
Prelude.(=<<) 1
Prelude.(==) 4
Prelude.(>) 4
Prelude.(>=) 4
Prelude.(>=>) 1
Prelude.(>>=) 1
Prelude.(>>>) 9
Prelude.(||) 2
Text.Parsing.Indent.(<*/>) 11
Text.Parsing.Indent.(<+/>) 9
Text.Parsing.Indent.(<-/>) 10
Text.Parsing.Indent.(<?/>) 12
Text.Parsing.Parser.Combinators.($>) 4
Text.Parsing.Parser.Combinators.(<#>) 1
Text.Parsing.Parser.Combinators.(<$) 4
Text.Parsing.Parser.Combinators.(<$>) 4
Text.Parsing.Parser.Combinators.(<?>) 4
Text.Parsing.Parser.Combinators.(<??>) 3
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.

2 changes: 1 addition & 1 deletion .tidyrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"importSort": "source",
"importWrap": "source",
"indent": 2,
"operatorsFile": null,
"operatorsFile": ".tidyoperators",
"ribbon": 1,
"typeArrowPlacement": "first",
"unicode": "never",
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
2 changes: 1 addition & 1 deletion src/Text/Parsing/Parser/Expr.purs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ makeParser term ops = do
<|> lassocP x lassocOp prefixP term postfixP
<|> nassocP x nassocOp prefixP term postfixP
<|> pure x
<?> "operator"
<?> "operator"
where
accum = foldr splitOp
{ rassoc: Nil
Expand Down
32 changes: 18 additions & 14 deletions src/Text/Parsing/Parser/Token.purs
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,10 @@ makeTokenParser (LanguageDef languageDef) =
folder (Just c) chars = Cons c chars

stringChar :: ParserT String m (Maybe Char)
stringChar = (Just <$> stringLetter)
<|> stringEscape
<?> "string character"
stringChar =
(Just <$> stringLetter)
<|> stringEscape
<?> "string character"

stringLetter :: ParserT String m Char
stringLetter = satisfy (\c -> (c /= '"') && (c /= '\\') && (c > '\x1A'))
Expand Down Expand Up @@ -685,8 +686,9 @@ makeTokenParser (LanguageDef languageDef) =

zeroNumber :: ParserT String m Int
zeroNumber =
char '0' *>
(hexadecimal <|> octal <|> decimal <|> pure 0) <?> ""
char '0'
*> (hexadecimal <|> octal <|> decimal <|> pure 0)
<?> ""

decimal :: ParserT String m Int
decimal = number 10 Basic.digit
Expand Down Expand Up @@ -860,21 +862,23 @@ inComment langDef@(LanguageDef languageDef) =

inCommentMulti :: forall m. Monad m => GenLanguageDef String m -> ParserT String m Unit
inCommentMulti langDef@(LanguageDef languageDef) =
fix \p -> (void $ try (string languageDef.commentEnd))
<|> (multiLineComment langDef *> p)
<|> (skipMany1 (noneOf startEnd) *> p)
<|> (oneOf startEnd *> p)
<?> "end of comment"
fix \p ->
(void $ try (string languageDef.commentEnd))
<|> (multiLineComment langDef *> p)
<|> (skipMany1 (noneOf startEnd) *> p)
<|> (oneOf startEnd *> p)
<?> "end of comment"
where
startEnd :: Array Char
startEnd = SCU.toCharArray languageDef.commentEnd <> SCU.toCharArray languageDef.commentStart

inCommentSingle :: forall m. Monad m => GenLanguageDef String m -> ParserT String m Unit
inCommentSingle (LanguageDef languageDef) =
fix \p -> (void $ try (string languageDef.commentEnd))
<|> (skipMany1 (noneOf startEnd) *> p)
<|> (oneOf startEnd *> p)
<?> "end of comment"
fix \p ->
(void $ try (string languageDef.commentEnd))
<|> (skipMany1 (noneOf startEnd) *> p)
<|> (oneOf startEnd *> p)
<?> "end of comment"
where
startEnd :: Array Char
startEnd = SCU.toCharArray languageDef.commentEnd <> SCU.toCharArray languageDef.commentStart
Expand Down
Loading