On 15/06/2011 16:02, Jim Gibson wrote:
At 12:38 PM +0100 6/15/11, Rob Dixon wrote:
On 15/06/2011 12:10, Paul Johnson wrote:
On Tue, Jun 14, 2011 at 11:56:04PM -0700, Beware wrote:
Hi
Sorry, i've been tired these past days.
So, this is what i want to do :
I've source code files in VHDL. I want to check that all specific
keywords of this language are in uppercase.
In fact, in my current script i read this file line per line and
check others rules.
Am i clear, now?
Here is some code that does this. I suggest you make sure you
understand what
it does and check that it is correct. Call it by passing the names of
your
VHDL files.
Note that this code isn't very clever. In particular you will get false
positives. To do the job properly you would need a VHDL parser. For that
reason I would suggest against modifying the code to alter the input
file as
part of a checkin hook, for example.
(I prefer my keywords to be in lowercase.)
#!/usr/bin/perl
use strict;
use warnings;
my @keywords = qw
(
abs access after alias all and architecture array assert attribute begin
block body buffer bus case component configuration constant disconnect
downto else elsif end entity exit file for function generate generic
group
guarded if impure in inertial inout is label library linkage literal
loop
map mod nand new next nor not null of on open or others out package port
postponed procedure process pure range record register reject return rol
ror select severity signal shared sla sli sra srl subtype then to
transport type unaffected units until use variable wait when while with
xnor xor
);
my $kw = join "|", @keywords;
You would need
my $kw = join "|", map uc, @keywords;
Why? He is using the 'i' modifier in the regular expression to find all
keywords regardless of case (lower, upper, mixed). Then checking to see
if the extracted keyword is equal to the upper-case version and printing
a warning message if it is not.
Very true: I missed the uc within the loop and the code is fine as it
stands. But it would be better to write, as John said
my $kw = uc join "|", @keywords;
and drop the call inside the loop.
warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq $w;
while (<>) {
for my $w (/(\b$kw\b)/ig) {
warn "Keyword '$w' not uppercase at $ARGV:$.\n" unless $w eq uc $w;
}
}
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/