From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/17685 Path: news.gmane.org!.POSTED!not-for-mail From: Jeff Newsgroups: gmane.text.pandoc Subject: simple question about using manyTill Date: Wed, 24 May 2017 08:35:28 -0700 (PDT) Message-ID: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_2022_1989215821.1495640128090" X-Trace: blaine.gmane.org 1495640128 23213 195.159.176.226 (24 May 2017 15:35:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 24 May 2017 15:35:28 +0000 (UTC) To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDY77TM4UQARBQGQS3EQKGQERDXMZTA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed May 24 17:35:23 2017 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-qt0-f192.google.com ([209.85.216.192]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dDYJn-0005wi-NM for gtp-pandoc-discuss@m.gmane.org; Wed, 24 May 2017 17:35:23 +0200 Original-Received: by mail-qt0-f192.google.com with SMTP id g55sf19753386qtc.0 for ; Wed, 24 May 2017 08:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=aeSRYqdDoJKND4+rfFHw471QRBjR7A1P2KInl3G+G2s=; b=hq9A8TmyC7WDV+kf4tp1RtibjwmiCwiHTu8l/CzD4rqLgDSFywO6oMeUNhSakbg3Fm X92/lZSSlllAkxZWFPUkX+llQOZHu5mFh+k25fjY7ifbsvrRbFoKVSeL76VYYXUzHhZL 4NDVRbYp8xjHV0E3p9ZHb1q7mk5Ab+Z4nPzU0Buqq1gyo58zjvP0zeHf6vQhNIALQjHT on/ojwSh1i/LkVxbvX+q33fIuhOcmQwSW5/0g8TWrBxkik1gYugc4v9/Ftrp8glVU7r7 /MxXH8Wdy95L4/p45grB/at9XqIpMP2fjEqYYpyfUFmBuSI2TNkDbZQa4z2BE3PBj+rc K6UQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:message-id:subject:mime-version:x-original-sender :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=aeSRYqdDoJKND4+rfFHw471QRBjR7A1P2KInl3G+G2s=; b=rgdelWx8m3bNm5LL6n4aVyiQXufG3TN9Ji/svS6FEc1VXVAmGhn/JbbuPGryUHMBsp gHungL1IdxX4ZqQZ0KdYsvn/5wUcjh/Nzpfi1PmnClUcMZfzWku3o9inPOWcVUiPsrPj 8Egg6ig34VzbvrUfghryKe+uxXPVKsbOhuztEXno6IrHG3suIX5uKH7ynmfU1UgB7/8o S2dS8Z+Cr5l2J52aj8wkjEGZpuZcI+odLWUDLcJ534frbeaBTLa3NK9c9fWJ38Ih3m7n BQP73cBaBH7TSf1FW2J2PoLCfjoa/N+ZgIqqZ6uVXNhKFGTKVJ1Unzxp0AcrYddI2bhW o+dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:date:from:to:message-id:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=aeSRYqdDoJKND4+rfFHw471QRBjR7A1P2KInl3G+G2s=; b=WHbUXW2s8RTBZCJa/+mVe9t984yyEJfA8whW6yW1fLlmW+yQfduO2k/REBNBc9em87 Ht3jUfR2Mlrfu2aihaHoE7sgVCsLSoUir37iFMKlhawCdVbJLLXAgDRL1UMmnxDgo0pg KJmIY1GgMB6rzcOedb7l9GLXx3Il5by2K9SzQ1HONn1rcgBOUgUH5C0aLVq83EVLKto5 Oanp5R2j4qwdQvP9HnCkwrXdWa8k8loR6V1IV2pLLEjZMx33Q2jFl0OYYDHgsFGAHQn5 CU4eQkFsa8wXRZgIUhwwKpOs4V9GL0C7mFwNmtWtXsGozHREs4KkmKrA9vjbr5VkVWAl /JqA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AODbwcAPUuecqWR0EYplSMKBZYDGMSB5BH/bJ5U6qyHz5geErBTZWSQa BrbSnkiHNaJGZg== X-Received: by 10.157.39.138 with SMTP id c10mr240772otb.9.1495640129140; Wed, 24 May 2017 08:35:29 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 10.157.80.146 with SMTP id b18ls9323594oth.4.gmail; Wed, 24 May 2017 08:35:28 -0700 (PDT) X-Received: by 10.157.45.79 with SMTP id v73mr239209ota.20.1495640128557; Wed, 24 May 2017 08:35:28 -0700 (PDT) X-Original-Sender: baconp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:17685 Archived-At: ------=_Part_2022_1989215821.1495640128090 Content-Type: multipart/alternative; boundary="----=_Part_2023_441365407.1495640128091" ------=_Part_2023_441365407.1495640128091 Content-Type: text/plain; charset="UTF-8" I am new to Haskell and I am trying to write a new reader for Pandoc. There is something strange about manyTill and I'm a bit stuck. I have written a minimal code to present the problem. Suppose I want to write a parser that succeeds if the string ends in three equal signs "===", and return the string preceeding the "===". I have written three versions. One with Parsec, and two with Pandoc: import Text.Parsec.String (Parser) import Text.Parsec (parse, ParseError) import Text.Parsec.Combinator (many1, manyTill) import Text.Parsec.Char (anyChar, string, noneOf) import qualified Text.Pandoc.Builder as B (str) import Text.Pandoc.Builder (Inlines) import Text.Parsec.Prim (try) simpleParse :: Parser a -> String -> Either ParseError a simpleParse p = parse p "" header' :: Parser String header' = manyTill anyChar (string "===") header'' :: Parser [Inlines] header'' = manyTill (B.str <$> (many1 anyChar)) (string "===") header''' :: Parser [Inlines] header''' = manyTill (B.str <$> (many1 (noneOf "="))) (string "===") I thought header' and header'' are the same parser except the type is a bit different. But I'm wrong: *Main> simpleParse header' "a===" Right "a" *Main> simpleParse header'' "a===" Left (line 1, column 5): unexpected end of input expecting "===" *Main> simpleParse header''' "a===" Right [Many {unMany = fromList [Str "a"]}] header''' works, but it seems to me a hacky solution, and I also don't understand *why do I have to exclude '=' in the Pandoc implementation?* Another problem with header''' is that I can't parse say "=a===" with it. Of course one may try to use 'try', as follows: headerWithTry' :: Parser String headerWithTry' = manyTill anyChar (try (string "===")) headerWithTry'' :: Parser [Inlines] headerWithTry'' = manyTill (B.str <$> (many1 anyChar)) (try (string "===")) headerWithTry''' :: Parser [Inlines] headerWithTry''' = manyTill (B.str <$> (many1 (noneOf "="))) (try (string "===")) But it does not work: *Main> simpleParse headerWithTry' "=a===" Right "=a" *Main> simpleParse headerWithTry'' "=a===" Left (line 1, column 6): unexpected end of input expecting "===" *Main> simpleParse headerWithTry''' "=a===" Left (line 1, column 1): unexpected "a" expecting "===" *Why?* Thanks, Jeff -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d879451a-e34c-495b-b72d-414e752d1e51%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. ------=_Part_2023_441365407.1495640128091 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I am new to Haskell and I am trying to write a new reader = for Pandoc.

