help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to use parsing expressing grammar


From: Helmut Eller
Subject: Re: how to use parsing expressing grammar
Date: Sat, 20 Dec 2008 10:34:45 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

* Xah Lee [2008-12-20 09:42+0100] writes:

> 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”.

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 "<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 "./ '"])
>    )
> )

Same problem here.  

If the basics work you can try to generalize this a bit.  E.g.

(imgTag "<img" whitespace (* attribute whitespace) ">")
(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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]