From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Xah Lee
Newsgroups: gmane.emacs.help
Subject: how to use parsing expressing grammar
Date: Wed, 17 Dec 2008 03:53:07 -0800 (PST)
Organization: http://groups.google.com
Message-ID: <72bde6b1-ee08-4053-8d42-2a16ccd59900@v5g2000prm.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1229521964 15649 80.91.229.12 (17 Dec 2008 13:52:44 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 17 Dec 2008 13:52:44 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 17 14:53:49 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LCwqO-00009j-Dm
for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Dec 2008 14:53:44 +0100
Original-Received: from localhost ([127.0.0.1]:57523 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LCwpC-0004RG-J1
for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Dec 2008 08:52:30 -0500
Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!v5g2000prm.googlegroups.com!not-for-mail
Original-Newsgroups: gnu.emacs.help
Original-Lines: 41
Original-NNTP-Posting-Host: 76.102.50.240
Original-X-Trace: posting.google.com 1229514787 30911 127.0.0.1 (17 Dec 2008 11:53:07
GMT)
Original-X-Complaints-To: groups-abuse@google.com
Original-NNTP-Posting-Date: Wed, 17 Dec 2008 11:53:07 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: v5g2000prm.googlegroups.com; posting-host=76.102.50.240;
posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,
gzip(gfe), gzip(gfe)
Original-Xref: news.stanford.edu gnu.emacs.help:165394
X-Mailman-Approved-At: Wed, 17 Dec 2008 08:51:27 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60727
Archived-At:
There are 2 parsing expression grammars in elisp.
* http://www.emacswiki.org/cgi-bin/wiki/ParserCompiler, (2008) by
Mike Mattie.
* http://www.emacswiki.org/emacs/ParsingExpressionGrammars (2008)
by Helmut Eller.
The second one seems simpler, and i'm trying to learn it as a regex
replacement, but don't know how to use it.
Could anyone give concrete example in the following scenario?
For example, on my website i have things like:
Related essays:
Suppose i want to change them to:
See also:
SomeTitleString1 someSring1
SomeTitleString2 someSring2
...
How do i do it?
Thanks.
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Kevin Rodgers
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Wed, 17 Dec 2008 20:43:28 -0700
Message-ID:
References: <72bde6b1-ee08-4053-8d42-2a16ccd59900@v5g2000prm.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: ger.gmane.org 1229571857 13906 80.91.229.12 (18 Dec 2008 03:44:17 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 18 Dec 2008 03:44:17 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 18 04:45:22 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LD9pA-0007od-NH
for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Dec 2008 04:45:20 +0100
Original-Received: from localhost ([127.0.0.1]:40354 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LD9ny-0006ok-GQ
for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Dec 2008 22:44:06 -0500
Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
id 1LD9ne-0006mh-5C
for help-gnu-emacs@gnu.org; Wed, 17 Dec 2008 22:43:46 -0500
Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
id 1LD9nc-0006mD-Ro
for help-gnu-emacs@gnu.org; Wed, 17 Dec 2008 22:43:45 -0500
Original-Received: from [199.232.76.173] (port=53422 helo=monty-python.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43) id 1LD9nc-0006m9-KR
for help-gnu-emacs@gnu.org; Wed, 17 Dec 2008 22:43:44 -0500
Original-Received: from main.gmane.org ([80.91.229.2]:56450 helo=ciao.gmane.org)
by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32)
(Exim 4.60) (envelope-from )
id 1LD9nc-0004C0-5f
for help-gnu-emacs@gnu.org; Wed, 17 Dec 2008 22:43:44 -0500
Original-Received: from list by ciao.gmane.org with local (Exim 4.43)
id 1LD9nW-00063M-Jw
for help-gnu-emacs@gnu.org; Thu, 18 Dec 2008 03:43:38 +0000
Original-Received: from c-67-161-145-183.hsd1.co.comcast.net ([67.161.145.183])
by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
id 1AlnuQ-0007hv-00
for ; Thu, 18 Dec 2008 03:43:38 +0000
Original-Received: from kevin.d.rodgers by c-67-161-145-183.hsd1.co.comcast.net with
local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00
for ; Thu, 18 Dec 2008 03:43:38 +0000
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 48
Original-X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: c-67-161-145-183.hsd1.co.comcast.net
User-Agent: Thunderbird 2.0.0.18 (Macintosh/20081105)
In-Reply-To: <72bde6b1-ee08-4053-8d42-2a16ccd59900@v5g2000prm.googlegroups.com>
X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6,
seldom 2.4 (older, 4)
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60767
Archived-At:
Xah Lee wrote:
> There are 2 parsing expression grammars in elisp.
>
> * http://www.emacswiki.org/cgi-bin/wiki/ParserCompiler, (2008) by
> Mike Mattie.
> * http://www.emacswiki.org/emacs/ParsingExpressionGrammars (2008)
> by Helmut Eller.
>
> The second one seems simpler, and i'm trying to learn it as a regex
> replacement, but don't know how to use it.
>
> Could anyone give concrete example in the following scenario?
>
> For example, on my website i have things like:
>
>
> Related essays:
>
>
> Suppose i want to change them to:
>
>
> See also:
>
> SomeTitleString1 someSring1
> SomeTitleString2 someSring2
> ...
>
>
> How do i do it?
Choose the right tool for the job:
sed -e 's|^Related essays:
$|See also:
|' -e
'/^$/,/^<\/ul>/{s|^<\(/*\)ul>$|<\1p>|;s|^- ||;s|
$|
|;}'
And since this is help-gnu-emacs@gnu.org:
C-x h
C-u M-| sed -e ...
--
Kevin Rodgers
Denver, Colorado, USA
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Xah Lee
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Thu, 18 Dec 2008 01:24:10 -0800 (PST)
Organization: http://groups.google.com
Message-ID: <1b3af3cc-ba20-40b3-aa50-9fc7cecc764a@a12g2000pro.googlegroups.com>
References: <72bde6b1-ee08-4053-8d42-2a16ccd59900@v5g2000prm.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1229636972 22354 80.91.229.12 (18 Dec 2008 21:49:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 18 Dec 2008 21:49:32 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 18 22:50:36 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LDQlJ-0005XI-IF
for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Dec 2008 22:50:29 +0100
Original-Received: from localhost ([127.0.0.1]:38909 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LDQk7-00072Z-FJ
for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Dec 2008 16:49:15 -0500
Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2!postnews.google.com!a12g2000pro.googlegroups.com!not-for-mail
Original-Newsgroups: gnu.emacs.help
Original-Lines: 83
Original-NNTP-Posting-Host: 76.102.50.240
Original-X-Trace: posting.google.com 1229592251 30641 127.0.0.1 (18 Dec 2008 09:24:11
GMT)
Original-X-Complaints-To: groups-abuse@google.com
Original-NNTP-Posting-Date: Thu, 18 Dec 2008 09:24:11 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: a12g2000pro.googlegroups.com; posting-host=76.102.50.240;
posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,
gzip(gfe), gzip(gfe)
Original-Xref: news.stanford.edu gnu.emacs.help:165451
X-Mailman-Approved-At: Thu, 18 Dec 2008 16:48:50 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60816
Archived-At:
On Dec 17, 7:43 pm, Kevin Rodgers wrote:
> Xah Lee wrote:
> > There are 2 parsing expression grammars in elisp.
>
> > *http://www.emacswiki.org/cgi-bin/wiki/ParserCompiler, (2008) by
> > Mike Mattie.
> > *http://www.emacswiki.org/emacs/ParsingExpressionGrammars(2008)
> > by Helmut Eller.
>
> > The second one seems simpler, and i'm trying to learn it as a regex
> > replacement, but don't know how to use it.
>
> > Could anyone give concrete example in the following scenario?
>
> > For example, on my website i have things like:
>
> >
> > Related essays:
> >
>
> > Suppose i want to change them to:
>
> >
> > See also:
> >
> > SomeTitleString1 someSring1
> > SomeTitleString2 someSring2
> > ...
> >
>
> > How do i do it?
>
> Choose the right tool for the job:
>
> sed -e 's|^Related essays:
$|See also:
|' -e
> '/^$/,/^<\/ul>/{s|^<\(/*\)ul>$|<\1p>|;s|^- ||;s|
$|
|;}'
>
> And since this is help-gnu-em...@gnu.org:
>
> C-x h
> C-u M-| sed -e ...
I'm mainly interested in learning about parsing expression grammar,
because its power is a order of magnitude higher than regex. In
practice, this just means it's the next generation of regex.
the sed code won't work in general... because as soon as you have some
other chars or slight variation, it stops working. You'll need to code
up a lot variations than conditional expressions. All the ~4000 html
pages on my website are valid html4. Even at the level of strictness
of valid xml, regex simply can't work.
if i wanted to, could've used Perl, which i'm a master, which is far
more powerful than sed. Even though emacs regex is less powerful than
perl, but in my opinion, the fact that you can move cursor about
freely due to elisp's buffer datatype, its power as a text processing
lang beats Perl despite Perl's more powerful regex. But still, they
all inferior to parsing expression grammar.
i think parsing expression grammar is so important that it should be
core of emacs soon, perhaps coded in C.
PS for those interested in PEG, Helmut Eller has given answer in
comp.emacs, here:
http://groups.google.com/group/comp.emacs/browse_frm/thread/acb19cb47f2e632=
f
See also:
=E2=80=A2 Text Processing: Elisp vs Perl
http://xahlee.org/emacs/elisp_text_processing_lang.html
=E2=80=A2 Pattern Matching vs Lexical Grammar Specification
http://xahlee.org/cmaci/notation/pattern_matching_vs_pattern_spec.html
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Xah Lee
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Sat, 20 Dec 2008 00:42:18 -0800 (PST)
Organization: http://groups.google.com
Message-ID: <098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1229770676 21111 80.91.229.12 (20 Dec 2008 10:57:56 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 20 Dec 2008 10:57:56 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 20 11:59:03 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LDzXx-0006Su-9O
for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Dec 2008 11:59:01 +0100
Original-Received: from localhost ([127.0.0.1]:50150 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LDzWk-0002b9-UQ
for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Dec 2008 05:57:47 -0500
Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!t39g2000prh.googlegroups.com!not-for-mail
Original-Newsgroups: gnu.emacs.help,comp.emacs
Original-Lines: 118
Original-NNTP-Posting-Host: 76.102.50.240
Original-X-Trace: posting.google.com 1229762539 1651 127.0.0.1 (20 Dec 2008 08:42:19
GMT)
Original-X-Complaints-To: groups-abuse@google.com
Original-NNTP-Posting-Date: Sat, 20 Dec 2008 08:42:19 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: t39g2000prh.googlegroups.com; posting-host=76.102.50.240;
posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,
gzip(gfe), gzip(gfe)
Original-Xref: news.stanford.edu gnu.emacs.help:165537 comp.emacs:97503
X-Mailman-Approved-At: Sat, 20 Dec 2008 05:56:14 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60868
Archived-At:
more questions on parsing expression grammar.
let's say i want to change tags of the form
=E2=80=9C
=E2=80=9D
into
=E2=80=9C
=E2=80=9D
I tried the following:
(defun doMyReplace ()
(interactive)
(peg-parse
(start imgTag)
(imgTag "
")
(whitespace [" "])
(filePath [a-z "."])
)
)
then placed my cursor at the beginning of the tag, then call
doMyReplace. It doesn't seems to work, except moving cursor to after
the =E2=80=9Ca=E2=80=9D.
I spent about 20 min but couldn't see what's wrong with my code?
----------------
in general, i wanted to use PEG to do transformation from html 4
transitional to html 4 strict. I have maybe 3 hundred files to do
this. One of the primary change from html 4 trans to html 4 strict is
that any image tag now needs to be wrapped with =E2=80=9Cdiv=E2=80=9D.
So basically,
needs to become
The first job i tried to do to as a simplification, is to try to write
a img tag matcher to test with. here's my code:
(defun doMyReplace ()
(interactive)
(peg-parse
(imgTag "
")
(whitespace ["\n "])
(digits [0-9])
(filePath [A-Z a-z "./_"])
(altStr [A-Z a-z "./ '"])
)
)
but then couldn't get it to work.
Any help appreciated.
Btw, would you be interested in starting a mailing list on PEG in
emacs? e.g. yasnippet has one thru google, nxml has one in yahoo
group, ljupdate has one in livejournal. I think it'd be helpful.
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
On Dec 19, 3:27=C2=A0pm, Xah Lee wrote:
> On Dec 17, 10:22=C2=A0am, Helmut Eller wrote:
>
>
>
> > * Helmut Eller [2008-12-17 16:21+0100] writes:
>
> > > Recording positions in this manner is obviously tedious and it just
> > > shows that the package hasn't received much battle testing. =C2=A0As =
a little
> > > improvement we could define a custom "region" operator which acts
> > > similarly as the *list operator, but instead of collecting a list we
> > > push the start and end positions. =C2=A0E.g.:
>
> > I released a new version of peg.el and added a replace operator.
> > We can now match and replace without helper function:
>
> > (defun parse3 ()
> > =C2=A0 (peg-parse
> > =C2=A0 =C2=A0(start _ "
" _ title _ ul)
> > =C2=A0 =C2=A0(title "" (replace (* (not "
") (any)) "See also:") =
"
")
> > =C2=A0 =C2=A0(ul (replace ""=
""))
> > =C2=A0 =C2=A0(li (replace "" "") (* (not "") (any)) (replace "=
" "
"))
> > =C2=A0 =C2=A0(_ (* (or whitespace comment)))
> > =C2=A0 =C2=A0(whitespace ["\n\t "])
> > =C2=A0 =C2=A0(comment "<-- " (* (not "-->") (any)) "-->")))
>
> > Helmut.
>
> Holy cow. This worked! LOL!
>
> Thanks!
>
> =C2=A0 Xah
> =E2=88=91http://xahlee.org/
>
> =E2=98=84
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Helmut Eller
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Sat, 20 Dec 2008 10:34:45 +0100
Message-ID:
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=gb2312
Content-Transfer-Encoding: 8bit
X-Trace: ger.gmane.org 1229770730 21238 80.91.229.12 (20 Dec 2008 10:58:50 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 20 Dec 2008 10:58:50 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Dec 20 11:59:57 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LDzYp-0006di-B3
for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Dec 2008 11:59:56 +0100
Original-Received: from localhost ([127.0.0.1]:50641 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LDzXc-0002wm-52
for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Dec 2008 05:58:40 -0500
Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.kpnqwest.it!news.kpnqwest.it.POSTED!not-for-mail
Original-NNTP-Posting-Date: Sat, 20 Dec 2008 03:35:18 -0600
Original-Newsgroups: gnu.emacs.help,comp.emacs
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)
Cancel-Lock: sha1:FWbeZCXJ1tWKOOJZK+0ToAoVux8=
Original-Lines: 59
X-Usenet-Provider: http://www.giganews.com
Original-NNTP-Posting-Host: 195.254.226.103
Original-X-Trace: sv3-V9L+1YrikvZoRcRbLsKEhXUCcKzN5L68VT1YOCLdj313SFhegckq7BqUO1Zkpo4LdNn6WfXkvfEgodm!K2fHOHx9UBSxhQ3+Ex+l7+FKsixu9RdbcX2u2hRsA97yHgYewE02ZTFv+ie5eS40
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint
properly
X-Postfilter: 1.3.39
Original-Xref: news.stanford.edu gnu.emacs.help:165538 comp.emacs:97504
X-Mailman-Approved-At: Sat, 20 Dec 2008 05:55:22 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60869
Archived-At:
* Xah Lee [2008-12-20 09:42+0100] writes:
> I tried the following:
>
> (defun doMyReplace ()
> (interactive)
> (peg-parse
> (start imgTag)
> (imgTag "
">")
> (whitespace [" "])
> (filePath [a-z "."])
> )
> )
>
> then placed my cursor at the beginning of the tag, then call
> doMyReplace. It doesn't seems to work, except moving cursor to after
> the ˇ°aˇ±.
The filePath rule only matches the first character. You probably
want to write (+ [a-z "."]). Same issue for whitespace.
> The first job i tried to do to as a simplification, is to try to write
> a img tag matcher to test with. here's my code:
>
> (defun doMyReplace ()
> (interactive)
> (peg-parse
> (imgTag "
"src=" "\"" filePath "\"" whitespace
> "alt=" "\"" (replace altStr "ˇď") "\"" whitespace
> "height=" "\"" digits "\"" whitespace
> "width=" "\"" digits "\""
> ">")
> (whitespace ["\n "])
> (digits [0-9])
> (filePath [A-Z a-z "./_"])
> (altStr [A-Z a-z "./ '"])
> )
> )
Same problem here.
If the basics work you can try to generalize this a bit. E.g.
(imgTag "
")
(attribute (or src height width alt))
(src "src" whitespace "=" whitespace "\"" filePath \"\"")
etc.
> Btw, would you be interested in starting a mailing list on PEG in
> emacs? e.g. yasnippet has one thru google, nxml has one in yahoo
> group, ljupdate has one in livejournal. I think it'd be helpful.
So far only 2 people asked questions. If there are some more we can set
up a mailing list.
Helmut.
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Xah Lee
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Sat, 20 Dec 2008 13:41:59 -0800 (PST)
Organization: http://groups.google.com
Message-ID: <91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1229827572 5056 80.91.229.12 (21 Dec 2008 02:46:12 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 21 Dec 2008 02:46:12 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 21 03:47:16 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LEELb-0004pf-CX
for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Dec 2008 03:47:15 +0100
Original-Received: from localhost ([127.0.0.1]:44880 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LEEKP-0007Wm-1s
for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Dec 2008 21:46:01 -0500
Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!w24g2000prd.googlegroups.com!not-for-mail
Original-Newsgroups: gnu.emacs.help,comp.emacs
Original-Lines: 98
Original-NNTP-Posting-Host: 76.102.50.240
Original-X-Trace: posting.google.com 1229809319 12917 127.0.0.1 (20 Dec 2008 21:41:59
GMT)
Original-X-Complaints-To: groups-abuse@google.com
Original-NNTP-Posting-Date: Sat, 20 Dec 2008 21:41:59 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: w24g2000prd.googlegroups.com; posting-host=76.102.50.240;
posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,
gzip(gfe), gzip(gfe)
Original-Xref: news.stanford.edu gnu.emacs.help:165549 comp.emacs:97505
X-Mailman-Approved-At: Sat, 20 Dec 2008 21:45:26 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60883
Archived-At:
Xah Lee wrote:
> let's say i want to change tags of the form
> =E2=80=9C
=E2=80=9D
> into
> =E2=80=9C
=E2=80=9D
> I tried the following:
> (defun doMyReplace ()
> (interactive)
> (peg-parse
> (start imgTag)
> (imgTag "
")
> (whitespace [" "])
> (filePath [a-z "."])
> )
> )
Helmut Eller wrote:
> The filePath rule only matches the first character. You probably
> want to write (+ [a-z "."]). Same issue for whitespace.
Thanks a lot! It worked out great!
I have another question, hopefully this one is not a dumb one.
In summary, if i have
(imgTag "
")
how to tell PEG that if a attribute is the last item, then the
whitespace following it is optional?
For example, the above will match
but won't match
Here's my code:
(defun doMyReplace ()
(interactive)
(peg-parse
(imgTag "
")
(attributes (or src alt width height))
(src "src" _* "=3D" _* "\"" filePath "\"")
(filePath (+ [A-Z a-z "./_-"]))
(alt "alt" _* "=3D" _* "\"" altStr "\"")
(altStr (* [A-Z a-z "./ '_"]))
(width "width" _* "=3D" _* "\"" digits "\"")
(height "height" _* "=3D" _* "\"" digits "\"")
(_* (* ["\n \t"])) ; 0 or more white space
(_ (+ ["\n \t"])) ; 1 or more white space
(digits (+ [0-9]))
)
)
here's a sample text to be matched:
if i add a space to the ending =E2=80=9C>=E2=80=9D, it matches.
Thanks again.
> > Btw, would you be interested in starting a mailing list on PEG in
> > emacs? e.g. yasnippet has one thru google, nxml has one in yahoo
> > group, ljupdate has one in livejournal. I think it'd be helpful.
>
> So far only 2 people asked questions. If there are some more we can set
> up a mailing list.
I'm pretty sure if you create it, more and more people will join it.
I'm very interested in PEG and think it is of critical importance. If
say emacs 24 has it built in as C code, with all its regex functions
such as search-forward-regexp, query-replace-regexp etc having PEG
version, it would make emacs a killer app.
>From Wikipedia, it appears that people have already wrote PEG lib for
most major langs. There is already a C lib for PEG. The problem with
them is that most comes with a background of computer lang parsing, as
opposed to practical use for text processing like regex. (note: regex
itself came from computer science background as a way to determine
languages with =E2=80=9Cregular=E2=80=9D grammar, but today it is far remov=
ed from
theoretical parsing. The process of this transmutation took i think 10
years, and it took another 10 or so years until it become a widely
popular tool in langs, starting with Perl in the 1990s) I don't forsee
that in the next 10 years that practicing programers will all know
about computer science of parsing or that major langs will all have
formal grammar spec. I'm pretty certain people are already seeing the
potential of PEG as regex replacement and working towards creatings
such practical goal.
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Xah Lee
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Sat, 20 Dec 2008 14:27:39 -0800 (PST)
Organization: http://groups.google.com
Message-ID:
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1229827615 5145 80.91.229.12 (21 Dec 2008 02:46:55 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 21 Dec 2008 02:46:55 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 21 03:48:01 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LEEMK-0004z0-4x
for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Dec 2008 03:48:00 +0100
Original-Received: from localhost ([127.0.0.1]:45330 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LEEL7-0007qj-PM
for geh-help-gnu-emacs@m.gmane.org; Sat, 20 Dec 2008 21:46:45 -0500
Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2!postnews.google.com!g1g2000pra.googlegroups.com!not-for-mail
Original-Newsgroups: gnu.emacs.help,comp.emacs
Original-Lines: 45
Original-NNTP-Posting-Host: 76.102.50.240
Original-X-Trace: posting.google.com 1229812060 32287 127.0.0.1 (20 Dec 2008 22:27:40
GMT)
Original-X-Complaints-To: groups-abuse@google.com
Original-NNTP-Posting-Date: Sat, 20 Dec 2008 22:27:40 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: g1g2000pra.googlegroups.com; posting-host=76.102.50.240;
posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,
gzip(gfe), gzip(gfe)
Original-Xref: news.stanford.edu gnu.emacs.help:165550 comp.emacs:97506
X-Mailman-Approved-At: Sat, 20 Dec 2008 21:45:26 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60884
Archived-At:
Hi Helmut,
another question i have is, how do i capture text as in regex's =E2=80=9C\(=
...
\)=E2=80=9D, =E2=80=9C\1=E2=80=9D?
I know in your elisp header file it mentions
;; (action FORM) ; evaluate FORM
;; `(VAR... -- FORM...) ; stack action
how do i capture match using that?
e.g. to match
(defun doMyReplace ()
(interactive)
(peg-parse
(imgTag "
")
(attributes (or src alt width height))
(src "src" _* "=3D" _* "\"" filePath "\"")
(filePath (+ [A-Z a-z "./_-"]))
(alt "alt" _* "=3D" _* "\"" altStr "\"")
(altStr (* [A-Z a-z "./ '_"]))
(width "width" _* "=3D" _* "\"" digits "\"")
(height "height" _* "=3D" _* "\"" digits "\"")
(_* (* ["\n \t"])) ; 0 or more white space
(_ (+ ["\n \t"])) ; 1 or more white space
(digits (+ [0-9]))
)
)
suppose i want to swap the src and alt text and have
Thanks.
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Helmut Eller
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Sun, 21 Dec 2008 10:49:44 +0100
Message-ID:
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: ger.gmane.org 1229864936 12443 80.91.229.12 (21 Dec 2008 13:08:56 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 21 Dec 2008 13:08:56 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 21 14:10:03 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LEO4I-00074L-Pm
for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Dec 2008 14:10:03 +0100
Original-Received: from localhost ([127.0.0.1]:51680 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LEO36-0002Ym-8D
for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Dec 2008 08:08:48 -0500
Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.kpnqwest.it!news.kpnqwest.it.POSTED!not-for-mail
Original-NNTP-Posting-Date: Sun, 21 Dec 2008 03:49:50 -0600
Original-Newsgroups: gnu.emacs.help,comp.emacs
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)
Cancel-Lock: sha1:XPDlivZXbytZrcgisocND/pNpRg=
Original-Lines: 52
X-Usenet-Provider: http://www.giganews.com
Original-NNTP-Posting-Host: 195.254.226.11
Original-X-Trace: sv3-WXwrQoDU3m6/sIaV5mvAP+geTz37fc+CRpqt5A2EnqFl1V12zSE5grrDbL0wRsvYeqDUpE/HTPHjYVm!SkFGVi6Rbojh4EnSvjzK1SvT5vSJ2+lVhEJpGZY+ZpFdK8iUzgf8gB3tQU+RO/U=
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint
properly
X-Postfilter: 1.3.39
Original-Xref: news.stanford.edu gnu.emacs.help:165555 comp.emacs:97507
X-Mailman-Approved-At: Sun, 21 Dec 2008 08:08:27 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60886
Archived-At:
* Xah Lee [2008-12-20 22:41+0100] writes:
> I have another question, hopefully this one is not a dumb one.
>
> In summary, if i have
>
> (imgTag "
")
>
> how to tell PEG that if a attribute is the last item, then the
> whitespace following it is optional?
Hmm, good question. Perhaps something like
(imgTag "
")
This does a bit of backtracking, but easy to read.
>> So far only 2 people asked questions. If there are some more we can set
>> up a mailing list.
>
> I'm pretty sure if you create it, more and more people will join it.
> I'm very interested in PEG and think it is of critical importance.
I'll try to set up project at savannah.
> If say emacs 24 has it built in as C code, with all its regex
> functions such as search-forward-regexp, query-replace-regexp etc
> having PEG version, it would make emacs a killer app.
I don't think that PEGs are easy to use interactively, like
query-replace-regexp. Regexps have a more concise notation, which is
crucial when used interactively.
> From Wikipedia, it appears that people have already wrote PEG lib for
> most major langs. There is already a C lib for PEG. The problem with
> them is that most comes with a background of computer lang parsing, as
> opposed to practical use for text processing like regex. (note: regex
> itself came from computer science background as a way to determine
> languages with “regular” grammar, but today it is far
> removed from theoretical parsing. The process of this transmutation
> took i think 10 years, and it took another 10 or so years until it
> become a widely popular tool in langs, starting with Perl in the
> 1990s) I don't forsee that in the next 10 years that practicing
> programers will all know about computer science of parsing or that
> major langs will all have formal grammar spec. I'm pretty certain
> people are already seeing the potential of PEG as regex replacement
> and working towards creatings such practical goal.
I think that the Lua language uses PEGs for text processing and
apparently implements it's regexp library on top of PEGs.
Helmut.
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Helmut Eller
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Sun, 21 Dec 2008 12:24:41 +0100
Message-ID:
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit
X-Trace: ger.gmane.org 1229864980 12713 80.91.229.12 (21 Dec 2008 13:09:40 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 21 Dec 2008 13:09:40 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 21 14:10:47 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LEO50-0007Gd-HG
for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Dec 2008 14:10:47 +0100
Original-Received: from localhost ([127.0.0.1]:43301 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LEO3o-0002os-2G
for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Dec 2008 08:09:32 -0500
Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.kpnqwest.it!news.kpnqwest.it.POSTED!not-for-mail
Original-NNTP-Posting-Date: Sun, 21 Dec 2008 05:24:44 -0600
Original-Newsgroups: gnu.emacs.help,comp.emacs
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)
Cancel-Lock: sha1:YOqhsvN9hQvQ+nHSE91WF5/9BHw=
Original-Lines: 79
X-Usenet-Provider: http://www.giganews.com
Original-NNTP-Posting-Host: 195.254.226.77
Original-X-Trace: sv3-XKQtl22w1CCahyfrHghPZSPwmLioWXEZA1ACEpep1F7T7Gs5xo4zl6ervjFSmY0Z99Vj7nEcoXTAVDl!yez12lJFo+XJRXHjv59p7qSfau7kQ1nOg0yKVCQGtZQl2t0Dm0AJdu9wxNMYFZM=
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint
properly
X-Postfilter: 1.3.39
Original-Xref: news.stanford.edu gnu.emacs.help:165556 comp.emacs:97508
X-Mailman-Approved-At: Sun, 21 Dec 2008 08:08:35 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60887
Archived-At:
* Xah Lee [2008-12-20 23:27+0100] writes:
> Hi Helmut,
>
> another question i have is, how do i capture text as in regex's “\(...
> \)”, “\1”?
>
> I know in your elisp header file it mentions
>
> ;; (action FORM) ; evaluate FORM
> ;; `(VAR... -- FORM...) ; stack action
>
> how do i capture match using that?
Basically there are 2 phases. The first phase parses, i.e., decides
which rules match, and the second phase executes actions. Actions are
executed at the point of match. The action can do whatever is needed.
The peg stack can be use to pass values between actions. You don't have
to use the stack, you could also use global variables or whatever is
convenient.
[...]
> suppose i want to swap the src and alt text and have
>
>
That's a bit complicated, but I think it's also a bit complicated to swap
to submatches with regexps. Let's assume that we have a helper function
to swap two regions:
(defun swap-regions (start1 end1 start2 end2)
(if (< start2 start1)
(swap-regions start2 end2 start1 end1)
(let ((string1 (buffer-substring start1 end1))
(string2 (buffer-substring start2 end2)))
(delete-region start2 end2)
(goto-char start2)
(insert string1)
(delete-region start1 end1)
(goto-char start1)
(insert string2))))
Then this should work:
(defun doMyReplace ()
(interactive)
(let (src-start src-end alt-start alt-end)
(peg-parse
(imgTag "
")
(attributes (or src alt width height))
(src "src" =
(action (setq src-start (point)))
"\"" filePath "\""
(action (setq src-end (point))))
(filePath (+ [A-Z a-z "./_-"]))
(alt "alt" =
(action (setq alt-start (point)))
"\"" altStr "\""
(action (setq alt-end (point))))
(altStr (* [A-Z a-z "./ '_"]))
(width "width" = "\"" digits "\"")
(height "height" = "\"" digits "\"")
(= _* "=" _*)
(_* (* ["\n \t"])) ; 0 or more white space
(_ (+ ["\n \t"])) ; 1 or more white space
(digits (+ [0-9])))
(swap-regions alt-start alt-end src-start src-end)))
I guess a mechanism to give matched regions a name would be useful.
E.g. (capture E NAME) would match E and store the matched region with
NAME in a hashtable. Actions could than easily refer to that region by
looking in the hashtable. Auxiliary functions like (capture-string NAME)
or (capture-beginning NAME) to lookup the matched string resp. start
position in the hypothetical capture table could be implemented on top
of that. Also something like replace-capture would then be easy to add.
Helmut.
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: ashishnkadakia@gmail.com
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Tue, 23 Dec 2008 15:21:07 -0800 (PST)
Organization: http://groups.google.com
Message-ID:
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1230132134 11509 80.91.229.12 (24 Dec 2008 15:22:13 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 24 Dec 2008 15:22:13 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 24 16:23:21 2008
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LFVZx-0005wn-01
for geh-help-gnu-emacs@m.gmane.org; Wed, 24 Dec 2008 16:23:21 +0100
Original-Received: from localhost ([127.0.0.1]:35959 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LFVYk-0001bb-0l
for geh-help-gnu-emacs@m.gmane.org; Wed, 24 Dec 2008 10:22:06 -0500
Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!w1g2000prk.googlegroups.com!not-for-mail
Original-Newsgroups: gnu.emacs.help,comp.emacs
Original-Lines: 125
Original-NNTP-Posting-Host: 144.160.98.31
Original-X-Trace: posting.google.com 1230074467 7663 127.0.0.1 (23 Dec 2008 23:21:07
GMT)
Original-X-Complaints-To: groups-abuse@google.com
Original-NNTP-Posting-Date: Tue, 23 Dec 2008 23:21:07 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: w1g2000prk.googlegroups.com; posting-host=144.160.98.31;
posting-account=DraSGAoAAABvy9dWZE1DTs19hZvRNdDG
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5)
Gecko/2008120122 Firefox/3.0.5,gzip(gfe),gzip(gfe)
Original-Xref: news.stanford.edu gnu.emacs.help:165584 comp.emacs:97513
X-Mailman-Approved-At: Wed, 24 Dec 2008 10:21:20 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:60918
Archived-At:
Sorry for the pointer to different language here.
If it doesn't matter which language you want to use, use Perl.
It has decent parsing modules, that can do job wonderfully.
On Dec 20, 3:42=C2=A0am, Xah Lee wrote:
> more questions on parsing expression grammar.
>
> let's say i want to change tags of the form
>
> =E2=80=9C
=E2=80=9D
>
> into
>
> =E2=80=9C
=E2=80=9D
>
> I tried the following:
>
> (defun doMyReplace ()
> (interactive)
> =C2=A0 (peg-parse
> =C2=A0 =C2=A0(start imgTag)
> =C2=A0 (imgTag "
">")
> =C2=A0 (whitespace [" "])
> =C2=A0 (filePath [a-z "."])
> =C2=A0 =C2=A0)
> )
>
> then placed my cursor at the beginning of the tag, then call
> doMyReplace. It doesn't seems to work, except moving cursor to after
> the =E2=80=9Ca=E2=80=9D.
>
> I spent about 20 min but couldn't see what's wrong with my code?
>
> ----------------
>
> in general, i wanted to use PEG to do transformation from html 4
> transitional to html 4 strict. I have maybe 3 hundred files to do
> this. One of the primary change from html 4 trans to html 4 strict is
> that any image tag now needs to be wrapped with =E2=80=9Cdiv=E2=80=9D.
>
> So basically,
>
>
>
> needs to become
>
> ![]()
>
> The first job i tried to do to as a simplification, is to try to write
> a img tag matcher to test with. here's my code:
>
> (defun doMyReplace ()
> (interactive)
> =C2=A0 (peg-parse
> =C2=A0 (imgTag "
=C2=A0"src=3D" "\"" filePath "\"" whitespace
> =C2=A0"alt=3D" "\"" (replace altStr "=E2=98=85") "\"" whitespace
> =C2=A0"height=3D" "\"" digits "\"" whitespace
> =C2=A0"width=3D" "\"" digits "\""
> =C2=A0">")
> =C2=A0 (whitespace ["\n "])
> =C2=A0 (digits [0-9])
> =C2=A0 (filePath [A-Z a-z "./_"])
> =C2=A0 (altStr [A-Z a-z "./ '"])
> =C2=A0 =C2=A0)
> )
>
> but then couldn't get it to work.
>
> Any help appreciated.
>
> Btw, would you be interested in starting a mailing list on PEG in
> emacs? e.g. yasnippet has one thru google, nxml has one in yahoo
> group, ljupdate has one in livejournal. I think it'd be helpful.
>
> =C2=A0 Xah
> =E2=88=91http://xahlee.org/
>
> =E2=98=84
>
> On Dec 19, 3:27=C2=A0pm, Xah Lee wrote:
>
> > On Dec 17, 10:22=C2=A0am, Helmut Eller wrote:
>
> > > * Helmut Eller [2008-12-17 16:21+0100] writes:
>
> > > > Recording positions in this manner is obviously tedious and it just
> > > > shows that the package hasn't received much battle testing. =C2=A0A=
s a little
> > > > improvement we could define a custom "region" operator which acts
> > > > similarly as the *list operator, but instead of collecting a list w=
e
> > > > push the start and end positions. =C2=A0E.g.:
>
> > > I released a new version of peg.el and added a replace operator.
> > > We can now match and replace without helper function:
>
> > > (defun parse3 ()
> > > =C2=A0 (peg-parse
> > > =C2=A0 =C2=A0(start _ "
" _ title _ ul)
> > > =C2=A0 =C2=A0(title "" (replace (* (not "
") (any)) "See also:"=
) "")
> > > =C2=A0 =C2=A0(ul (replace "" ""))
> > > =C2=A0 =C2=A0(li (replace "" "") (* (not "") (any)) (replace=
"" "
"))
> > > =C2=A0 =C2=A0(_ (* (or whitespace comment)))
> > > =C2=A0 =C2=A0(whitespace ["\n\t "])
> > > =C2=A0 =C2=A0(comment "<-- " (* (not "-->") (any)) "-->")))
>
> > > Helmut.
>
> > Holy cow. This worked! LOL!
>
> > Thanks!
>
> > =C2=A0 Xah
> > =E2=88=91http://xahlee.org/
>
> > =E2=98=84
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Leo
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Tue, 03 Mar 2009 17:34:41 +0000
Organization: University of Cambridge
Message-ID:
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: ger.gmane.org 1236101913 30351 80.91.229.12 (3 Mar 2009 17:38:33 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 3 Mar 2009 17:38:33 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 03 18:39:50 2009
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LeYaL-0002J5-MM
for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Mar 2009 18:39:18 +0100
Original-Received: from localhost ([127.0.0.1]:37423 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LeYZ0-0007JC-HJ
for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Mar 2009 12:37:54 -0500
Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
id 1LeYW7-0004Mp-VD
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 12:34:55 -0500
Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
id 1LeYW6-0004LE-EU
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 12:34:55 -0500
Original-Received: from [199.232.76.173] (port=43921 helo=monty-python.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43) id 1LeYW6-0004Ki-1N
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 12:34:54 -0500
Original-Received: from main.gmane.org ([80.91.229.2]:38774 helo=ciao.gmane.org)
by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32)
(Exim 4.60) (envelope-from )
id 1LeYW5-0000kH-8C
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 12:34:53 -0500
Original-Received: from list by ciao.gmane.org with local (Exim 4.43)
id 1LeYW0-0004sx-Bm
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 17:34:48 +0000
Original-Received: from smaug.linux.pwf.cam.ac.uk ([193.60.95.72])
by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
id 1AlnuQ-0007hv-00
for ; Tue, 03 Mar 2009 17:34:48 +0000
Original-Received: from sdl.web by smaug.linux.pwf.cam.ac.uk with local (Gmexim 0.1
(Debian)) id 1AlnuQ-0007hv-00
for ; Tue, 03 Mar 2009 17:34:48 +0000
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 14
Original-X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: smaug.linux.pwf.cam.ac.uk
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)
Cancel-Lock: sha1:e6ER76FW5RQ7slVvRqt+l5tCP9M=
X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6,
seldom 2.4 (older, 4)
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:62559
Archived-At:
On 2008-12-21 09:49 +0000, Helmut Eller wrote:
>> I'm pretty sure if you create it, more and more people will join it.
>> I'm very interested in PEG and think it is of critical importance.
>
> I'll try to set up project at savannah.
I have seen the project on
http://savannah.nongnu.org/projects/emacs-peg. I wonder it might be a
good idea to make a newsgroup on gmane to link to the mailing list. It
will make more Emacs users subscribe to it.
Best wishes,
--
.: Leo :. [ sdl.web AT gmail.com ] .: I use Emacs :.
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Mike Mattie
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Tue, 3 Mar 2009 09:59:15 -0800
Message-ID: <20090303095915.332c4ee1@gmail.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Trace: ger.gmane.org 1236115725 18884 80.91.229.12 (3 Mar 2009 21:28:45 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 3 Mar 2009 21:28:45 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 03 22:30:02 2009
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LecBd-0004P7-0F
for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Mar 2009 22:30:01 +0100
Original-Received: from localhost ([127.0.0.1]:43470 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LecAH-0005Fq-Qe
for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Mar 2009 16:28:37 -0500
Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
id 1LeYtp-0007lG-EL
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 12:59:25 -0500
Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
id 1LeYtn-0007jO-Fc
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 12:59:24 -0500
Original-Received: from [199.232.76.173] (port=34631 helo=monty-python.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43) id 1LeYtn-0007jH-66
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 12:59:23 -0500
Original-Received: from wa-out-1112.google.com ([209.85.146.182]:5704)
by monty-python.gnu.org with esmtp (Exim 4.60)
(envelope-from ) id 1LeYtm-0004pf-GN
for help-gnu-emacs@gnu.org; Tue, 03 Mar 2009 12:59:22 -0500
Original-Received: by wa-out-1112.google.com with SMTP id k17so1441360waf.26
for ; Tue, 03 Mar 2009 09:59:20 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
h=domainkey-signature:received:received:date:from:to:subject
:message-id:in-reply-to:references:x-mailer:mime-version
:content-type:content-transfer-encoding;
bh=KtLXskYOS6LxknDupyhFqBcc353li9sHxnX96k6XqG0=;
b=P7e5WFz/1V+Nv6guPqh3+oSueIzikXHm9TSNWkuB7Vg5hm62heHpAvWafijmUvM1Ox
RIrPU+/jDA83snyIJALf4b0gRaMUuql3BXwkjMgB7p+Etkn7C2c6krzw8Uq5P90PQJlv
QgxagyI+jFvqRDM8Am0Y7KhOnnWqiC2dQkwLo=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
h=date:from:to:subject:message-id:in-reply-to:references:x-mailer
:mime-version:content-type:content-transfer-encoding;
b=KlueMwcWXCMscffjSp117p1C4eGMI68OQ99rgJXfV+qbpe1zrYQ0hIkn6XDVDxpMwh
q6FSqJbVBmqHm24o5brdjTaq3QXedoarz1lODfk6cAuYyhGl/84pqcR7Xm2cRTi2Zu/G
112SfIdjIiKBXHWM4AsD11oICHF3e1Sme+4Ag=
Original-Received: by 10.114.152.17 with SMTP id z17mr3515882wad.73.1236103160627;
Tue, 03 Mar 2009 09:59:20 -0800 (PST)
Original-Received: from localhost (c66-235-1-45.sea2.cablespeed.com [66.235.1.45])
by mx.google.com with ESMTPS id k21sm1193044waf.6.2009.03.03.09.59.20
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Tue, 03 Mar 2009 09:59:20 -0800 (PST)
In-Reply-To:
X-Mailer: Claws Mail 3.7.0 (GTK+ 2.12.11; i686-pc-linux-gnu)
X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Mailman-Approved-At: Tue, 03 Mar 2009 16:26:23 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:62562
Archived-At:
On Tue, 03 Mar 2009 17:34:41 +0000
Leo wrote:
> On 2008-12-21 09:49 +0000, Helmut Eller wrote:
> >> I'm pretty sure if you create it, more and more people will join
> >> it. I'm very interested in PEG and think it is of critical
> >> importance.
> >
> > I'll try to set up project at savannah.
>
> I have seen the project on
> http://savannah.nongnu.org/projects/emacs-peg. I wonder it might be a
> good idea to make a newsgroup on gmane to link to the mailing list. It
> will make more Emacs users subscribe to it.
>
> Best wishes,
I was working on a PEG/CFG parser compiler:
http://www.emacswiki.org/cgi-bin/wiki/ParserCompiler
I will be resuming the development soon. Please keep me in the loop on such efforts.
Cheers,
Mike Mattie
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Miles Bader
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Wed, 04 Mar 2009 09:35:00 +0900
Message-ID: <87d4cyqg5n.fsf@catnip.gol.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
<067151a4-b892-4e9a-8600-e2dcd92cb0ad@v18g2000pro.googlegroups.com>
<87fxhukvuu.fsf@gmail.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: ger.gmane.org 1236127255 21834 80.91.229.12 (4 Mar 2009 00:40:55 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 4 Mar 2009 00:40:55 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 04 01:42:10 2009
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LefBZ-0003G2-0N
for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Mar 2009 01:42:09 +0100
Original-Received: from localhost ([127.0.0.1]:36165 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LefAD-0004Ou-NM
for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Mar 2009 19:40:45 -0500
Original-Path: news.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
Original-Newsgroups: gnu.emacs.help,comp.emacs,comp.lang.lisp
Original-Lines: 46
Original-X-Trace: individual.net 3VzhhYylHJPeXcWQfAhusAtmiTUFiyAvZ4CoWwbuZgTICLFlaG
Cancel-Lock: sha1:V7JPDz0b4bbk1xrYfH8/OWMP/6Q=
sha1:nXqu4YfYiTNkz4xwEsqkyAYS9JY=
System-Type: x86_64-unknown-linux-gnu
Original-Xref: news.stanford.edu gnu.emacs.help:167271 comp.emacs:97917
comp.lang.lisp:262169
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:62565
Archived-At:
W Dan Meyer writes:
> Are we talking about memoising PEG (e.g Packrat) in elisp? ...
> Packrat parser is the best option out there currently because it
> recognises much complex grammar then LALR(1), and it has no
> ambiguities with expressing these grammars.
You also might be interested in Roberto Ierusalimschy's paper on the
implemenation of LPEG, which is a PEG implementation for Lua:
http://www.inf.puc-rio.br/~roberto/docs/peg.pdf
Note that LPEG does _not_ use the packrat algorithm, as apparently it
presents some serious practical problems for common uses of parsing
tools:
In 2002, Ford proposed Packrat [5], an adaptation of the original
algorithm that uses lazy evaluation to avoid that inefficiency.
Even with this improvement, however, the space complexity of the
algorithm is still linear on the subject size (with a somewhat big
constant), even in the best case. As its author himself recognizes,
this makes the algorithm not befitting for parsing “large amounts of
relatively flat” data ([5], p. 57). However, unlike parsing tools,
regular-expression tools aim exactly at large amounts of relatively
flat data.
To avoid these difficulties, we did not use the Packrat algorithm
for LPEG. To implement LPEG we created a virtual parsing machine, not
unlike Knuth’s parsing machine [15], where each pattern is
represented as a program for the machine. The program is somewhat
similar to a recursive-descendent parser (with limited backtracking)
for the pattern, but it uses an explicit stack instead of recursion.
The general LPEG page is here:
http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html
-Miles
--
Justice, n. A commodity which in a more or less adulterated condition the
State sells to the citizen as a reward for his allegiance, taxes and personal
service.
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: W Dan Meyer
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Tue, 03 Mar 2009 23:52:25 +0000
Organization: Aioe.org NNTP Server
Message-ID: <87fxhukvuu.fsf@gmail.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
<067151a4-b892-4e9a-8600-e2dcd92cb0ad@v18g2000pro.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: ger.gmane.org 1236147932 32264 80.91.229.12 (4 Mar 2009 06:25:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 4 Mar 2009 06:25:32 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 04 07:26:47 2009
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LekYx-0005jB-MW
for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Mar 2009 07:26:40 +0100
Original-Received: from localhost ([127.0.0.1]:36490 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LekXc-0005vX-4N
for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Mar 2009 01:25:16 -0500
Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!aioe.org!not-for-mail
Original-Newsgroups: gnu.emacs.help,comp.emacs,comp.lang.lisp
Original-Lines: 38
Original-NNTP-Posting-Host: SzaqlAEO6bbHF9XXoMT3gw.user.aioe.org
Original-X-Complaints-To: abuse@aioe.org
Original-NNTP-Posting-Date: Tue, 3 Mar 2009 23:52:59 +0000 (UTC)
X-Notice: Filtered by postfilter v. 0.7.7
Cancel-Lock: sha1:nllXLFziTD1vR/6KeaWeZZRxmiA=
sha1:yoVZVxROJrMEOHYruSn9Z1NvcY8=
User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux)
Original-Xref: news.stanford.edu gnu.emacs.help:167270 comp.emacs:97916
comp.lang.lisp:262168
X-Mailman-Approved-At: Wed, 04 Mar 2009 01:20:43 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:62570
Archived-At:
Xah Lee writes:
> On Mar 3, 9:59 am, Mike Mattie wrote:
>> On Tue, 03 Mar 2009 17:34:41 +0000
>>
>> Leo wrote:
>> > On 2008-12-21 09:49 +0000, Helmut Eller wrote:
>> > >> I'm pretty sure if you create it, more and more people will join
>> > >> it. I'm very interested in PEG and think it is of critical
>> > >> importance.
>>
>> > > I'll try to set up project at savannah.
>>
>> > I have seen the project on
>> >http://savannah.nongnu.org/projects/emacs-peg. I wonder it might be a
>> > good idea to make a newsgroup on gmane to link to the mailing list. It
>> > will make more Emacs users subscribe to it.
>>
>> > Best wishes,
>>
>> I was working on a PEG/CFG parser compiler:http://www.emacswiki.org/cgi-bin/wiki/ParserCompiler
>>
>> I will be resuming the development soon. Please keep me in the loop on such efforts.
Are we talking about memoising PEG (e.g Packrat) in elisp? There might
be more people interested. I do realise that Emacs doesn't have decent
parsing facility and it makes it's regular expression based engine in
more complex areas useless (mentioned nested tags). Since it's automata
based you cannot go beyond simple patterns. That means also that
everybody is reinventing a wheel with implanting all those recursive
decent parsers when it comes to analyse, pretty print, syntax highlight
of such modes like Haskell one. Packrat parser is the best option out
there currently because it recognises much complex grammar then LALR(1),
and it has no ambiguities with expressing these grammars. Works well
also as a standalone combinator based solution rather then a parser
generator, plus it is lex-less e.g allow to recognise several different
languages in _one_go_ and one context without marking them explicitly!
cheers Dan W
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Mike Mattie
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Wed, 4 Mar 2009 22:18:51 -0800
Message-ID: <20090304221851.4569a0e3@gmail.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
<067151a4-b892-4e9a-8600-e2dcd92cb0ad@v18g2000pro.googlegroups.com>
<87fxhukvuu.fsf@gmail.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: multipart/signed; boundary="Sig_/BzsYHvKPe=ZB+ITBJ8lgUKg";
protocol="application/pgp-signature"; micalg=PGP-SHA1
X-Trace: ger.gmane.org 1236245517 15696 80.91.229.12 (5 Mar 2009 09:31:57 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 5 Mar 2009 09:31:57 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 05 10:33:12 2009
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1Lf9x1-00042T-Jj
for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Mar 2009 10:33:12 +0100
Original-Received: from localhost ([127.0.0.1]:35563 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1Lf9vg-00029Z-88
for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Mar 2009 04:31:48 -0500
Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
id 1Lf6vF-00012u-Rq
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 01:19:09 -0500
Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
id 1Lf6vD-000125-Kf
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 01:19:09 -0500
Original-Received: from [199.232.76.173] (port=59410 helo=monty-python.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43) id 1Lf6vD-000122-Cd
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 01:19:07 -0500
Original-Received: from wa-out-1112.google.com ([209.85.146.179]:29351)
by monty-python.gnu.org with esmtp (Exim 4.60)
(envelope-from ) id 1Lf6vC-0004tT-V3
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 01:19:07 -0500
Original-Received: by wa-out-1112.google.com with SMTP id k17so1876422waf.26
for ; Wed, 04 Mar 2009 22:19:04 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
h=domainkey-signature:received:received:date:from:to:subject
:message-id:in-reply-to:references:x-mailer:mime-version
:content-type; bh=rKIaigPvb0PE27aHcRobnou1K86k+y4HKEr9C5rq3oo=;
b=NYuRWLBMldewcNxsQbxKEAz+pLrCBWCy2Rwhu8vvSMoI7LAp7puBCRxSgyZLaY/J5a
9cjLznkjJq4lttxnEbjzRZSuD9h9wRk5H4DtP0TeN1ORiMIEzoV+XXJqcNTjcYFx/udP
fJGdPJMZN/OcvSrbWu6iGEb6ymqIPXaxLZ/Og=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
h=date:from:to:subject:message-id:in-reply-to:references:x-mailer
:mime-version:content-type;
b=eANGbOzBpcbTfo88EcszXY63CRQq9KcpoeefeLdP/3K8XRi3n7QC5BAqZ9kQylyo/z
gnLLmTMMWrnwRrhQS/p3QIv6i6oGIMFSwTsmnoMJ1NRTGzGsyoMbHMhc95jpNwCZBzBY
xj7Zepl23cXHkO1EvTSXRhZyjmJ01/dC8Tguc=
Original-Received: by 10.115.111.3 with SMTP id o3mr465053wam.60.1236233944242;
Wed, 04 Mar 2009 22:19:04 -0800 (PST)
Original-Received: from localhost (c66-235-1-45.sea2.cablespeed.com [66.235.1.45])
by mx.google.com with ESMTPS id j34sm1208502waf.27.2009.03.04.22.19.03
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Wed, 04 Mar 2009 22:19:04 -0800 (PST)
In-Reply-To: <87fxhukvuu.fsf@gmail.com>
X-Mailer: Claws Mail 3.7.0 (GTK+ 2.12.11; i686-pc-linux-gnu)
X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Mailman-Approved-At: Thu, 05 Mar 2009 04:31:19 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:62606
Archived-At:
--Sig_/BzsYHvKPe=ZB+ITBJ8lgUKg
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
On Tue, 03 Mar 2009 23:52:25 +0000
W Dan Meyer wrote:
> Xah Lee writes:
>=20
> > On Mar 3, 9:59 am, Mike Mattie wrote:
> >> On Tue, 03 Mar 2009 17:34:41 +0000
> >>
> >> Leo wrote:
> >> > On 2008-12-21 09:49 +0000, Helmut Eller wrote:
> >> > >> I'm pretty sure if you create it, more and more people will
> >> > >> join it. I'm very interested in PEG and think it is of
> >> > >> critical importance.
> >>
> >> > > I'll try to set up project at savannah.
> >>
> >> > I have seen the project on
> >> >http://savannah.nongnu.org/projects/emacs-peg. I wonder it might
> >> >be a
> >> > good idea to make a newsgroup on gmane to link to the mailing
> >> > list. It will make more Emacs users subscribe to it.
> >>
> >> > Best wishes,
> >>
> >> I was working on a PEG/CFG parser
> >> compiler:http://www.emacswiki.org/cgi-bin/wiki/ParserCompiler
> >>
> >> I will be resuming the development soon. Please keep me in the
> >> loop on such efforts.
>=20
> Are we talking about memoising PEG (e.g Packrat) in elisp? There
> might be more people interested. I do realise that Emacs doesn't
> have decent parsing facility and it makes it's regular expression
> based engine in more complex areas useless (mentioned nested tags).
> Since it's automata based you cannot go beyond simple patterns. That
> means also that everybody is reinventing a wheel with implanting all
> those recursive decent parsers when it comes to analyse, pretty
> print, syntax highlight of such modes like Haskell one. Packrat
> parser is the best option out there currently because it recognises
> much complex grammar then LALR(1), and it has no ambiguities with
> expressing these grammars. Works well also as a standalone combinator
> based solution rather then a parser generator, plus it is lex-less
> e.g allow to recognise several different languages in _one_go_ and
> one context without marking them explicitly! cheers Dan W
Yes, packrat PEG. I am currently working on the left recursion, and the mem=
oization.
The code generator is done. It is still very alpha, and a vehicle for exper=
imenting, but
it is also the third iteration.
I want to make it useful first, which requires a number of features, and th=
en try some more
exotic things.
The design goal is to produce a parser compiler that is easy to use. There =
are many tasks, or
good projects in Emacs that would be far easier to solve with a parser.=20
It is implemented as a macro so that you can go from from grammer to parser=
is a single eval.=20
There is a direct correlation between the grammar and the AST produced in s=
imple
grammars. With these two features you can quickly put together a parser to =
glue various
jobs together. It will be complete too so you aren't handicapped in complex=
grammars.
Beyond that I want to implement more before I venture on where the design c=
an go.
What I don't expect is parsing large volumes of data such as the linux kern=
el tree
at reasonable speed. Maybe it will, For that I would expect
to port it outside of elisp.
I won't give timelines, but I have more time than before (0) to work on it =
now.
Cheers,
Mike Mattie
--Sig_/BzsYHvKPe=ZB+ITBJ8lgUKg
Content-Type: application/pgp-signature; name=signature.asc
Content-Disposition: attachment; filename=signature.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
iEYEARECAAYFAkmvbtUACgkQdfRchrkBInly8ACgrqNN4W14UdtgW2TT6Oj6tv8O
Y0cAn2RaLP+0iJbKcZC3Q96PVKepFl/A
=hjZu
-----END PGP SIGNATURE-----
--Sig_/BzsYHvKPe=ZB+ITBJ8lgUKg--
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Mike Mattie
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Wed, 4 Mar 2009 22:55:54 -0800
Message-ID: <20090304225554.07eb4dd3@gmail.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
<067151a4-b892-4e9a-8600-e2dcd92cb0ad@v18g2000pro.googlegroups.com>
<87fxhukvuu.fsf@gmail.com> <87d4cyqg5n.fsf@catnip.gol.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1236245576 15852 80.91.229.12 (5 Mar 2009 09:32:56 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 5 Mar 2009 09:32:56 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 05 10:34:11 2009
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1Lf9xy-0004Ih-8T
for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Mar 2009 10:34:10 +0100
Original-Received: from localhost ([127.0.0.1]:44738 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1Lf9wc-0002uV-Ug
for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Mar 2009 04:32:46 -0500
Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
id 1Lf7Uw-0000Bi-A7
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 01:56:02 -0500
Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
id 1Lf7Uu-00009v-50
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 01:56:01 -0500
Original-Received: from [199.232.76.173] (port=56701 helo=monty-python.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43) id 1Lf7Ut-00009p-UZ
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 01:55:59 -0500
Original-Received: from wa-out-1112.google.com ([209.85.146.177]:46959)
by monty-python.gnu.org with esmtp (Exim 4.60)
(envelope-from ) id 1Lf7Ut-0008AJ-Ah
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 01:55:59 -0500
Original-Received: by wa-out-1112.google.com with SMTP id k17so1884204waf.26
for ; Wed, 04 Mar 2009 22:55:58 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
h=domainkey-signature:received:received:date:from:to:subject
:message-id:in-reply-to:references:x-mailer:mime-version
:content-type:content-transfer-encoding;
bh=CDyzybrQeWVOm0vO4ZVnA7hSVvTez14Zqci6rN3Vx8Y=;
b=uaq94By90nPJ5jhMiXsGZh763Y3gfrDs8uAFLJ68eHs+jQQpWX8QiRmEMmwXD4yvVA
DmmnJF4er9eWokK0OGsZAXO7Us+XQMZVF7fZ9q/t0pmHJKEtOskbRdPCquMNJFYl6cVP
JAlGpiDg2ObhWn41EU7N/vaum9DYZcb+ogFoE=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;
h=date:from:to:subject:message-id:in-reply-to:references:x-mailer
:mime-version:content-type:content-transfer-encoding;
b=S306o44dYqZRPt/AdO7BYBJQX7gxRC/QiGDSOeFbPMngc+izebnTM+o0HkHnqp3OoS
PGAHJ3DUnnjc+3VMa5wSo79QZPYN+Xv+vb7tXKka068iMciChWF2HYfxWc/DJoao0hPc
yahJ1eOdqPnXDrIEbADvdMFFQBwuaXjxzR+YU=
Original-Received: by 10.115.73.20 with SMTP id a20mr490616wal.1.1236236158086;
Wed, 04 Mar 2009 22:55:58 -0800 (PST)
Original-Received: from localhost (c66-235-1-45.sea2.cablespeed.com [66.235.1.45])
by mx.google.com with ESMTPS id k35sm2118660waf.21.2009.03.04.22.55.57
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Wed, 04 Mar 2009 22:55:57 -0800 (PST)
In-Reply-To: <87d4cyqg5n.fsf@catnip.gol.com>
X-Mailer: Claws Mail 3.7.0 (GTK+ 2.12.11; i686-pc-linux-gnu)
X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Mailman-Approved-At: Thu, 05 Mar 2009 04:31:19 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:62607
Archived-At:
On Wed, 04 Mar 2009 09:35:00 +0900
Miles Bader wrote:
> W Dan Meyer writes:
> > Are we talking about memoising PEG (e.g Packrat) in elisp? ...
> > Packrat parser is the best option out there currently because it
> > recognises much complex grammar then LALR(1), and it has no
> > ambiguities with expressing these grammars.
>=20
> You also might be interested in Roberto Ierusalimschy's paper on the
> implemenation of LPEG, which is a PEG implementation for Lua:
>=20
> http://www.inf.puc-rio.br/~roberto/docs/peg.pdf
>=20
>=20
> Note that LPEG does _not_ use the packrat algorithm, as apparently it
> presents some serious practical problems for common uses of parsing
> tools:
>=20
> In 2002, Ford proposed Packrat [5], an adaptation of the
> original algorithm that uses lazy evaluation to avoid that
> inefficiency.
>=20
> Even with this improvement, however, the space complexity of the
> algorithm is still linear on the subject size (with a somewhat big
> constant), even in the best case. As its author himself recognizes,
> this makes the algorithm not befitting for parsing =E2=80=9Clarge amou=
nts
> of relatively flat=E2=80=9D data ([5], p. 57). However, unlike parsing to=
ols,
> regular-expression tools aim exactly at large amounts of relatively
> flat data.
>=20
> To avoid these difficulties, we did not use the Packrat
> algorithm for LPEG. To implement LPEG we created a virtual parsing
> machine, not unlike Knuth=E2=80=99s parsing machine [15], where each patt=
ern
> is represented as a program for the machine. The program is somewhat
> similar to a recursive-descendent parser (with limited
> backtracking) for the pattern, but it uses an explicit stack instead
> of recursion.
>=20
>=20
> The general LPEG page is here:
>=20
> http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html
>=20
>=20
> -Miles
>=20
It seems there is a convergence :) I implemented the same thing in my
parser compiler, with a different intent.The PEG operators decompose
down to an internal instruction set translated by the core into
elisp functions.
The VM is a co-routine of two functions. A compiler which generates
code from a valid instruction set, and a "union" function which
determines the validity of a given instruction sequence. The union
essentially attempts to pack as many instructions as possible into
a matching function. When adding an instruction produces an invalid set
it kicks the set to the compile function and starts a fresh matching=20
function.
My goal was to allow the creation of custom operators for the ugly parts
of practical grammars that can be mixed with standard operators
in a consistent fashion. If the compiler is flexible enough then maybe
the AST can move inside the parser so the user does not have to re-invent
the wheel from the match hooks -> AST.
It's probably getting a bit to parser specific for emacs-help, but if you
want to compare notes feel free to e-mail me.
Cheers,
Mike Mattie
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Xah Lee
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Tue, 3 Mar 2009 14:05:39 -0800 (PST)
Organization: http://groups.google.com
Message-ID: <067151a4-b892-4e9a-8600-e2dcd92cb0ad@v18g2000pro.googlegroups.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1236245636 16039 80.91.229.12 (5 Mar 2009 09:33:56 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 5 Mar 2009 09:33:56 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 05 10:35:11 2009
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1Lf9yu-0004bB-Pu
for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Mar 2009 10:35:09 +0100
Original-Received: from localhost ([127.0.0.1]:45200 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1Lf9xZ-0003IL-Hr
for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Mar 2009 04:33:45 -0500
Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!v18g2000pro.googlegroups.com!not-for-mail
Original-Newsgroups: gnu.emacs.help,comp.emacs,comp.lang.lisp
Original-Lines: 90
Original-NNTP-Posting-Host: 24.6.175.142
Original-X-Trace: posting.google.com 1236117939 30375 127.0.0.1 (3 Mar 2009 22:05:39
GMT)
Original-X-Complaints-To: groups-abuse@google.com
Original-NNTP-Posting-Date: Tue, 3 Mar 2009 22:05:39 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: v18g2000pro.googlegroups.com; posting-host=24.6.175.142;
posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,
gzip(gfe), gzip(gfe)
Original-Xref: news.stanford.edu gnu.emacs.help:167267 comp.emacs:97912
comp.lang.lisp:262163
X-Mailman-Approved-At: Thu, 05 Mar 2009 04:32:50 -0500
X-BeenThere: help-gnu-emacs@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Users list for the GNU Emacs text editor
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.help:62608
Archived-At:
On Mar 3, 9:59 am, Mike Mattie wrote:
> On Tue, 03 Mar 2009 17:34:41 +0000
>
> Leo wrote:
> > On 2008-12-21 09:49 +0000, Helmut Eller wrote:
> > >> I'm pretty sure if you create it, more and more people will join
> > >> it. I'm very interested in PEG and think it is of critical
> > >> importance.
>
> > > I'll try to set up project at savannah.
>
> > I have seen the project on
> >http://savannah.nongnu.org/projects/emacs-peg. I wonder it might be a
> > good idea to make a newsgroup on gmane to link to the mailing list. It
> > will make more Emacs users subscribe to it.
>
> > Best wishes,
>
> I was working on a PEG/CFG parser compiler:http://www.emacswiki.org/cgi-b=
in/wiki/ParserCompiler
>
> I will be resuming the development soon. Please keep me in the loop on su=
ch efforts.
Folks,
when you create a PEG parser, please please make it user oriented one,
so that any user of emacs familiar with regex find-replace will be
able to use PEG for find-replace. In particular, when doing find-
replace on nested text such as XML.
regex is powerful, but it doesn't do nested text. PEG comes to the
rescue. However, it needs to be regex-like, in the sense that the
program interface will be a simple source text and replacement text.
e.g. a function peg-replace that takes 2 args, pattern text, and text
source. The pattern text can be the region, buffer, or a filename, the
text source to work on can be similar. (thus, maybe peg-replace-
region, peg-replace-buffer, peg-replace-file etc.)
last time i was looking at PEG, i opted to try Helmut Eller's version
because it seems simpler. (mike's version is far more compiler geeking
incomprehensible) But still problematic to use. I got busy in other
things so i didn't continue on studying it, so i dropped out of this
thread (havn't read Helmut's last message in detail). Rather, i simply
want just to use it. Last in this thread, he mentioned about stacks
and i went huh... and just didn't have time to go further.
Regex is practically extremely useful, a tool every programer uses
today. However, regex cannot work with nested text such as XML/HTML,
which is used extensively, probably more so than any programing lang
or text. So, brigining regex power to html/xml will be a major impact
on not just emacs, but the whole programing industry. PEG, practically
speaking, is basically just the next generation of so-called regex.
Emacs can be the first to have such a feature. (existing PEG
implementations in various lang, at this point, as far as i know, are
all tech geeking toys, done by geekers interested in language parsing
and so on.)
Personally, i have huge need for regex that can work on html.
PEG is of course not just a regex replacement, but a BNF replacement
in the sense it is actually for machines to read. For these reasons
that's how i got heavily interested in PEG. (see:
=E2=80=A2 Pattern Matching vs Lexical Grammar Specification
http://xahlee.org/cmaci/notation/pattern_matching_vs_pattern_spec.html
)
Please make your PEG in emacs with a regex-like API. Something any
emacs user familiar with regex will be able to use brainlessly. This
will be huge...
i had plans to open a mailing list and stuff... but got busy with
other things. I'll come back to this. But i hope you are convienced
about making PEG usable as a text-editing tool, as opposed to a tool
for computer scientist or compiler/parser writers.
Also, Mike & Helmut, please consider putting your code in goode code.
Google Code is very popular, probably today the most popular code
building service, and extremely easy to use, and from my studies
Google's products and services are all extremely high quality. It
would help a lot in your software at least in the marketing aspect if
you use Google Code. Also, open a google group is very useful and
popular. (yasnippet is a successful example for a emacs project on
google code. There are several others, including e.g. js2, ejacs, the
erlang one, etc.) Going into Savana or anything on FSF services tend
to be a dead end. (yeah, controversy, but whatever.)
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: Mike Mattie
Newsgroups: gmane.emacs.help
Subject: Re: how to use parsing expressing grammar
Date: Thu, 5 Mar 2009 08:38:06 -0800
Message-ID: <20090305083806.1ea2aeef@gmail.com>
References: <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
<098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com>
<91fa65a0-a7e7-4374-8f96-5786c8908615@w24g2000prd.googlegroups.com>
<067151a4-b892-4e9a-8600-e2dcd92cb0ad@v18g2000pro.googlegroups.com>
NNTP-Posting-Host: lo.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1236319336 18249 80.91.229.12 (6 Mar 2009 06:02:16 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 6 Mar 2009 06:02:16 +0000 (UTC)
To: help-gnu-emacs@gnu.org
Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 06 07:03:31 2009
Return-path:
Envelope-to: geh-help-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([199.232.76.165])
by lo.gmane.org with esmtp (Exim 4.50)
id 1LfT9e-0004EL-5s
for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Mar 2009 07:03:30 +0100
Original-Received: from localhost ([127.0.0.1]:42892 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43)
id 1LfT8I-00052A-Gr
for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Mar 2009 01:02:06 -0500
Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
id 1LfGaP-0003LB-3V
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 11:38:17 -0500
Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
id 1LfGaM-0003Kb-S2
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 11:38:16 -0500
Original-Received: from [199.232.76.173] (port=51856 helo=monty-python.gnu.org)
by lists.gnu.org with esmtp (Exim 4.43) id 1LfGaM-0003KX-LD
for help-gnu-emacs@gnu.org; Thu, 05 Mar 2009 11:38:14 -0500
Original-Received: from wa-out-1112.google.com ([209.85.146.177]:8817)
by monty-python.gnu.org with esmtp (Exim 4.60)
(envelope-from