diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..7f1f486 --- /dev/null +++ b/default.nix @@ -0,0 +1,6 @@ +{ pkgs ? import {} }: +with pkgs.haskellPackages; +developPackage { + root = ./.; + modifier = drv: pkgs.haskell.lib.addBuildTools drv [ cabal-install ghcid ]; +} diff --git a/package.yaml b/package.yaml index 9fe554c..89b7f15 100644 --- a/package.yaml +++ b/package.yaml @@ -21,7 +21,6 @@ description: Please see the README on GitHub at = 4.7 && < 5 -- megaparsec >= 8.0 && < 9 library: source-dirs: src diff --git a/pie.cabal b/pie.cabal index 4472645..c5c2da0 100644 --- a/pie.cabal +++ b/pie.cabal @@ -34,7 +34,6 @@ library src build-depends: base >=4.7 && <5 - , megaparsec >=8.0 && <9 default-language: Haskell2010 executable pie-exe @@ -46,7 +45,6 @@ executable pie-exe ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 - , megaparsec >=8.0 && <9 , pie default-language: Haskell2010 @@ -60,6 +58,5 @@ test-suite pie-test ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.7 && <5 - , megaparsec >=8.0 && <9 , pie default-language: Haskell2010 diff --git a/src/Lib.hs b/src/Lib.hs index 9b9fb51..d04050f 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -1,11 +1,13 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE LambdaCase #-} module Lib ( someFunc ) where - +import Control.Monad ( forM_ ) +{- import Data.Void import qualified Text.Megaparsec as Parsec import qualified Text.Megaparsec.Stream as Parsec @@ -38,7 +40,7 @@ parseRoot = () <$ do where satisfyFeature :: (FeatureSet -> Bool) -> Parsec.Parsec Void [Phoneme] Phoneme satisfyFeature p = Parsec.satisfy (p . features) - +-} data Manner = Tenuis | Media | MediaAspirata @@ -50,9 +52,44 @@ data Place = Labial | Dental | Palatal | Velar | Labiovelar data Phoneme = E | O | A | E_ | O_ | A_ | I | U | N | M | R | L - | P | B | Bh | T | D | Dh | Kj | Gj | Gjh | K | G | Gh | Kw | Gw | Gwh | S | H1 | H2 | H3 + | P | B | Bh | T | D | Dh | Kj | Gj | Gjh | K | G | Gh | Kw | Gw | Gwh | S | H1 | H2 | H3 | H deriving (Eq, Ord) +instance Show Phoneme where + show = \case + E -> "e" + O -> "o" + A -> "a" + E_ -> "ē" + O_ -> "ō" + A_ -> "ā" + I -> "i" + U -> "u" + N -> "n" + M -> "m" + R -> "r" + L -> "l" + P -> "p" + B -> "b" + Bh -> "bh" + T -> "t" + D -> "d" + Dh -> "dh" + Kj -> "ḱ" + Gj -> "ǵ" + Gjh -> "ǵh" + K -> "k" + G -> "g" + Gh -> "gh" + Kw -> "kʷ" + Gw -> "gʷ" + Gwh -> "gʷh" + S -> "s" + H1 -> "h₁" + H2 -> "h₂" + H3 -> "h₃" + H -> "H" + data FeatureSet = Vowel | Resonant @@ -69,7 +106,7 @@ features :: Phoneme -> FeatureSet features phoneme | phoneme == S = Sibilant | phoneme `elem` [E, O, A, E_, O_, A_] = Vowel - | phoneme `elem` [H1, H2, H3] = Laryngeal + | phoneme `elem` [H1, H2, H3, H] = Laryngeal | phoneme `elem` [I, U, N, M, R, L] = Resonant | otherwise = Plosive { manner = if @@ -85,6 +122,55 @@ features phoneme } +syllabify :: [Phoneme] -> [Bool] +syllabify = foldr isSonant [] + where + hasToBeSyllabic p = features p == Vowel + canBeSyllabic p = features p `elem` [Vowel, Resonant, Laryngeal] + isSonant current xs = case xs of + [] -> [hasToBeSyllabic current] -- last phoneme in word + previousIsSonant : _ -> if previousIsSonant + then hasToBeSyllabic current : xs -- only vowels are sonant, the rest can be consonantal + else canBeSyllabic current : xs -- make syllabic if previous is not syllabic + +showSyllabic :: Phoneme -> Bool -> String +showSyllabic phoneme syllabic = case (phoneme, syllabic) of + (I , False) -> "y" + (U , False) -> "w" + (N , True ) -> "ṇ" + (M , True ) -> "ṃ" + (R , True ) -> "ṛ" + (L , True ) -> "ḷ" + (H1, True ) -> "ə₁" + (H2, True ) -> "ə₂" + (H3, True ) -> "ə₃" + (H , True ) -> "ə" + _ -> show phoneme + +printSyllabified ps = + putStr (concatMap show ps) >> putChar ' ' >> print (syllabify ps) someFunc :: IO () -someFunc = Parsec.parseTest parseRoot [P, R, E, Kj] +someFunc = do + let pieLines = + [ [Kj, M, T, O, M] + , [N, E, H2, U, S] + , [I, U, N, E, G, T, I] + , [I, U, N, G, E, N, T, I] + , [H2, N, R, Bh, I] + , [H2, E, R, H3, T, R, O, M] + , [H2, I, U, H, O, N] + , [H2, S, N, T, I, E, H2] + , [Gh, E_, I, M, N, O] + , [Kj, U, N, Bh, I] + , [D, I, U, O, S] + , [N, M, R, T, O, S] + , [U, L, Kw, O, S] + , [Kj, U, N, O, S] + , [D, N, T, N, S] + , [N, D, R, Kj, T, O, S] + , [U, N, T, O, S] + , [D, U, I, D, Kj, M, T] + ] + forM_ pieLines + $ \line -> putStrLn $ concat $ zipWith showSyllabic line (syllabify line)