From c80c5d9d621d60b6ca83f5d6cd8f8cb6974f65ac Mon Sep 17 00:00:00 2001 From: David Ogborn Date: Fri, 20 May 2022 16:52:49 -0400 Subject: [PATCH 1/2] tidal-parse: added new test to verify that code that is only a comment is parsed as silence --- tidal-parse/test/Sound/Tidal/TidalParseTest.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tidal-parse/test/Sound/Tidal/TidalParseTest.hs b/tidal-parse/test/Sound/Tidal/TidalParseTest.hs index 849f3e981..0e68f9279 100644 --- a/tidal-parse/test/Sound/Tidal/TidalParseTest.hs +++ b/tidal-parse/test/Sound/Tidal/TidalParseTest.hs @@ -30,6 +30,12 @@ run = it "parses a string containing only spaces as silence" $ " " `parsesTo` silence + it "parses a string containing only a one-line comment as silence" $ + "-- commented out" `parsesTo` silence + + it "parses a string containing only a multi-line comment as silence" $ + "{- commented out \n this is another line}" `parsesTo` silence + it "parses the identifier silence as silence" $ "silence" `parsesTo` silence From ac66771fd5201d6f669b80570a3623b0f33f3704 Mon Sep 17 00:00:00 2001 From: David Ogborn Date: Fri, 3 Jun 2022 11:42:16 -0400 Subject: [PATCH 2/2] tidal-parse: fixed bug where programs that are only comments would be errors --- tidal-parse/src/Sound/Tidal/Parse.hs | 16 ++++++++-------- tidal-parse/test/Sound/Tidal/TidalParseTest.hs | 6 ++++++ tidal-parse/tidal-parse.cabal | 3 +-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tidal-parse/src/Sound/Tidal/Parse.hs b/tidal-parse/src/Sound/Tidal/Parse.hs index 522d332cf..c506e24a7 100644 --- a/tidal-parse/src/Sound/Tidal/Parse.hs +++ b/tidal-parse/src/Sound/Tidal/Parse.hs @@ -2,7 +2,6 @@ module Sound.Tidal.Parse (parseTidal) where -import Language.Haskell.Exts import Language.Haskellish as Haskellish import Control.Applicative import Data.Bifunctor @@ -20,13 +19,14 @@ type H = Haskellish () -- This is depended upon by Estuary, and changes to its type will cause problems downstream for Estuary. parseTidal :: String -> Either String ControlPattern -parseTidal x = - if strip x == [] then (return T.silence) - else (f $ Language.Haskell.Exts.parseExp x) - where - strip = dropWhileEnd isSpace . dropWhile isSpace - f (ParseOk x') = second fst $ runHaskellish parser () x' - f (ParseFailed l s) = throwError $ show l ++ ": " ++ show s +parseTidal x = if x' == [] then (return T.silence) else r + where + x' = dropWhileEnd isSpace $ dropWhile isSpace $ Haskellish.removeComments x + r = bimap showSyntaxError fst $ Haskellish.parseAndRun parser () x + +showSyntaxError :: (Span,Data.Text.Text) -> String +showSyntaxError (((lineNumber,columnNumber),(_,_)),msg) = + show lineNumber ++ ":" ++ show columnNumber ++ " " ++ Data.Text.unpack msg -- The class Parse is a class for all of the types that we know how to parse. diff --git a/tidal-parse/test/Sound/Tidal/TidalParseTest.hs b/tidal-parse/test/Sound/Tidal/TidalParseTest.hs index 0e68f9279..1b5a47208 100644 --- a/tidal-parse/test/Sound/Tidal/TidalParseTest.hs +++ b/tidal-parse/test/Sound/Tidal/TidalParseTest.hs @@ -42,6 +42,12 @@ run = it "parses a very simple single 's' pattern" $ "s \"bd cp\"" `parsesTo` s "bd cp" + it "parses a very simple single 's' pattern with a same line comment" $ + "s \"bd cp\" -- comment " `parsesTo` s "bd cp" + + it "parses a very simple single 's' pattern with a multi line comment" $ + "s \"bd cp\" {- \n comment -}" `parsesTo` s "bd cp" + it "parses a very simple single 'sound' pattern" $ "sound \"bd cp\"" `parsesTo` sound "bd cp" diff --git a/tidal-parse/tidal-parse.cabal b/tidal-parse/tidal-parse.cabal index 1ee681702..7d5006e2e 100644 --- a/tidal-parse/tidal-parse.cabal +++ b/tidal-parse/tidal-parse.cabal @@ -32,9 +32,8 @@ library base >=4.8 && <5 , tidal >= 1.8 && <1.9 , transformers >= 0.5 && < 0.5.7 - , haskell-src-exts >= 1.17.1 && < 1.24 , template-haskell - , haskellish + , haskellish >= 0.3.2 && < 0.4 , containers < 0.7 , mtl >= 2.2.2 && <2.3 , text < 1.3