[Haskell-cafe] Parsec error message not making any sense

Fredrik Karlsson dargosch at gmail.com
Mon Jul 8 23:54:17 CEST 2013


Dear list,

I have a Parsec parser that fails and gives the following error message:

*Main> parseFromFile textgridfile testFile
Left
"/Users/frkkan96/Documents/src/ume/umecore/testing/testdata/testdata.TextGrid"
(line 35, column 5):
unexpected "t"
expecting "intervals ["

Now, this is perfectly understandable, but line 35, col 5 in the file being
parsed looks like the supplies image - there is no 't' there.

Any ideas on what is going on?

The parser I am using is:

data VariableLine = VariableLine String String deriving Show
data TierType = IntervalTier | PointTier deriving Show

data Tier = Tier String deriving Show
data LabelFile = LabelFile Double Double deriving Show

data Label = Label String TierType Double Double String deriving Show


haskelldef = makeTokenParser haskellDef


textgridfile :: Parser (LabelFile, [[Label]])
textgridfile = do
h <- header
ll <- many1 tier
return $ (h,ll)

header :: Parser LabelFile
header = do
string headTS1
start <- try (float haskelldef)
<|> (fmap fromInteger $ integer haskelldef )
string "xmax = "
end <- try (float haskelldef)
<|> (fmap fromInteger $ integer haskelldef )
string "tiers? <exists> \n"
string "size = "
integer haskelldef
string "item []:"
whiteSpace haskelldef
return $ LabelFile start end

tier :: Parser [Label]
tier = do
whiteSpace haskelldef
string "item ["
integer haskelldef
string "]:"
whiteSpace haskelldef
try (string "class = \"IntervalTier\"")
<|> string "class = \"TextTier\""
whiteSpace haskelldef
string "name = "
char '"'
name <- many quotedChar
char '"' <?> "quote at end of cell"
whiteSpace haskelldef
string "xmin = "
try (float haskelldef) <|> (fmap fromInteger $ integer haskelldef )
whiteSpace haskelldef
string "xmax = "
try (float haskelldef) <|> (fmap fromInteger $ integer haskelldef )
string "intervals: size = " <|> string "points: size = "
integer haskelldef
whiteSpace haskelldef
labelList <- many1 (interval name)
return $ labelList
interval :: String -> Parser Label
interval tierName = do
whiteSpace haskelldef
string "intervals ["
integer haskelldef
string "]:"
whiteSpace haskelldef
string "xmin = "
start <- try (float haskelldef)
<|> (fmap fromInteger $ integer haskelldef )
whiteSpace haskelldef
string "xmax = "
end <- try (float haskelldef)
<|> (fmap fromInteger $ integer haskelldef )
whiteSpace haskelldef
string "text = "
char '"'
text <- many quotedChar
char '"' <?> "quote at end of cell"
return $ Label tierName IntervalTier start end text

which fails on the attached input file.

I can't see how 't' is found?? What am I doing wrong?

/Fredrik



-- 
"Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130708/279fe67b/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Ska?rmavbild 2013-07-08 kl. 23.43.41.png
Type: image/png
Size: 142509 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130708/279fe67b/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testdata.TextGrid
Type: application/octet-stream
Size: 3793 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130708/279fe67b/attachment-0001.obj>


More information about the Haskell-Cafe mailing list