#!/usr/bin/env parrot-nqp INIT { pir::load_bytecode("YAML/Tiny.pbc"); pir::loadlib("io_ops"); } sub check_pir($file, @regexes) { my @deprecations; my $fh := pir::new('FileHandle'); $fh.open($file); my $line := 1; while $fh.readline -> $l { for @regexes -> $regex { my $r := $regex[0]; if $l ~~ / $r / { @deprecations.push("$file:$line: { $regex[2] }"); } } $line++; } $fh.close; return @deprecations; } MAIN(pir::getinterp()[2]); sub MAIN(@ARGS) { my $name := @ARGS.shift; my @files; my $apiyaml := 'api.yaml'; USAGE($name) unless pir::elements(@ARGS); # getopt my $arg; while $arg := @ARGS.shift { say("Parsing $arg"); if $arg eq '--help' || $arg eq '-h' { USAGE($name); } elsif $arg == '--apiyaml' { $apiyaml := @ARGS.shift; } else { @files.push($arg); } } # unless pir::stat__ISI($apiyaml, 0) { # FIXME this produces the error # say("$apiyaml not found, aborting"); # pir::exit(1); # } # prepare the regexes my $parser := YAML::Tiny.new; my $api := $parser.read_string(slurp($apiyaml)); my @regs_pir; for $api[0] { if $_ && $_ { if $_ { my $r := $_; @regs_pir.push( [Regex::P6Regex::Compiler.compile($r), $r, $_] ); } } } # check the given files for @files -> $f { if $f ~~ / '.pir' $ / { say(check_pir($f, @regs_pir).join("\n")); } } } sub USAGE($name) { say("Usage: $name "); pir::exit(1); } # vim: ft=perl6