Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6953569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:29:47+00:00 2026-05-27T14:29:47+00:00

I’m trying to create a parser (with parsec), that parses tokens, delimited by newlines,

  • 0

I’m trying to create a parser (with parsec), that parses tokens, delimited by newlines, commas, semicolons and unicode dashes (ndash and mdash):

authorParser = do
    name <- many1 (noneOf [',', ':', '\r', '\n', '\8212', '\8213'])
    many (char ',' <|> char ':' <|> char '-' <|> char '\8212' <|> char '\8213')

But the ndash-mdash (\8212, \8213) part never ‘succeeds’ and i’m getting invalid parse results.

How do i specify unicode dashes with char parser?

P.S. I’ve tried (chr 8212), (chr 8213) too. It doesn’t helps.

ADDITION: It is better to use Data.Text. The switch from ByteStrings madness to Data.Text saved me a lot of time and ‘source space’ 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:29:47+00:00Added an answer on May 27, 2026 at 2:29 pm

    Works for me:

    Prelude Text.ParserCombinators.Parsec> let authorName = do { name <- many1 (noneOf ",:\r\n\8212\8213"); many (oneOf ",:-\8212\8213"); }
    Prelude Text.ParserCombinators.Parsec> parse authorName "" "my Name,\8212::-:\8213,"
    Right ",\8212::-:\8213,"
    

    How did you try?

    The above was using plain String, which works without problems because a Char is a full uncode code point. It’s not as nice with other types of input stream. Text will probably also work well for this example, I think that the dashes are encoded as a single code unit there. For ByteString, however, things are more complicated. If you’re using plain Data.ByteString.Char8 (strict or lazy, doesn’t matter), the Chars get truncated on packing, only the least significant 8 bits are retained, so ‘\8212’ becomes 20 and ‘\8213’ becomes 21. If the input stream is constructed the same way, that still kind of works, only all Chars congruent to 20 or 21 modulo 256 will be mapped to the same as one of the dashes.

    However, it is likely that the input stream is UTF-8 encoded, then the dashes are encoded as three bytes each, “\226\128\148” resp. “\226\128\149”, which doesn’t match what you get by truncating. Trying to parse utf-8 encoded text with ByteString and parsec is a bit more involved, the units of which the parse result is composed are not single bytes, but sequences of bytes, 1-4 in length each.

    To use noneOf, you need an

    instance Text.Parsec.Prim.Stream ByteString m Char
    

    which does the right thing. The instance provided in Text.Parsec.ByteString[.Lazy] doesn’t, it uses the Data.ByteString[.Lazy].Char8 interface, so an en-dash would become a single ‘\20’ not matching ‘\8212’ or produce three Chars, ‘\226’, ‘\128’ and ‘\148’ in three successive calls to uncons, none of which matches ‘\8212’ either, depending on how the input was encoded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.