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 bd1013705..6da8852d3 100644 --- a/tidal-parse/test/Sound/Tidal/TidalParseTest.hs +++ b/tidal-parse/test/Sound/Tidal/TidalParseTest.hs @@ -30,12 +30,24 @@ 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 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 d1b0d5a13..bdd3af2be 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.10 , transformers >= 0.5 && < 0.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 < 2.1