attoparsec and line/col numbers

127 views
Skip to first unread message

Daniel

unread,
Dec 2, 2011, 8:46:47 PM12/2/11
to Stanford CS240h 2011 Autumn
Is there a way to get the line and column numbers of the cursor out of
attoparsec as you are parsing?

Drew Haven

unread,
Dec 2, 2011, 8:50:34 PM12/2/11
to stanford-1...@googlegroups.com
If I recall, one of the ways Attoparsec gains its speed (as it is much faster than Parsec) is by sacrificing a lot of conveniences like tracking line and column numbers.  You can use the <?> operator to set custom error messages though, which will help you identify why a failure occurs, but I don't know how to get the line/column number as you are going in case you wanted to do something like tagging tokens for errors during later analysis.

Drew Haven
drew....@gmail.com

Daniel Sommermann

unread,
Dec 3, 2011, 2:20:07 AM12/3/11
to stanford-1...@googlegroups.com, Drew Haven
So if I want those features, I'll need to use another parser, such as parsec. Thanks for the info. Should it be straightforward to convert attoparsec parsers to parsec parsers? Any good/recommended tutorials on parsec? I found http://book.realworldhaskell.org/read/using-parsec.html already, which is proving helpful.

Drew Haven

unread,
Dec 3, 2011, 1:15:35 PM12/3/11
to Daniel Sommermann, stanford-1...@googlegroups.com
Exactly.  I find this line in the lecture notes.  I knew I remembered Brian mentioning it.  Parsec is very similar, and I've used it in the past.  Give it a look.

attoparsec does not attempt to give friendly error messages (no file names or line numbers). Parsec might be a better choice for e.g. parsing source files, where the friendliness/performance tradeoff is a little different.

Drew Haven
drew....@gmail.com
Reply all
Reply to author
Forward
0 new messages