Re: [Haskell-cafe] Parsec error message not making any sense
Hi Roman, I'm using parsec-3.1.3 I put the code in a gist here - sorry about that. https://gist.github.com/dargosch/5955045 Fredrik On Tue, Jul 9, 2013 at 12:08 AM, Roman Cheplyaka r...@ro-che.info wrote: Hi Fredrik, First, do you use the latest parsec version (3.1.3)? If not, can you try the same with 3.1.3? Second, please upload your code to hpaste.org or a similar service and give us the link. It's not much fun to extract code from an html email. Roman * Fredrik Karlsson dargo...@gmail.com [2013-07-08 23:54:17+0200] 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. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. testdata.TextGrid Description: Binary data ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec error message not making any sense
Hi, Sorry, that was a careless extraction of code - I should have made sure that it was complete. Please, have a look again. When downloading and running the gist ( https://gist.github.com/dargosch/5955045) , I still get the error: Main let testFile = /Users/frkkan96/Documents/src/ume/umecore/testing/testdata/testdata.TextGrid *Main parseFromFile textgridfile testFile Left /Users/frkkan96/Documents/src/ume/umecore/testing/testdata/testdata.TextGrid (line 35, column 5): unexpected t expecting intervals [ on the attached testfile. The tier parser works once, but then I get an error that I cant understand, given the input. How come the parser finds the unexpected t when the expected thing is what is in the input at that point? Thankful for any help I can get on this. On Tue, Jul 9, 2013 at 10:22 PM, Fredrik Karlsson dargo...@gmail.comwrote: Hi, Sorry, that was a careless extraction of code - I should have made sure that it was complete. Please, have a look again. When downloading and running the gist, I still get the error: Main let testFile = /Users/frkkan96/Documents/src/ume/umecore/testing/testdata/testdata.TextGrid *Main parseFromFile textgridfile testFile Left /Users/frkkan96/Documents/src/ume/umecore/testing/testdata/testdata.TextGrid (line 35, column 5): unexpected t expecting intervals [ on the attached testfile. The tier parser works once, but then I get an error that I cant understand, given the input. How come the parser finds the unexpected t when the expected thing is what is in the input at that point? Thankful for any help I can get on this. /Fredrik On Tue, Jul 9, 2013 at 9:37 AM, Roman Cheplyaka r...@ro-che.info wrote: Please check your code. I had two problems with it: mixed tabs and spaces, and undefined 'quotedChar'. After defining quotedChar = anyChar, I get a different error message from yours: *Main parseFromFile textgridfile testdata.TextGrid Left testdata.TextGrid (line 137, column 1): unexpected end of input expecting quote at end of cell Roman * Fredrik Karlsson dargo...@gmail.com [2013-07-09 08:07:24+0200] Hi Roman, I'm using parsec-3.1.3 I put the code in a gist here - sorry about that. https://gist.github.com/dargosch/5955045 Fredrik On Tue, Jul 9, 2013 at 12:08 AM, Roman Cheplyaka r...@ro-che.info wrote: Hi Fredrik, First, do you use the latest parsec version (3.1.3)? If not, can you try the same with 3.1.3? Second, please upload your code to hpaste.org or a similar service and give us the link. It's not much fun to extract code from an html email. Roman * Fredrik Karlsson dargo...@gmail.com [2013-07-08 23:54:17+0200] 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
[Haskell-cafe] Parsec : parse either an interger or a double?
Dear list, Sorry for asking you another parsec question. I have a text file that is the output of a C/C++ program, involving time references in double format. Now, the program seems to truncate the output if possible, so a file that is one second long will produce this file: File type = ooTextFile Object class = TextGrid xmin = 0 xmax = 1 and a file that is 1.1 seconds long will be this: File type = ooTextFile Object class = TextGrid xmin = 0 xmax = 1.1 ... Now, how do I handle this case in parsec? I have tried this: start - try (float haskellDef) | fmap ( / 1.0 ) $ integer haskelldef and similar solutions, but I cant get it to accept the 0. /Fredrik -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec : parse either an interger or a double?
Sorry for answering my own question : end - try (float haskelldef) | (fmap fromInteger $ integer haskelldef ) appears to work nicelly. Sorry about that. /Fredrik On Sun, Jul 7, 2013 at 1:57 PM, Fredrik Karlsson dargo...@gmail.com wrote: Dear list, Sorry for asking you another parsec question. I have a text file that is the output of a C/C++ program, involving time references in double format. Now, the program seems to truncate the output if possible, so a file that is one second long will produce this file: File type = ooTextFile Object class = TextGrid xmin = 0 xmax = 1 and a file that is 1.1 seconds long will be this: File type = ooTextFile Object class = TextGrid xmin = 0 xmax = 1.1 ... Now, how do I handle this case in parsec? I have tried this: start - try (float haskellDef) | fmap ( / 1.0 ) $ integer haskelldef and similar solutions, but I cant get it to accept the 0. /Fredrik -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Basic Parsec float integer parsing question
Dear list, Sorry for asking a simple parsec question, but both Parsec and Haskell is new to me, so please be gentle :-) I have this code: import Text.ParserCombinators.Parsec import Text.Parsec.Token import Text.ParserCombinators.Parsec.Char data VariableLine = VariableLine String String deriving Show data TierType = IntervalTier | PointTier deriving Show data Tier = Tier TierType String Float Float Integer data Label = Interval Float Float String data LabelFile = LabelFile Float Float symbol :: Parser Char symbol = oneOf !#$%|*+-/:=?@^_~ testString = intervals [1]:\nxmin = 0 \nxmax = 0.028192 \ntext = \\ headTS1 = File type = \ooTextFile\\nObject class = \TextGrid\\n\nxmin = header :: Parser LabelFile header = do headTS1 start - float string \nxmax = end - float string \ntiers? exists\nsize = integer char '\n' return $ LabelFile start end Loading it into ghci I get : Prelude :l parsectest.hs [1 of 1] Compiling Main ( parsectest.hs, interpreted ) parsectest.hs:21:9: Couldn't match type `[]' with `Text.Parsec.Prim.ParsecT String () Data.Functor.Identity.Identity' Expected type: Text.Parsec.Prim.ParsecT String () Data.Functor.Identity.Identity Char Actual type: [Char] In a stmt of a 'do' block: headTS1 In the expression: do { headTS1; start - float; string \ \xmax = ; end - float; } In an equation for `header': header = do { headTS1; start - float; string \ \xmax = ; } parsectest.hs:22:18: Couldn't match expected type `Text.Parsec.Prim.ParsecT String () Data.Functor.Identity.Identity Float' with actual type `GenTokenParser s0 u0 m0 - Text.Parsec.Prim.ParsecT s0 u0 m0 Double' In a stmt of a 'do' block: start - float In the expression: do { headTS1; start - float; string \ \xmax = ; end - float; } In an equation for `header': header = do { headTS1; start - float; string \ \xmax = ; } parsectest.hs:24:16: Couldn't match expected type `Text.Parsec.Prim.ParsecT String () Data.Functor.Identity.Identity Float' with actual type `GenTokenParser s1 u1 m1 - Text.Parsec.Prim.ParsecT s1 u1 m1 Double' In a stmt of a 'do' block: end - float In the expression: do { headTS1; start - float; string \ \xmax = ; end - float; } In an equation for `header': header = do { headTS1; start - float; string \ \xmax = ; } parsectest.hs:26:9: Couldn't match expected type `Text.Parsec.Prim.ParsecT String () Data.Functor.Identity.Identity a0' with actual type `GenTokenParser s2 u2 m2 - Text.Parsec.Prim.ParsecT s2 u2 m2 Integer' In a stmt of a 'do' block: integer In the expression: do { headTS1; start - float; string \ \xmax = ; end - float; } In an equation for `header': header = do { headTS1; start - float; string \ \xmax = ; } Failed, modules loaded: none. I'm sure I'm doing something really stupid here, but I need help to get through this problem. I've used the predefined letter parser at other places in the code, so I can't understand why float and integer does not work. /Fredrik -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe