On Mon, Jan 14, 2002 at 11:01:57PM -0500, Aaron D. Marasco wrote:
> At 22:54 14 01 2002, Ronald J Kimball wrote:
> >On Mon, Jan 14, 2002 at 07:32:15PM -0500, Aaron D. Marasco wrote:
> >>
> >> The double hyphen in front of the incoming text is optional and could have
> >> spaces on either side of it. The spaces between "fields" is arbitrary (but
> >> never tabs). The signal fields always have at least one space on the left,
> >
> >Is that in addition to the space after the double hyphen?
>
> it is required to make sense. After all, these are comments we are parsing,
> and it is wise to have the signals indented under what they are for...
I'll take that as a yes.
> >Are there any kinds of lines besides comments and signal fields?
>
> Well, the rest of the code, but I have no problem with cut & paste of the
> script out of the VHDL comments and then cutting that block out of the code.
Okay, as long as it doesn't need to be accounted for in our solutions.
> >> The overall length of the script is the most important, speed is
> >> no concern. Lines are limited to 78 characters too. :(
> >
> >Four lines:
> >
> >#!perl -nl
> >s/^ ?-- ?//;push@a,[s/:$//?"--== $_ ==--":/^ *(\S+)\s+(\S+)\s*(\S*)/];
> >$;=$:if($:=length$1)>$;}{*b=$_,$#b?($b[2]=~s/.+/_vector($& downto 0)/,
> >$b[2]=~s/^/ std_logic/,printf"%-$;s : %s%s;\n",@b):print@b for@a
>
> OK, let's see if I can figure this one out...
>
> I think s/^[ -]*//; would beat s/^ ?-- ?//; wouldn't it?
As long as you're confident in the formatting of your input. As far as I
know there may be lines that start with '- -' or something like that.
> After that, I cannot keep track anymore of what is going on. :(
Okay, the annotated version... :)
#!perl -nl
# while (<>) {
# chomp;
## from -n
s/^ ?-- ?//;
# remove the leading double hyphen, if present.
push @a, [ s/:$// ? "--== $_ ==--" : /^ *(\S+)\s+(\S+)\s*(\S*)/ ];
# push an anonymous array onto @a
# if $_ ends with a colon (which is removed), the anonymous array
# contains the string "--== $_ ==--"
# otherwise, the anonymous contains the three substrings matched by
# /^ *(\S+)\s+(\S+)\s*(\S*)/
$; = $: if ($:=length$1) > $;
# if the length of $1 is greater than $;
# then assign the length of $1 to $;
# $; will hold the maximum length of $1 over all the lines
} ## # while (<>) {
{
*b=$_,
# assign the array reference in $_ to *b
# now @b is the same array as @$_
$#b
? (
$b[2]=~s/.+/_vector($& downto 0)/,
$b[2]=~s/^/ std_logic/,
printf"%-$;s : %s%s;\n",@b
)
: print @b
# if @b does not have exactly one element
# then do some substitutions on the third element of @b
# and print out the formatted string with the elements of @b
# otherwise just print the contents of @b
for @a
# do all that for each element in @a
# } ## {
## from -n
Ronald