unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: ashishnkadakia@gmail.com
To: help-gnu-emacs@gnu.org
Subject: Re: how to use parsing expressing grammar
Date: Tue, 23 Dec 2008 15:21:07 -0800 (PST)	[thread overview]
Message-ID: <d17068f9-b067-470e-be0b-6803e4fff1a7@w1g2000prk.googlegroups.com> (raw)
In-Reply-To: 098ddc5b-7074-41fb-a921-caee3bddddff@t39g2000prh.googlegroups.com

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 am, Xah Lee <xah...@gmail.com> wrote:
> more questions on parsing expression grammar.
>
> let's say i want to change tags of the form
>
> “<img src="archimedesspiral.png">”
>
> into
>
> “<img src="★">”
>
> I tried the following:
>
> (defun doMyReplace ()
> (interactive)
>   (peg-parse
>    (start imgTag)
>   (imgTag "<img" whitespace "src=" "\"" (replace filePath "★") "\""
> ">")
>   (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”.
>
> 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 “div”.
>
> So basically,
>
> <img ...>
>
> needs to become
>
> <div><img ...></div>
>
> 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 "<img" whitespace
>  "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 "./ '"])
>    )
> )
>
> 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
> ∑http://xahlee.org/
>
> ☄
>
> On Dec 19, 3:27 pm, Xah Lee <xah...@gmail.com> wrote:
>
> > On Dec 17, 10:22 am, Helmut Eller <eller.hel...@gmail.com> 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.  As 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.  E.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 ()
> > >   (peg-parse
> > >    (start _ "<hr>" _ title _ ul)
> > >    (title "<p>" (replace (* (not "</p>") (any)) "See also:") "</p>")
> > >    (ul (replace "<ul>" "<p>") _ (*list li _) (replace "</ul>" "</p>"))
> > >    (li (replace "<li>" "") (* (not "</li>") (any)) (replace "</li>" "<br>"))
> > >    (_ (* (or whitespace comment)))
> > >    (whitespace ["\n\t "])
> > >    (comment "<-- " (* (not "-->") (any)) "-->")))
>
> > > Helmut.
>
> > Holy cow. This worked! LOL!
>
> > Thanks!
>
> >   Xah
> > ∑http://xahlee.org/
>
> > ☄



  parent reply	other threads:[~2008-12-23 23:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <6b8a1070-1a89-48b0-9287-343b673b5758@a29g2000pra.googlegroups.com>
     [not found] ` <m27i5yygi5.fsf@gmail.com>
     [not found]   ` <m2k59ywtj2.fsf@gmail.com>
     [not found]     ` <b3203a8b-324f-440f-98a9-653c8d582c7c@y1g2000pra.googlegroups.com>
2008-12-20  8:42       ` how to use parsing expressing grammar Xah Lee
2008-12-20  9:34         ` Helmut Eller
2008-12-20 21:41           ` Xah Lee
2008-12-21  9:49             ` Helmut Eller
2009-03-03 17:34               ` Leo
2009-03-03 17:59                 ` Mike Mattie
     [not found]                 ` <mailman.2299.1236115586.31690.help-gnu-emacs@gnu.org>
2009-03-03 22:05                   ` Xah Lee
2009-03-03 23:52                     ` W Dan Meyer
2009-03-04  0:35                       ` Miles Bader
2009-03-05  6:55                         ` Mike Mattie
2009-03-05  6:18                       ` Mike Mattie
2009-03-05 16:38                     ` Mike Mattie
2009-03-06  8:53                     ` Helmut Eller
2008-12-20 22:27           ` Xah Lee
2008-12-21 11:24             ` Helmut Eller
2008-12-23 23:21         ` ashishnkadakia [this message]
2008-12-17 11:53 Xah Lee
2008-12-18  3:43 ` Kevin Rodgers
     [not found] ` <mailman.3007.1229571828.26697.help-gnu-emacs@gnu.org>
2008-12-18  9:24   ` Xah Lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d17068f9-b067-470e-be0b-6803e4fff1a7@w1g2000prk.googlegroups.com \
    --to=ashishnkadakia@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).