From 53365b7e422782feae624379307b66381f82cd97 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 15:58:18 -0500 Subject: [PATCH 01/17] Add test for all error variants --- test/Main.purs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/Main.purs b/test/Main.purs index eb239c9..9e9286d 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -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) @@ -671,6 +671,32 @@ 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 " " <~?> \_ -> "failure") + "no" + "Expected failure" + parseErrorTestMessage + (string " " <|> string "-" <~?> \_ -> "failure") + "no" + "Expected failure" + parseErrorTestMessage + ("failure" string " ") + "no" + "Expected failure" + parseErrorTestMessage + ("failure" string " " <|> string "-") + "no" + "Expected failure" + -- we can't test "NaN" with `parseTest` because nan doesn't compare equal case runParser "NaN" number of Right actual -> do From 005a89ee36273e2d8f3e3727058f86f0715d8499 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 15:59:23 -0500 Subject: [PATCH 02/17] Make other variants infixr --- src/Text/Parsing/Parser/Combinators.purs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Text/Parsing/Parser/Combinators.purs b/src/Text/Parsing/Parser/Combinators.purs index 56720ba..2b48d71 100644 --- a/src/Text/Parsing/Parser/Combinators.purs +++ b/src/Text/Parsing/Parser/Combinators.purs @@ -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 <~?> -- | 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. -- | From 5ca65e85d193d8ec565973750a56672239495ea8 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 15:59:32 -0500 Subject: [PATCH 03/17] Drop prec back to 3 --- src/Text/Parsing/Parser/Combinators.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Text/Parsing/Parser/Combinators.purs b/src/Text/Parsing/Parser/Combinators.purs index 2b48d71..0a11589 100644 --- a/src/Text/Parsing/Parser/Combinators.purs +++ b/src/Text/Parsing/Parser/Combinators.purs @@ -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 -- | 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 From 4718120a07f9044c8d9eb042373a0141e388c76f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:04:00 -0500 Subject: [PATCH 04/17] Update changelog --- CHANGELOG.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72164c2..b98e8fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,10 @@ 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 ``, `` and `<~?>` right-associative (#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. Updating these three operators + to match its direction prevents a compiler error: `MixedAssociativityError` New features: From 7ca3990c55311cfb87b8c475133c2e107472d731 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:04:04 -0500 Subject: [PATCH 05/17] Bust CI cache --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5cc57a1..9c55473 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 path: | .spago output From f2c146f2e9ccbc5d7ea7d86398335ff94797c5b4 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:17:41 -0500 Subject: [PATCH 06/17] Add combinator test for operators --- test/Main.purs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/Main.purs b/test/Main.purs index 9e9286d..8c24f04 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -680,6 +680,10 @@ main = do (string " " <|> string "-" "failure") "no" "Expected failure" + parseErrorTestMessage + (string " " "bad" <|> string "-" "failure") + "no" + "Expected failure" parseErrorTestMessage (string " " <~?> \_ -> "failure") "no" @@ -688,6 +692,10 @@ main = do (string " " <|> string "-" <~?> \_ -> "failure") "no" "Expected failure" + parseErrorTestMessage + (string " " <~?> (\_ -> "bad") <|> string "-" <~?> \_ -> "failure") + "no" + "Expected failure" parseErrorTestMessage ("failure" string " ") "no" @@ -696,6 +704,10 @@ main = do ("failure" string " " <|> string "-") "no" "Expected failure" + parseErrorTestMessage + (string "x" <|> "failure" string " " <|> "bad" string "-") + "no" + "Expected failure" -- we can't test "NaN" with `parseTest` because nan doesn't compare equal case runParser "NaN" number of From c586fe0940a34775d208c0bca559b0c719faf5a1 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:18:06 -0500 Subject: [PATCH 07/17] Fix conflicting prec issues --- src/Text/Parsing/Parser/Combinators.purs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Text/Parsing/Parser/Combinators.purs b/src/Text/Parsing/Parser/Combinators.purs index 0a11589..5cf6076 100644 --- a/src/Text/Parsing/Parser/Combinators.purs +++ b/src/Text/Parsing/Parser/Combinators.purs @@ -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 3 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 @@ -132,7 +132,7 @@ infixr 3 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) -infixr 3 withLazyErrorMessage as <~?> +infixl 4 withLazyErrorMessage as <~?> -- | Flipped `()`. asErrorMessage :: forall m s a. Monad m => String -> ParserT s m a -> ParserT s m a From 92e772dcef43756cc9a8c10e16e97e1ca896969e Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:19:27 -0500 Subject: [PATCH 08/17] Update entry --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b98e8fd..92de354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +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 ``, `` and `<~?>` right-associative (#163, #164 by @JordanMartinez) +- Make `` right-associative (#164 by @JordanMartinez) +- Drop `` and `<~?>` prec from 3 to 4 (#163, #164 by @JordanMartinez) - `<|>` was made right associative. Updating these three operators - to match its direction prevents a compiler error: `MixedAssociativityError` + `<|>` was made right associative. Decreasing these two operators + prevents a compiler error (i.e. `MixedAssociativityError`) + without causing issues with `<$>`. New features: From e8128750f03b6c467d6d7354bf7600227345f885 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:33:56 -0500 Subject: [PATCH 09/17] Deduplicate tests by using oneOf --- test/Main.purs | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index 8c24f04..bfba564 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -7,6 +7,7 @@ import Control.Lazy (fix) import Data.Array (some, toUnfoldable) import Data.Array as Array import Data.Either (Either(..)) +import Data.Foldable (oneOf) import Data.List (List(..), fromFoldable, many) import Data.List.NonEmpty (cons, cons') import Data.List.NonEmpty as NE @@ -672,40 +673,19 @@ main = do parseTest "+6.0" (6.0) number -- test from issue #161 + -- all the below operators should play well together 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 "-") + (oneOf + [ string " " "1" + , string " " <|> string " " "2" + , string " " "3" <|> string " " "4" + , string " " <~?> \_ -> "5" + , string " " <|> string " " <~?> \_ -> "6" + , string " " <~?> (\_ -> "7") <|> string " " <~?> \_ -> "8" + , "9" string " " <|> string " " + , string " " <|> "10" string " " <|> "11" string " " + ] + ) "no" "Expected failure" From dfa0775c11928589baf3243149b671f307d7859e Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:49:19 -0500 Subject: [PATCH 10/17] Operator combos galore! --- test/Main.purs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index bfba564..af245bf 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -21,7 +21,7 @@ import Effect (Effect) 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 (ParseError(..), Parser, ParserT, fail, 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.Expr (Assoc(..), Operator(..), buildExprParser) import Text.Parsing.Parser.Language (haskellDef, haskellStyle, javaStyle) @@ -676,18 +676,37 @@ main = do -- all the below operators should play well together parseErrorTestMessage (oneOf - [ string " " "1" + [ fail "test " + , string " " "1" , string " " <|> string " " "2" , string " " "3" <|> string " " "4" - , string " " <~?> \_ -> "5" - , string " " <|> string " " <~?> \_ -> "6" - , string " " <~?> (\_ -> "7") <|> string " " <~?> \_ -> "8" - , "9" string " " <|> string " " - , string " " <|> "10" string " " <|> "11" string " " + , "" <$ string " " "5" + <|> string " " $> "" "6" + <|> const "" <$> string " " "7" + <* string " " $> "" "8" + *> string " " $> "" "9" + , fail "test <~?>" + , string " " <~?> \_ -> "21" + , string " " <|> string " " <~?> \_ -> "22" + , string " " <~?> (\_ -> "23") <|> string " " <~?> \_ -> "24" + , "" <$ string " " <~?> (\_ -> "25") + <|> string " " $> "" <~?> (\_ -> "26") + <|> const "" <$> string " " <~?> (\_ -> "27") + <* string " " $> "" <~?> (\_ -> "28") + *> string " " $> "" <~?> \_ -> "29" + , fail "test " + , "41" string " " + , "42" string " " <|> string " " + , "43" string " " <|> "44" string " " + , "" <$ "45" string " " + <|> "46" string " " $> "" + <|> const "" <$> "47" string " " + <* "48" string " " + *> "49" string " " ] ) "no" - "Expected failure" + "No alternative" -- we can't test "NaN" with `parseTest` because nan doesn't compare equal case runParser "NaN" number of From 748c422e6a5bf4b8d9115bda2cb206e50ed35ad3 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:50:31 -0500 Subject: [PATCH 11/17] Fix last few tests --- test/Main.purs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index af245bf..533a76d 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -698,11 +698,11 @@ main = do , "41" string " " , "42" string " " <|> string " " , "43" string " " <|> "44" string " " - , "" <$ "45" string " " + , "45" "" <$ string " " <|> "46" string " " $> "" - <|> const "" <$> "47" string " " - <* "48" string " " - *> "49" string " " + <|> "47" const "" <$> string " " + <* ("48" string " ") + *> ("49" string " ") ] ) "no" From d06567411125fc2cee6ee9208fff201742532639 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:52:57 -0500 Subject: [PATCH 12/17] Fix formatting... ew... --- test/Main.purs | 68 +++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index 533a76d..f2eedc1 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -675,35 +675,45 @@ main = do -- test from issue #161 -- all the below operators should play well together parseErrorTestMessage - (oneOf - [ fail "test " - , string " " "1" - , string " " <|> string " " "2" - , string " " "3" <|> string " " "4" - , "" <$ string " " "5" - <|> string " " $> "" "6" - <|> const "" <$> string " " "7" - <* string " " $> "" "8" - *> string " " $> "" "9" - , fail "test <~?>" - , string " " <~?> \_ -> "21" - , string " " <|> string " " <~?> \_ -> "22" - , string " " <~?> (\_ -> "23") <|> string " " <~?> \_ -> "24" - , "" <$ string " " <~?> (\_ -> "25") - <|> string " " $> "" <~?> (\_ -> "26") - <|> const "" <$> string " " <~?> (\_ -> "27") - <* string " " $> "" <~?> (\_ -> "28") - *> string " " $> "" <~?> \_ -> "29" - , fail "test " - , "41" string " " - , "42" string " " <|> string " " - , "43" string " " <|> "44" string " " - , "45" "" <$ string " " - <|> "46" string " " $> "" - <|> "47" const "" <$> string " " - <* ("48" string " ") - *> ("49" string " ") - ] + ( oneOf + [ fail "test " + , string " " "1" + , string " " <|> string " " "2" + , string " " "3" <|> string " " "4" + , "" <$ string " " "5" + <|> string " " $> "" + "6" + <|> const "" <$> string " " + "7" + <* string " " + $> "" + "8" + *> string " " + $> "" + "9" + , fail "test <~?>" + , string " " <~?> \_ -> "21" + , string " " <|> string " " <~?> \_ -> "22" + , string " " <~?> (\_ -> "23") <|> string " " <~?> \_ -> "24" + , "" <$ string " " <~?> (\_ -> "25") + <|> string " " $> "" <~?> (\_ -> "26") + <|> const "" <$> string " " <~?> (\_ -> "27") + <* string " " + $> "" <~?> (\_ -> "28") + *> string " " + $> "" <~?> \_ -> "29" + , fail "test " + , "41" string " " + , "42" string " " <|> string " " + , "43" string " " <|> "44" string " " + , "45" "" <$ string " " + <|> "46" + string " " $> "" + <|> "47" + const "" <$> string " " + <* ("48" string " ") + *> ("49" string " ") + ] ) "no" "No alternative" From 8409f819b69215d183c9ee459dda4a3b4cb2a996 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:58:56 -0500 Subject: [PATCH 13/17] Add operators table for purs-tidy --- .gitignore | 1 + .tidyoperators | 7 +++++++ .tidyrc.json | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .tidyoperators diff --git a/.gitignore b/.gitignore index 7e82b68..8a183fa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ !.github !.editorconfig !.tidyrc.json +!.tidyoperators output generated-docs diff --git a/.tidyoperators b/.tidyoperators new file mode 100644 index 0000000..fcf3aa6 --- /dev/null +++ b/.tidyoperators @@ -0,0 +1,7 @@ +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.() 3 +Text.Parsing.Parser.Combinators.(<~?>) 4 diff --git a/.tidyrc.json b/.tidyrc.json index 4f013c1..1a4c51c 100644 --- a/.tidyrc.json +++ b/.tidyrc.json @@ -2,7 +2,7 @@ "importSort": "source", "importWrap": "source", "indent": 2, - "operatorsFile": null, + "operatorsFile": ".tidyoperators", "ribbon": 1, "typeArrowPlacement": "first", "unicode": "never", From 851dfea4bd47d30f83316edddbe1b026a7b8d91f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 16:59:47 -0500 Subject: [PATCH 14/17] Rerun formatter --- src/Text/Parsing/Parser/Token.purs | 27 ++++++----- test/Main.purs | 78 +++++++++++++++++++----------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/Text/Parsing/Parser/Token.purs b/src/Text/Parsing/Parser/Token.purs index e9fe7ff..94deb86 100644 --- a/src/Text/Parsing/Parser/Token.purs +++ b/src/Text/Parsing/Parser/Token.purs @@ -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')) @@ -860,21 +861,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 diff --git a/test/Main.purs b/test/Main.purs index f2eedc1..c6002dd 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -156,17 +156,20 @@ stackSafeLoopsTest = do "" (Position { line: 1, column: 1 }) - parseTest "aaaabcd" "b" $ - skipMany1Rec (string "a") *> string "b" + parseTest "aaaabcd" "b" + $ skipMany1Rec (string "a") + *> string "b" parseErrorTestPosition (skipMany1Rec (string "a")) "bcd" (Position { line: 1, column: 1 }) - parseTest "aaaabcd" "b" $ - skipManyRec (string "a") *> string "b" - parseTest "bcd" "b" $ - skipManyRec (string "a") *> string "b" + parseTest "aaaabcd" "b" + $ skipManyRec (string "a") + *> string "b" + parseTest "bcd" "b" + $ skipManyRec (string "a") + *> string "b" parseTest "aaa" (NE.cons' "a" $ toUnfoldable [ "a", "a" ]) $ many1Rec (string "a") @@ -175,12 +178,15 @@ stackSafeLoopsTest = do "" (Position { line: 1, column: 1 }) - parseTest "a,a,ab" (toUnfoldable [ "a", "a", "a" ]) $ - sepByRec (string "a") (string ",") <* string "b" - parseTest "b" Nil $ - sepByRec (string "a") (string ",") <* string "b" - parseTest "a,a,ab" (NE.cons' "a" $ toUnfoldable [ "a", "a" ]) $ - sepBy1Rec (string "a") (string ",") <* string "b" + parseTest "a,a,ab" (toUnfoldable [ "a", "a", "a" ]) + $ sepByRec (string "a") (string ",") + <* string "b" + parseTest "b" Nil + $ sepByRec (string "a") (string ",") + <* string "b" + parseTest "a,a,ab" (NE.cons' "a" $ toUnfoldable [ "a", "a" ]) + $ sepBy1Rec (string "a") (string ",") + <* string "b" parseErrorTestPosition (sepBy1Rec (string "a") (string ",")) "" @@ -190,12 +196,15 @@ stackSafeLoopsTest = do "a," (Position { line: 1, column: 3 }) - parseTest "a,a,a,b" (toUnfoldable [ "a", "a", "a" ]) $ - endByRec (string "a") (string ",") <* string "b" - parseTest "b" Nil $ - endByRec (string "a") (string ",") <* string "b" - parseTest "a,a,a,b" (NE.cons' "a" $ toUnfoldable [ "a", "a" ]) $ - endBy1Rec (string "a") (string ",") <* string "b" + parseTest "a,a,a,b" (toUnfoldable [ "a", "a", "a" ]) + $ endByRec (string "a") (string ",") + <* string "b" + parseTest "b" Nil + $ endByRec (string "a") (string ",") + <* string "b" + parseTest "a,a,a,b" (NE.cons' "a" $ toUnfoldable [ "a", "a" ]) + $ endBy1Rec (string "a") (string ",") + <* string "b" parseErrorTestPosition (endBy1Rec (string "a") (string ",")) "" @@ -680,10 +689,13 @@ main = do , string " " "1" , string " " <|> string " " "2" , string " " "3" <|> string " " "4" - , "" <$ string " " "5" - <|> string " " $> "" + , "" <$ string " " + "5" + <|> string " " + $> "" "6" - <|> const "" <$> string " " + <|> const "" + <$> string " " "7" <* string " " $> "" @@ -695,21 +707,29 @@ main = do , string " " <~?> \_ -> "21" , string " " <|> string " " <~?> \_ -> "22" , string " " <~?> (\_ -> "23") <|> string " " <~?> \_ -> "24" - , "" <$ string " " <~?> (\_ -> "25") - <|> string " " $> "" <~?> (\_ -> "26") - <|> const "" <$> string " " <~?> (\_ -> "27") + , "" <$ string " " + <~?> (\_ -> "25") + <|> string " " + $> "" + <~?> (\_ -> "26") + <|> const "" + <$> string " " + <~?> (\_ -> "27") <* string " " - $> "" <~?> (\_ -> "28") + $> "" + <~?> (\_ -> "28") *> string " " - $> "" <~?> \_ -> "29" + $> "" + <~?> \_ -> "29" , fail "test " , "41" string " " , "42" string " " <|> string " " , "43" string " " <|> "44" string " " - , "45" "" <$ string " " - <|> "46" + , "45" + "" <$ string " " + <|> "46" string " " $> "" - <|> "47" + <|> "47" const "" <$> string " " <* ("48" string " ") *> ("49" string " ") From 52e462be97c91fae6a15c8493328bc119413f1d1 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 17:01:49 -0500 Subject: [PATCH 15/17] Undo formatting changes --- test/Main.purs | 51 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index c6002dd..ed26092 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -689,50 +689,29 @@ main = do , string " " "1" , string " " <|> string " " "2" , string " " "3" <|> string " " "4" - , "" <$ string " " - "5" - <|> string " " - $> "" - "6" - <|> const "" - <$> string " " - "7" - <* string " " - $> "" - "8" - *> string " " - $> "" - "9" + , "" <$ string " " "5" + <|> string " " $> "" "6" + <|> const "" <$> string " " "7" + <* string " " $> "" "8" + *> string " " $> "" "9" , fail "test <~?>" , string " " <~?> \_ -> "21" , string " " <|> string " " <~?> \_ -> "22" , string " " <~?> (\_ -> "23") <|> string " " <~?> \_ -> "24" - , "" <$ string " " - <~?> (\_ -> "25") - <|> string " " - $> "" - <~?> (\_ -> "26") - <|> const "" - <$> string " " - <~?> (\_ -> "27") - <* string " " - $> "" - <~?> (\_ -> "28") - *> string " " - $> "" - <~?> \_ -> "29" + , "" <$ string " " <~?> (\_ -> "25") + <|> string " " $> "" <~?> (\_ -> "26") + <|> const "" <$> string " " <~?> (\_ -> "27") + <* string " " $> "" <~?> (\_ -> "28") + *> string " " $> "" <~?> \_ -> "29" , fail "test " , "41" string " " , "42" string " " <|> string " " , "43" string " " <|> "44" string " " - , "45" - "" <$ string " " - <|> "46" - string " " $> "" - <|> "47" - const "" <$> string " " - <* ("48" string " ") - *> ("49" string " ") + , "45" "" <$ string " " + <|> "46" string " " $> "" + <|> "47" const "" <$> string " " + <* ("48" string " ") + *> ("49" string " ") ] ) "no" From 10e4133e8847414590aa9c9faa809dbc7aa83bef Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 17:15:12 -0500 Subject: [PATCH 16/17] Fix tidy operators table --- .tidyoperators | 224 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) diff --git a/.tidyoperators b/.tidyoperators index fcf3aa6..778d286 100644 --- a/.tidyoperators +++ b/.tidyoperators @@ -1,7 +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 From 5e81788afb386067ae78a059c194462c16f40698 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Thu, 24 Mar 2022 17:17:28 -0500 Subject: [PATCH 17/17] Rerun formatter --- src/Text/Parsing/Parser/Expr.purs | 2 +- src/Text/Parsing/Parser/Token.purs | 11 ++++---- test/Main.purs | 44 ++++++++++++++++++------------ 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/Text/Parsing/Parser/Expr.purs b/src/Text/Parsing/Parser/Expr.purs index cc0e148..88a4b0e 100644 --- a/src/Text/Parsing/Parser/Expr.purs +++ b/src/Text/Parsing/Parser/Expr.purs @@ -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 diff --git a/src/Text/Parsing/Parser/Token.purs b/src/Text/Parsing/Parser/Token.purs index 94deb86..12a418b 100644 --- a/src/Text/Parsing/Parser/Token.purs +++ b/src/Text/Parsing/Parser/Token.purs @@ -463,7 +463,7 @@ makeTokenParser (LanguageDef languageDef) = stringChar = (Just <$> stringLetter) <|> stringEscape - "string character" + "string character" stringLetter :: ParserT String m Char stringLetter = satisfy (\c -> (c /= '"') && (c /= '\\') && (c > '\x1A')) @@ -686,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 @@ -866,7 +867,7 @@ inCommentMulti langDef@(LanguageDef languageDef) = <|> (multiLineComment langDef *> p) <|> (skipMany1 (noneOf startEnd) *> p) <|> (oneOf startEnd *> p) - "end of comment" + "end of comment" where startEnd :: Array Char startEnd = SCU.toCharArray languageDef.commentEnd <> SCU.toCharArray languageDef.commentStart @@ -877,7 +878,7 @@ inCommentSingle (LanguageDef languageDef) = (void $ try (string languageDef.commentEnd)) <|> (skipMany1 (noneOf startEnd) *> p) <|> (oneOf startEnd *> p) - "end of comment" + "end of comment" where startEnd :: Array Char startEnd = SCU.toCharArray languageDef.commentEnd <> SCU.toCharArray languageDef.commentStart diff --git a/test/Main.purs b/test/Main.purs index ed26092..4db59c9 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -158,7 +158,7 @@ stackSafeLoopsTest = do parseTest "aaaabcd" "b" $ skipMany1Rec (string "a") - *> string "b" + *> string "b" parseErrorTestPosition (skipMany1Rec (string "a")) "bcd" @@ -166,10 +166,10 @@ stackSafeLoopsTest = do parseTest "aaaabcd" "b" $ skipManyRec (string "a") - *> string "b" + *> string "b" parseTest "bcd" "b" $ skipManyRec (string "a") - *> string "b" + *> string "b" parseTest "aaa" (NE.cons' "a" $ toUnfoldable [ "a", "a" ]) $ many1Rec (string "a") @@ -180,13 +180,13 @@ stackSafeLoopsTest = do parseTest "a,a,ab" (toUnfoldable [ "a", "a", "a" ]) $ sepByRec (string "a") (string ",") - <* string "b" + <* string "b" parseTest "b" Nil $ sepByRec (string "a") (string ",") - <* string "b" + <* string "b" parseTest "a,a,ab" (NE.cons' "a" $ toUnfoldable [ "a", "a" ]) $ sepBy1Rec (string "a") (string ",") - <* string "b" + <* string "b" parseErrorTestPosition (sepBy1Rec (string "a") (string ",")) "" @@ -198,13 +198,13 @@ stackSafeLoopsTest = do parseTest "a,a,a,b" (toUnfoldable [ "a", "a", "a" ]) $ endByRec (string "a") (string ",") - <* string "b" + <* string "b" parseTest "b" Nil $ endByRec (string "a") (string ",") - <* string "b" + <* string "b" parseTest "a,a,a,b" (NE.cons' "a" $ toUnfoldable [ "a", "a" ]) $ endBy1Rec (string "a") (string ",") - <* string "b" + <* string "b" parseErrorTestPosition (endBy1Rec (string "a") (string ",")) "" @@ -692,8 +692,12 @@ main = do , "" <$ string " " "5" <|> string " " $> "" "6" <|> const "" <$> string " " "7" - <* string " " $> "" "8" - *> string " " $> "" "9" + <* string " " + $> "" + "8" + *> string " " + $> "" + "9" , fail "test <~?>" , string " " <~?> \_ -> "21" , string " " <|> string " " <~?> \_ -> "22" @@ -701,17 +705,23 @@ main = do , "" <$ string " " <~?> (\_ -> "25") <|> string " " $> "" <~?> (\_ -> "26") <|> const "" <$> string " " <~?> (\_ -> "27") - <* string " " $> "" <~?> (\_ -> "28") - *> string " " $> "" <~?> \_ -> "29" + <* string " " + $> "" + <~?> (\_ -> "28") + *> string " " + $> "" + <~?> \_ -> "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"