[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to use parsing expressing grammar
From: |
Xah Lee |
Subject: |
Re: how to use parsing expressing grammar |
Date: |
Sat, 20 Dec 2008 14:27:39 -0800 (PST) |
User-agent: |
G2/1.0 |
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?
e.g. to match
<img src="some.png" alt="pretty" width="33" height="33" >
(defun doMyReplace ()
(interactive)
(peg-parse
(imgTag "<img" _ (+ attributes _) ">")
(attributes (or src alt width height))
(src "src" _* "=" _* "\"" filePath "\"")
(filePath (+ [A-Z a-z "./_-"]))
(alt "alt" _* "=" _* "\"" altStr "\"")
(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]))
)
)
suppose i want to swap the src and alt text and have
<img src="pretty" alt="some.png" width="33" height="33" >
Thanks.
Xah
∑ http://xahlee.org/
☄
Re: how to use parsing expressing grammar, ashishnkadakia, 2008/12/24