add script to lántas pages
This commit is contained in:
parent
ba5522187c
commit
f61e5b1146
13 changed files with 332 additions and 143 deletions
|
@ -1,5 +1,3 @@
|
|||
{-# OPTIONS_GHC -fdefer-typed-holes #-}
|
||||
|
||||
module Split (split) where
|
||||
|
||||
import Glyphs
|
||||
|
@ -16,11 +14,14 @@ import Data.Void
|
|||
type P = Parsec Void Text
|
||||
|
||||
|
||||
lcChar :: P Char
|
||||
lcChar = Char.toLower <$> anySingle
|
||||
|
||||
longestWith :: String -> (Text -> Maybe a) -> P a
|
||||
longestWith name p = try $ go . Text.singleton =<< anySingle where
|
||||
longestWith name p = try $ go . Text.singleton =<< lcChar where
|
||||
go acc = case p acc of
|
||||
Nothing -> fail $ "longestWith " <> name <> ": " <> show acc
|
||||
Just x -> try (do c <- anySingle; go $ Text.snoc acc c) <|> pure x
|
||||
Just x -> try (do c <- lcChar; go $ Text.snoc acc c) <|> pure x
|
||||
|
||||
maxFrom :: String -> Map Text a -> P a
|
||||
maxFrom name i = longestWith name \x -> Map.lookup x i
|
||||
|
@ -29,7 +30,7 @@ initial :: P Glyph
|
|||
initial = maxFrom "initial" initials
|
||||
|
||||
medial :: P Segs
|
||||
medial = maxFrom "medial" medials
|
||||
medial = P [] <$ chunk "\\" <|> maxFrom "medial" medials
|
||||
|
||||
final :: P Glyph
|
||||
final = maxFrom "final" finals
|
||||
|
@ -40,18 +41,22 @@ ivowel = maxFrom "vowel" vowels
|
|||
word :: P [Piece]
|
||||
word = (<>) <$> some initMed <*> fin where
|
||||
initMed = try $
|
||||
[(i, ms) | i <- initial, ms <- some medial] <|>
|
||||
[(v, []) | v <- ivowel]
|
||||
[(i, [m]) | i <- initial, m <- medial] <|>
|
||||
[(v, []) | v <- ivowel] <|>
|
||||
dash
|
||||
fin = maybe [] (\x -> [(x, [])]) <$> optional final
|
||||
|
||||
number :: P [Piece]
|
||||
number = [[h1] <> ns <> [h2] | h1 <- hash, ns <- some digit, h2 <- hash] where
|
||||
number = some (digit <|> hash) where
|
||||
hash = (num, []) <$ chunk "#"
|
||||
digit = [(numbers ! Char.digitToInt i, []) | i <- digitChar]
|
||||
|
||||
punct :: P [Piece]
|
||||
punct = [[(p, [])] | p <- maxFrom "punctuation" punctuation]
|
||||
|
||||
dash :: P Piece
|
||||
dash = (wave, []) <$ chunk "–"
|
||||
|
||||
text :: P [[Piece]]
|
||||
text = space *> many (segment <* space) <* eof where
|
||||
segment = punct <|> number <|> word
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue