com php-langspec: Add check_refs tool: tools/check_re fs.php tools/util.php
[email protected] (Nikita Popov) Fri, 11 Nov 2016 21:10:47 +0000
| Newsgroups | php.standards.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit: 61641e09508d3588e02aa85f542e8702318597f3=0AAuthor: Nikita Pop= ov <[email protected]> Fri, 11 Nov 2016 22:10:47 +0100=0AParents: e07= c954abd8f04847eed6884defdf8bd2219e8cc=0ABranches: master=0A=0ALink: = http://git.php.net/?p=3Dphp-langspec.git;a=3Dcommitdiff;h=3D61641e09508d358= 8e02aa85f542e8702318597f3=0A=0ALog:=0AAdd check_refs tool=0A=0AChanged path= s:=0A A tools/check_refs.php=0A M tools/util.php=0A=0A=0ADiff:=0Adiff -= -git a/tools/check_refs.php b/tools/check_refs.php=0Anew file mode 100644= =0Aindex 0000000..f76e735=0A--- /dev/null=0A+++ b/tools/check_refs.php=0A@@= -0,0 +1,36 @@=0A+<?php error_reporting(E_ALL);=0A+=0A+require __DIR__ . '/= util.php';=0A+=0A+// Collect all valid anchors=0A+$anchors =3D [];=0A+forea= ch (spec_files() as $fileName =3D> $path) {=0A+ $contents =3D file_get_c= ontents($path);=0A+ foreach (heading_info($contents) as $info) {=0A+ = $fullAnchor =3D $fileName . '#' . $info['anchor'];=0A+ $anchors[= $fullAnchor] =3D true;=0A+ }=0A+}=0A+=0A+// Find unknown anchor referenc= es=0A+foreach (spec_files() as $fileName =3D> $path) {=0A+ $contents =3D= file_get_contents($path);=0A+=0A+ if (!preg_match_all('/\]\(([^)]+)\)/'= , $contents, $matches)) {=0A+ continue;=0A+ }=0A+=0A+ foreach = ($matches[1] as $anchor) {=0A+ if (!preg_match('/^(#|\d{2})/', $anch= or)) {=0A+ continue;=0A+ }=0A+=0A+ if ('#' =3D=3D= =3D $anchor[0]) {=0A+ $anchor =3D $fileName . $anchor;=0A+ = }=0A+=0A+ if (!isset($anchors[$anchor])) {=0A+ echo "Un= known anchor $anchor in $fileName\n";=0A+ }=0A+ }=0A+}=0Adiff --g= it a/tools/util.php b/tools/util.php=0Aindex e6d21e5..52a8a99 100644=0A--- = a/tools/util.php=0A+++ b/tools/util.php=0A@@ -17,6 +17,8 @@ function spec_f= iles() {=0A }=0A }=0A =0A+/* Iterator of heading information.=0A+ * Ass= oc array with title, anchor, level. */=0A function heading_info($code) {=0A= $anchors =3D [];=0A $lines =3D explode("\n", $code);=0A