#!/usr/bin/perl -w use strict; use warnings; unless (@ARGV) { die "Usage: syntax-check \n" . "This app does super simple syntax checking: making sure that\n" . "brackets are all matched up. It sees if the aiml2rs had any\n" . "hiccups along the way.\n"; } opendir (DIR, $ARGV[0]); foreach my $file (sort(grep(/\.rs$/i, readdir(DIR)))) { print "Syntax checking $ARGV[0]/$file...\n"; open (READ, "$ARGV[0]/$file"); my $line = 0; while () { $line++; chomp; my @chars = split(//, $_); my $curly = 0; # {} my $angled = 0; # <> foreach my $c (@chars) { $curly++ if $c eq '{'; $curly-- if $c eq '}'; $angled++ if $c eq '<'; $angled-- if $c eq '>'; } # Warnings? my $warning = ''; if ($curly > 0) { $warning .= "Unmatched left curly bracket; "; } if ($curly < 0) { $warning .= "Unmatched right curly bracket; "; } if ($angled > 0) { $warning .= "Unmatched left chevron; "; } if ($angled < 0) { $warning .= "Unmatched right chevron; "; } if (length $warning) { print "\tWarning: $warning\n" . "\t$line: $_\n"; } } close (READ); } closedir (DIR);