There is something strange about manyTill and I'm a = bit stuck.

I have written a minimal code to present the problem. Sup= pose I want to write a parser that succeeds if the string ends in three equ= al signs "=3D=3D=3D", and return the string preceeding the "= =3D=3D=3D". I have written three versions. One with Parsec, and two wi= th Pandoc:

import Text.Parsec.String (Parser)
import Text.Parsec = (parse, ParseError)
import Text.Parsec.Combinator (many1, manyTill)
i= mport Text.Parsec.Char (anyChar, string, noneOf)
import qualified Text.P= andoc.Builder as B (str)
import Text.Pandoc.Builder (Inlines)
import = Text.Parsec.Prim (try)

simpleParse :: Parser a -> String -> Ei= ther ParseError a
simpleParse p =3D parse p ""

header&#= 39; :: Parser String
header' =3D manyTill anyChar (string "=3D= =3D=3D")

header'' :: Parser [Inlines]
header'= 9; =3D manyTill (B.str <$> (many1 anyChar)) (string "=3D=3D=3D&q= uot;)

header''' :: Parser [Inlines]
header''&= #39; =3D manyTill (B.str <$> (many1 (noneOf "=3D"))) (strin= g "=3D=3D=3D")

I thought header' and header'' = are the same parser except the type is a bit different. But I'm wrong:<= br>
*Main> simpleParse header' "a=3D=3D=3D"
Right &q= uot;a"
*Main> simpleParse header'' "a=3D=3D=3D"= ;
Left (line 1, column 5):
unexpected end of input
expecting "= ;=3D=3D=3D"
*Main> simpleParse header''' "a=3D= =3D=3D"
Right [Many {unMany =3D fromList [Str "a"]}]
<= br>header''' works, but it seems to me a hacky solution, and I = also don't understand why do I have to exclude '=3D' in the = Pandoc implementation?
Another problem with header''' is= that I can't parse say "=3Da=3D=3D=3D" with it.

Of co= urse one may try to use 'try', as follows:

headerWithTry'= ; :: Parser String
headerWithTry' =3D manyTill anyChar (try (string = "=3D=3D=3D"))

headerWithTry'' :: Parser [Inlines]<= br>headerWithTry'' =3D manyTill (B.str <$> (many1 anyChar)) (= try (string "=3D=3D=3D"))

headerWithTry''' :: = Parser [Inlines]
headerWithTry''' =3D manyTill (B.str <$&= gt; (many1 (noneOf "=3D"))) (try (string "=3D=3D=3D"))<= br>
But it does not work:
*Main> simpleParse headerWithTry' &q= uot;=3Da=3D=3D=3D"
Right "=3Da"
*Main> simpleParse = headerWithTry'' "=3Da=3D=3D=3D"
Left (line 1, column 6= ):
unexpected end of input
expecting "=3D=3D=3D"
*Main&g= t; simpleParse headerWithTry''' "=3Da=3D=3D=3D"
Le= ft (line 1, column 1):
unexpected "a"
expecting "=3D= =3D=3D"

Why?

Thanks,
Jeff

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/= msgid/pandoc-discuss/d879451a-e34c-495b-b72d-414e752d1e51%40googlegroups.co= m.
For more options, visit http= s://groups.google.com/d/optout.
------=_Part_2023_441365407.1495640128091-- ------=_Part_2022_1989215821.1495640128090--