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