Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added dedeprecator script to detect deprecations in Parrot code

Copied from https://github.com/tadzik/parrot-deprecation-detector
Modified api.yaml to add the detection regexes
  • Loading branch information...
commit b8c1df9c49ba46d88858536fa80b0d57f151db6c 1 parent 8c03bce
@tadzik tadzik authored
Showing with 142 additions and 0 deletions.
  1. +6 −0 api.yaml
  2. +136 −0 tools/dev/dedeprecator
View
6 api.yaml
@@ -19,6 +19,9 @@
- 'PIR'
- 'syntax'
- 'deprecated'
+ detection:
+ regex:
+ pir: '^ ".sub" .+ ":init"'
ticket: 'https://trac.parrot.org/parrot/ticket/1896'
-
name: '":load" and ":init" Sub flags doing different things'
@@ -81,6 +84,9 @@
tags:
- 'deprecated'
- 'PMC'
+ detection:
+ regex:
+ pir: 'new\s\[?\''Complex\''\]?'
ticket: 'https://trac.parrot.org/parrot/ticket/1892'
-
name: 'Cross-HLL library loading'
View
136 tools/dev/dedeprecator
@@ -0,0 +1,136 @@
+#!/usr/bin/env parrot-nqp
+
+=begin README
+dedepracator: find deprecations in your Parrot code
+
+This script, fed with a yaml file with Parrot deprecations
+(you probably want it to be Parrot's api.yaml), will scan your code
+for a deprecations and warn you about them.
+
+Usage:
+
+# scan the current directory for deprecations
+$ dedeprecator
+
+# scan test.pir for deprecations, using api.yaml
+$ dedeprecator test.pir
+
+# scan bar.pir and baz.pir using the alternate api.yaml file
+$ dedeprecator --apiyaml /somewhere/else/foo.yaml bar.pir baz.pir
+
+# in case you forgot everything
+$ dedeprecator -h
+# or
+$ dedeprecator --help
+=end README
+
+INIT {
+ pir::load_bytecode("YAML/Tiny.pbc");
+ pir::loadlib("os");
+}
+
+sub check_pir($file, @regexes) {
+ my @deprecations;
+
+ my $fh := pir::new('FileHandle');
+ $fh.open($file);
+ $fh.encoding('utf8');
+ 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';
+# getopt
+ my $arg;
+ while pir::elements(@ARGS) {
+ $arg := @ARGS.shift;
+ if $arg eq '--help' || $arg eq '-h' {
+ USAGE($name);
+ } elsif $arg eq '--apiyaml' {
+ unless pir::elements(@ARGS) {
+ say("--apiyaml requires an argument");
+ USAGE($name);
+ }
+ $apiyaml := @ARGS.shift;
+ } else {
+ @files.push($arg);
+ }
+ }
+# prepare the regexes
+ my $parser := YAML::Tiny.new;
+ my $api;
+ try {
+ $api := $parser.read_string(slurp($apiyaml));
+ CATCH {
+ say("Failed parsing '$apiyaml'\n"
+ ~ "Make sure that it exists and is a valid YAML");
+ pir::exit(1);
+ }
+ }
+ my @regs_pir;
+ for $api[0] {
+ if $_<detection> && $_<detection><regex> {
+ if $_<detection><regex><pir> {
+ my $r := $_<detection><regex><pir>;
+ @regs_pir.push(
+ [Regex::P6Regex::Compiler.compile($r), $r, $_<name>]
+ );
+ }
+ }
+ }
+# if no files are given, find all files in the current directory,
+# recursively
+ unless pir::elements(@files) {
+ my $os := pir::new('OS');
+ my @candidates := $os.readdir('.');
+ while pir::elements(@candidates) {
+ my $file := @candidates.shift;
+ # this probably can be written better
+ next if $file ~~ /[^ '.' $] | [^ '..' $]
+ | ['/..' $] | ['/.' $]/;
+ @files.push($file);
+ try { # try is isdir said funny
+ for $os.readdir($file) {
+ @candidates.push("$file/$_");
+ }
+ }
+ }
+ }
+# check the given files
+ for @files -> $f {
+ if $f ~~ / '.pir' $ / {
+ my @d;
+ try {
+ @d := check_pir($f, @regs_pir);
+ CATCH {
+ say("Failed checking $f: $!");
+ }
+ }
+ if pir::elements(@d) {
+ say(@d.join("\n"));
+ }
+ }
+ }
+}
+
+sub USAGE($name) {
+ say("Usage: $name [--apiyaml <api.yaml file>] [<files to check>]");
+ pir::exit(1);
+}
+
+# vim: ft=perl6
Please sign in to comment.
Something went wrong with that request. Please try again.