Skip to content

Commit 54525df

Browse files
Fix other <|> breakage (#164)
* Add test for all error variants * Fix infix and prec for operators: <?>, <??>, <~?> * Bust CI cache * Add tidy operators table * Rerun formatter
1 parent edc61eb commit 54525df

File tree

9 files changed

+337
-44
lines changed

9 files changed

+337
-44
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Cache PureScript dependencies
2323
uses: actions/cache@v2
2424
with:
25-
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
25+
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}-2
2626
path: |
2727
.spago
2828
output

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
!.github
44
!.editorconfig
55
!.tidyrc.json
6+
!.tidyoperators
67

78
output
89
generated-docs

.tidyoperators

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
Control.Alt.($>) 4
2+
Control.Alt.(<#>) 1
3+
Control.Alt.(<$) 4
4+
Control.Alt.(<$>) 4
5+
Control.Alt.(<@>) 4
6+
Control.Alt.(<|>) 3
7+
Control.Alternative.($>) 4
8+
Control.Alternative.(*>) 4
9+
Control.Alternative.(<#>) 1
10+
Control.Alternative.(<$) 4
11+
Control.Alternative.(<$>) 4
12+
Control.Alternative.(<*) 4
13+
Control.Alternative.(<*>) 4
14+
Control.Alternative.(<@>) 4
15+
Control.Alternative.(<|>) 3
16+
Control.Applicative.($>) 4
17+
Control.Applicative.(*>) 4
18+
Control.Applicative.(<#>) 1
19+
Control.Applicative.(<$) 4
20+
Control.Applicative.(<$>) 4
21+
Control.Applicative.(<*) 4
22+
Control.Applicative.(<*>) 4
23+
Control.Applicative.(<@>) 4
24+
Control.Apply.($>) 4
25+
Control.Apply.(*>) 4
26+
Control.Apply.(<#>) 1
27+
Control.Apply.(<$) 4
28+
Control.Apply.(<$>) 4
29+
Control.Apply.(<*) 4
30+
Control.Apply.(<*>) 4
31+
Control.Apply.(<@>) 4
32+
Control.Biapply.(*>>) 4
33+
Control.Biapply.(<<$>>) 4
34+
Control.Biapply.(<<*) 4
35+
Control.Biapply.(<<*>>) 4
36+
Control.Bind.($>) 4
37+
Control.Bind.(*>) 4
38+
Control.Bind.(<#>) 1
39+
Control.Bind.(<$) 4
40+
Control.Bind.(<$>) 4
41+
Control.Bind.(<*) 4
42+
Control.Bind.(<*>) 4
43+
Control.Bind.(<=<) 1
44+
Control.Bind.(<@>) 4
45+
Control.Bind.(=<<) 1
46+
Control.Bind.(>=>) 1
47+
Control.Bind.(>>=) 1
48+
Control.Category.(<<<) 9
49+
Control.Category.(>>>) 9
50+
Control.Comonad.($>) 4
51+
Control.Comonad.(<#>) 1
52+
Control.Comonad.(<$) 4
53+
Control.Comonad.(<$>) 4
54+
Control.Comonad.(<<=) 1
55+
Control.Comonad.(<@>) 4
56+
Control.Comonad.(=<=) 1
57+
Control.Comonad.(=>=) 1
58+
Control.Comonad.(=>>) 1
59+
Control.Extend.($>) 4
60+
Control.Extend.(<#>) 1
61+
Control.Extend.(<$) 4
62+
Control.Extend.(<$>) 4
63+
Control.Extend.(<<=) 1
64+
Control.Extend.(<@>) 4
65+
Control.Extend.(=<=) 1
66+
Control.Extend.(=>=) 1
67+
Control.Extend.(=>>) 1
68+
Control.Monad.($>) 4
69+
Control.Monad.(*>) 4
70+
Control.Monad.(<#>) 1
71+
Control.Monad.(<$) 4
72+
Control.Monad.(<$>) 4
73+
Control.Monad.(<*) 4
74+
Control.Monad.(<*>) 4
75+
Control.Monad.(<=<) 1
76+
Control.Monad.(<@>) 4
77+
Control.Monad.(=<<) 1
78+
Control.Monad.(>=>) 1
79+
Control.Monad.(>>=) 1
80+
Control.MonadPlus.($>) 4
81+
Control.MonadPlus.(*>) 4
82+
Control.MonadPlus.(<#>) 1
83+
Control.MonadPlus.(<$) 4
84+
Control.MonadPlus.(<$>) 4
85+
Control.MonadPlus.(<*) 4
86+
Control.MonadPlus.(<*>) 4
87+
Control.MonadPlus.(<=<) 1
88+
Control.MonadPlus.(<@>) 4
89+
Control.MonadPlus.(<|>) 3
90+
Control.MonadPlus.(=<<) 1
91+
Control.MonadPlus.(>=>) 1
92+
Control.MonadPlus.(>>=) 1
93+
Control.Plus.($>) 4
94+
Control.Plus.(<#>) 1
95+
Control.Plus.(<$) 4
96+
Control.Plus.(<$>) 4
97+
Control.Plus.(<@>) 4
98+
Control.Plus.(<|>) 3
99+
Control.Semigroupoid.(<<<) 9
100+
Control.Semigroupoid.(>>>) 9
101+
Data.Array.(!!) 8
102+
Data.Array.(..) 8
103+
Data.Array.(:) 6
104+
Data.Array.(\\) 5
105+
Data.Array.NonEmpty.(!!) 8
106+
Data.Array.NonEmpty.(..) 8
107+
Data.Array.NonEmpty.(:) 6
108+
Data.Array.NonEmpty.(\\) 5
109+
Data.BooleanAlgebra.(&&) 3
110+
Data.BooleanAlgebra.(||) 2
111+
Data.Bounded.(<) 4
112+
Data.Bounded.(<=) 4
113+
Data.Bounded.(>) 4
114+
Data.Bounded.(>=) 4
115+
Data.CommutativeRing.(*) 7
116+
Data.CommutativeRing.(+) 6
117+
Data.CommutativeRing.(-) 6
118+
Data.DivisionRing.(*) 7
119+
Data.DivisionRing.(+) 6
120+
Data.DivisionRing.(-) 6
121+
Data.Either.Nested.(\/) type 6
122+
Data.Either.Nested.(\/) 6
123+
Data.Eq.(/=) 4
124+
Data.Eq.(==) 4
125+
Data.EuclideanRing.(*) 7
126+
Data.EuclideanRing.(+) 6
127+
Data.EuclideanRing.(-) 6
128+
Data.EuclideanRing.(/) 7
129+
Data.Field.(*) 7
130+
Data.Field.(+) 6
131+
Data.Field.(-) 6
132+
Data.Field.(/) 7
133+
Data.Function.(#) 1
134+
Data.Function.($) 0
135+
Data.Function.(<<<) 9
136+
Data.Function.(>>>) 9
137+
Data.Functor.($>) 4
138+
Data.Functor.(<#>) 1
139+
Data.Functor.(<$) 4
140+
Data.Functor.(<$>) 4
141+
Data.Functor.(<@>) 4
142+
Data.Functor.Contravariant.(>#<) 4
143+
Data.Functor.Contravariant.(>$<) 4
144+
Data.Functor.Coproduct.Nested.(<\/>) type 6
145+
Data.Functor.Coproduct.Nested.(<\/>) 6
146+
Data.Functor.Product.Nested.(</\>) type 6
147+
Data.Functor.Product.Nested.(</\>) 6
148+
Data.HeytingAlgebra.(&&) 3
149+
Data.HeytingAlgebra.(||) 2
150+
Data.Int.Bits.(.&.) 10
151+
Data.Int.Bits.(.^.) 10
152+
Data.Int.Bits.(.|.) 10
153+
Data.List.(!!) 8
154+
Data.List.(..) 8
155+
Data.List.(:) 6
156+
Data.List.(\\) 5
157+
Data.List.Lazy.(!!) 8
158+
Data.List.Lazy.(..) 8
159+
Data.List.Lazy.(:) 6
160+
Data.List.Lazy.(\\) 5
161+
Data.List.Lazy.NonEmpty.(:) 6
162+
Data.List.Lazy.Types.(:) 6
163+
Data.List.NonEmpty.(!!) 8
164+
Data.List.NonEmpty.(:) 6
165+
Data.List.Types.(:) 6
166+
Data.Monoid.(<>) 5
167+
Data.NaturalTransformation.(~>) type 4
168+
Data.NonEmpty.(:|) 5
169+
Data.Number.Approximate.(~=) 4
170+
Data.Number.Approximate.(≅) 4
171+
Data.Number.Approximate.(≇) 4
172+
Data.Ord.(<) 4
173+
Data.Ord.(<=) 4
174+
Data.Ord.(>) 4
175+
Data.Ord.(>=) 4
176+
Data.Profunctor.Choice.(+++) 2
177+
Data.Profunctor.Choice.(|||) 2
178+
Data.Profunctor.Strong.(&&&) 3
179+
Data.Profunctor.Strong.(***) 3
180+
Data.Ring.(*) 7
181+
Data.Ring.(+) 6
182+
Data.Ring.(-) 6
183+
Data.Semigroup.(<>) 5
184+
Data.Semiring.(*) 7
185+
Data.Semiring.(+) 6
186+
Data.Tuple.Nested.(/\) type 6
187+
Data.Tuple.Nested.(/\) 6
188+
Math.(%) 7
189+
Prelude.(~>) type 4
190+
Prelude.(#) 1
191+
Prelude.($) 0
192+
Prelude.($>) 4
193+
Prelude.(&&) 3
194+
Prelude.(*) 7
195+
Prelude.(*>) 4
196+
Prelude.(+) 6
197+
Prelude.(-) 6
198+
Prelude.(/) 7
199+
Prelude.(/=) 4
200+
Prelude.(<) 4
201+
Prelude.(<#>) 1
202+
Prelude.(<$) 4
203+
Prelude.(<$>) 4
204+
Prelude.(<*) 4
205+
Prelude.(<*>) 4
206+
Prelude.(<<<) 9
207+
Prelude.(<=) 4
208+
Prelude.(<=<) 1
209+
Prelude.(<>) 5
210+
Prelude.(<@>) 4
211+
Prelude.(=<<) 1
212+
Prelude.(==) 4
213+
Prelude.(>) 4
214+
Prelude.(>=) 4
215+
Prelude.(>=>) 1
216+
Prelude.(>>=) 1
217+
Prelude.(>>>) 9
218+
Prelude.(||) 2
219+
Text.Parsing.Indent.(<*/>) 11
220+
Text.Parsing.Indent.(<+/>) 9
221+
Text.Parsing.Indent.(<-/>) 10
222+
Text.Parsing.Indent.(<?/>) 12
223+
Text.Parsing.Parser.Combinators.($>) 4
224+
Text.Parsing.Parser.Combinators.(<#>) 1
225+
Text.Parsing.Parser.Combinators.(<$) 4
226+
Text.Parsing.Parser.Combinators.(<$>) 4
227+
Text.Parsing.Parser.Combinators.(<?>) 4
228+
Text.Parsing.Parser.Combinators.(<??>) 3
229+
Text.Parsing.Parser.Combinators.(<@>) 4
230+
Text.Parsing.Parser.Combinators.(<|>) 3
231+
Text.Parsing.Parser.Combinators.(<~?>) 4

.tidyrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"importSort": "source",
33
"importWrap": "source",
44
"indent": 2,
5-
"operatorsFile": null,
5+
"operatorsFile": ".tidyoperators",
66
"ribbon": 1,
77
"typeArrowPlacement": "first",
88
"unicode": "never",

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88
- Update project and deps to PureScript v0.15.0 (#160 by @JordanMartinez)
99
- Drop deprecated `MonadZero` instance (#160 by @JordanMartinez)
10-
- Make `<?>` right-associative and increase prec from 3 to 2 (#163 by @JordanMartinez)
10+
- Make `<??>` right-associative (#164 by @JordanMartinez)
11+
- Drop `<?>` and `<~?>` prec from 3 to 4 (#163, #164 by @JordanMartinez)
1112

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

1617
New features:
1718

src/Text/Parsing/Parser/Combinators.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ import Text.Parsing.Parser (ParseError(..), ParseState(..), ParserT(..), fail)
119119
withErrorMessage :: forall m s a. Monad m => ParserT s m a -> String -> ParserT s m a
120120
withErrorMessage p msg = p <|> fail ("Expected " <> msg)
121121

122-
infixr 2 withErrorMessage as <?>
122+
infixl 4 withErrorMessage as <?>
123123

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

135-
infixl 3 withLazyErrorMessage as <~?>
135+
infixl 4 withLazyErrorMessage as <~?>
136136

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

141-
infixl 3 asErrorMessage as <??>
141+
infixr 3 asErrorMessage as <??>
142142

143143
-- | Wrap a parser with opening and closing markers.
144144
-- |

src/Text/Parsing/Parser/Expr.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ makeParser term ops = do
5555
<|> lassocP x lassocOp prefixP term postfixP
5656
<|> nassocP x nassocOp prefixP term postfixP
5757
<|> pure x
58-
<?> "operator"
58+
<?> "operator"
5959
where
6060
accum = foldr splitOp
6161
{ rassoc: Nil

src/Text/Parsing/Parser/Token.purs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,10 @@ makeTokenParser (LanguageDef languageDef) =
460460
folder (Just c) chars = Cons c chars
461461

462462
stringChar :: ParserT String m (Maybe Char)
463-
stringChar = (Just <$> stringLetter)
464-
<|> stringEscape
465-
<?> "string character"
463+
stringChar =
464+
(Just <$> stringLetter)
465+
<|> stringEscape
466+
<?> "string character"
466467

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

686687
zeroNumber :: ParserT String m Int
687688
zeroNumber =
688-
char '0' *>
689-
(hexadecimal <|> octal <|> decimal <|> pure 0) <?> ""
689+
char '0'
690+
*> (hexadecimal <|> octal <|> decimal <|> pure 0)
691+
<?> ""
690692

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

861863
inCommentMulti :: forall m. Monad m => GenLanguageDef String m -> ParserT String m Unit
862864
inCommentMulti langDef@(LanguageDef languageDef) =
863-
fix \p -> (void $ try (string languageDef.commentEnd))
864-
<|> (multiLineComment langDef *> p)
865-
<|> (skipMany1 (noneOf startEnd) *> p)
866-
<|> (oneOf startEnd *> p)
867-
<?> "end of comment"
865+
fix \p ->
866+
(void $ try (string languageDef.commentEnd))
867+
<|> (multiLineComment langDef *> p)
868+
<|> (skipMany1 (noneOf startEnd) *> p)
869+
<|> (oneOf startEnd *> p)
870+
<?> "end of comment"
868871
where
869872
startEnd :: Array Char
870873
startEnd = SCU.toCharArray languageDef.commentEnd <> SCU.toCharArray languageDef.commentStart
871874

872875
inCommentSingle :: forall m. Monad m => GenLanguageDef String m -> ParserT String m Unit
873876
inCommentSingle (LanguageDef languageDef) =
874-
fix \p -> (void $ try (string languageDef.commentEnd))
875-
<|> (skipMany1 (noneOf startEnd) *> p)
876-
<|> (oneOf startEnd *> p)
877-
<?> "end of comment"
877+
fix \p ->
878+
(void $ try (string languageDef.commentEnd))
879+
<|> (skipMany1 (noneOf startEnd) *> p)
880+
<|> (oneOf startEnd *> p)
881+
<?> "end of comment"
878882
where
879883
startEnd :: Array Char
880884
startEnd = SCU.toCharArray languageDef.commentEnd <> SCU.toCharArray languageDef.commentStart

0 commit comments

Comments
 (0)