Subject: shorter struct regex?

From: "James A. Robinson" <[email-masked]>
Date: Sat, 18 Mar 2000 00:24:24 -0500

I'm starting to develop some mild RSI problems, and am trying to move away
from the mouse. This leads me to look at editors like vi or sam instead
of wily. In wily I end up using a pipe to sam half the time anyway, so
I'm working through using structured regular expressions while editing
my code in sam.

I just worked through a problem, and am wondering if there was a shorter
way to solve it.  I had a bunch of arrays defined in a java file:

...
public Hashtable return()
throws MissingRequiredValueException
{
	String[] req =
	{
		"order-id", "amount"
	};

	String[] opt =
	{
		"card-number", "card-exp", "card-name", "card-address", "card-city",
		"card-zip"
	};
	return processRequest("return", req, opt);
}
...

I wanted to expand the elements of the arrays to one per line. This is
what I used:

,x/{\n([^}]+\n)+	}/x/, +[^\n]/x/ +/c/\n		/

Is there way I could of done this with less work?

Jim

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       [email-masked]
Stanford University HighWire Press      http://highwire.stanford.edu/
650-723-7294 (W) 650-725-9335 (F)

---

From: Byron Rakitzis <[email-masked]>
Date: Wed, 22 Mar 2000 19:05:47 -0500

> ....

Jim,

One of my favorite tricks is a pipe to fmt. Fmt will preserve leading
whitespace (well, it can be trickier than that since fmt tries to do
pharagraph indentation as well). To force one-column output, you only
need to do "fmt -1", which strictly speaking denotes one-CHARACTER output,
but fmt does the right thing.

So:

piped through "fmt -1" gives (at least on this linux machine):

		"card-number",
		"card-exp",
		"card-name",
		"card-address",
		"card-city",
		"card-zip"

Of course, you still have the problem about selecting the braced-in
regions without using the mouse. Perhaps another out-of-the-box approach
is to pipe your entire code through a C beautifier. "indent" has so
many options, I would be surprised if array initializers one-per-line
was not one of them.

Byron.

---

From: "James A. Robinson" <[email-masked]>
Date: Thu, 23 Mar 2000 10:19:04 -0500

> > In sam, highlight the suspect arrays and then ,s/, */,\n	/g
> would work.  This is a case where I think using the mouse
> makes more sense than typing all the gook.  

Ah, but the point was to do this without the mouse. =) Not because I'm
perverse, but because I had about 30 of these arrays in my program. Plus
I'm writing it in noweb, so I had a mix of latex documentation mixed in
with the code (which about doubles the size of the file).

> But if you want
> to type the gook, can't you just say
> 
> 	,x/{([^}]|\n)+}/,s/, */,\n	/g

The extra ',' in there before s/// would mess things up. But with a few
tweaks, like making sure it doesn't add a newline if one already exists:

	,x/{([^}]|\n)+}/s/, *[^\n]/,\n		/g

It works and would have saved 8 characters. Thank you!

Jim

---

From: Bengt Kleberg <[email-masked]>
Date: Thu, 23 Mar 2000 04:51:53 -0500

> From: "James A. Robinson" <[email-masked]>

> I wanted to expand the elements of the arrays to one per line.

> ,x/{\n([^}]+\n)+	}/x/, +[^\n]/x/ +/c/\n		/
This might be totally wrong, but I assume that since you have 'hard coded'
the 2 #\tab in the final c// expression I am allowed the same kind of
works-for-this-problem solution :-).
Presumable there is a way to get hold of the amount of #\tab and then use t to
copy it to the right place...

Anyway, my suggestion would be:
,x/	+".+\n/ x/ +/ c/\n		/

Best Wishes, Bengt
===============================================================
Everything aforementioned should be regarded as totally private
opinions, and nothing else. [email-masked]
``His great strength is that he is uncompromising. It would make
him physically ill to think of programming in C++.''