Thank you for the responses Vincent and Neil. <br><br>Neil, thanks for the information here-I will meditate on this and how to utilize it. <br><br>-Patrick<br><br><div class="gmail_quote">On 4 November 2012 22:34, Neil Van Dyke <span dir="ltr"><<a href="mailto:neil@neilvandyke.org" target="_blank">neil@neilvandyke.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So you would like to be able to do things like rename an identifier, change "(if X Y)" to "(and X Y)", change "(if (not X) Y Z)" to "(if X Z Y)", etc.?<br>
<br>
If so, I would probably start by letting user specify transformation rules like for "syntax-case" or "syntax-parse", do "read-syntax", do some simple tree traversal of the syntax objects that tries the rules at each step, have a matching rule add to a list of "progedit" "replace" operations, and then finally feed those operations through "progedit".<br>
<br>
And alternative would be to use parse info from Check Syntax, perhaps with the user's transformation rules in effect. I haven't thought that through, so it might be overkill. If you go that direction, you might think of a different rules language, rather than "syntax-case" or "syntax-parse".<br>
<br>
One gotcha with "progedit" with syntax objects, depending on how you use it: comments are not usually in the syntax objects, and can get deleted if you are not careful, or left in the wrong place if you don't do additional work. For example of changing "if" forms to "and" forms, you want to replace only the "if" keyword, not the entire form, so that:<br>
<br>
(if X<br>
;; hi<br>
Y)<br>
<br>
ends up looking like this:<br>
<br>
(and X<br>
;; hi<br>
Y)<br>
<br>
If the replace operation is for the entire "if" form, you will lose the comment:<br>
<br>
(and X Y)<br>
<br>
For example of comments in wrong place, let's say you are getting rid of "not" around the condition of an "if" form by swapping the order of the arms. Like in previous example, to preserve comments, you want your progedit replace operations to focus on small pieces that don't have important comments within them, so if you do that, then this:<br>
<br>
(if (not X)<br>
;; X is false, so Y<br>
Y<br>
;; X is true, so Z<br>
Z)<br>
<br>
becomes:<br>
<br>
(if X<br>
;; X is false, so Y<br>
Z<br>
;; X is true, so Z<br>
Y)<br>
<br>
The problem is that the comments are in the wrong places. The current version of progedit doesn't have any magic for moving comments around -- you'll have to figure out how you want comments moved, and then probably move the comments using progedit delete and insert operations, in addition to the syntax changes you are making. An alternative way would be to have the syntax reader include syntax objects for comments, and then deal with it in pattern-matching and transformation that way.<br>
<br>
(I plan to add these notes about comments to the progedit documentation. No promises on building in smarter handling of comments into progedit itself anytime soon, unless a get a chance to think more about a good approach for it.)<br>
<br>
Neil V.<br>
<br>
</blockquote></div><br>