module Data.Music.Abc.Parser (
parse
) where
import Data.Monoid
import Data.Either
import Control.Monad
import Control.Applicative hiding ((<|>), optional, many)
import Text.Parsec hiding (parse)
import Text.Parsec.Token
import Text.Parsec.String
import Data.Music.Abc
parse :: String -> Either ParseError AbcFile
parse = runParser abcFile () ""
abcFile :: Parser AbcFile
abcFile = do
string "%abc"
optional $ string "-" >> version
optional $ fileHeader
fileBody
return undefined
fileHeader :: Parser FileHeader
fileHeader = fmap (uncurry FileHeader . partitionEithers) $ many1 $ mzero
<|> fmap Left informationField
<|> fmap Right styleSheetDirective
fileBody :: Parser [Element]
fileBody = (flip sepBy) emptyLine $ mzero
<|> fmap Tune abcTune
<|> fmap FreeText freeText
<|> fmap TypesetText typeSetText
informationField :: Parser Information
informationField = do
letter
char ':'
char '\n'
return undefined
styleSheetDirective :: Parser Directive
styleSheetDirective = mzero
byteOrderMark :: Parser ()
byteOrderMark = do
char '\xFFFE' <|> char '\xFEFF'
return ()
version :: Parser Double
version = undefined
abcTune :: Parser AbcTune
abcTune = undefined
freeText :: Parser String
freeText = undefined
typeSetText :: Parser String
typeSetText = mzero
lexer :: TokenParser ()
lexer = makeTokenParser $ LanguageDef {
commentStart = "[r:",
commentEnd = "]",
commentLine = "%",
nestedComments = False,
identStart = (letter <|> char '_'),
identLetter = (alphaNum <|> char '_'),
opStart = mzero,
opLetter = mzero,
reservedNames = reservedNames,
reservedOpNames = mzero,
caseSensitive = True
}
where
reservedNames = []
llex = lexeme lexer
lnat = natural lexer
lstr = stringLiteral lexer
lname = identifier lexer
lres = reserved lexer
lspace = whiteSpace lexer
emptyLine = newLine >> newLine
newLine = string "\r\n" <|> string "\n"
single x = [x]
notSupported x = error $ "Not supported yet: " ++ x