Skip to content

Commit

Permalink
Merge pull request #941 from dktr0/main
Browse files Browse the repository at this point in the history
catching up tidal and tidal-parse to each other
  • Loading branch information
yaxu authored Sep 14, 2022
2 parents 860a480 + 4db0d1a commit 1a5963f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
16 changes: 8 additions & 8 deletions tidal-parse/src/Sound/Tidal/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions tidal-parse/test/Sound/Tidal/TidalParseTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 1 addition & 2 deletions tidal-parse/tidal-parse.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a5963f

Please sign in to comment.