OSDN Git Service

DocParser: remove decorations before processing
authorscribu <mail@scribu.net>
Thu, 1 Aug 2013 20:18:57 +0000 (23:18 +0300)
committerscribu <mail@scribu.net>
Thu, 1 Aug 2013 20:18:57 +0000 (23:18 +0300)
php/WP_CLI/DocParser.php

index f830285..ebd9a52 100644 (file)
@@ -7,11 +7,19 @@ class DocParser {
        protected $docComment;
 
        function __construct( $docComment ) {
-               $this->docComment = $docComment;
+               $this->docComment = self::remove_decorations( $docComment );
+       }
+
+       private static function remove_decorations( $comment ) {
+               $comment = preg_replace( '|^/\*\*\n|', '', $comment );
+               $comment = preg_replace( '|\n[\t ]*\*/$|', '', $comment );
+               $comment = preg_replace( '|^[\t ]*\* ?|m', '', $comment );
+
+               return $comment;
        }
 
        function get_shortdesc() {
-               if ( !preg_match( '/\* (\w.+)\n*/', $this->docComment, $matches ) )
+               if ( !preg_match( '|^([^@][^\n]+)\n*|', $this->docComment, $matches ) )
                        return false;
 
                return $matches[1];
@@ -22,14 +30,14 @@ class DocParser {
        }
 
        function get_tag( $name ) {
-               if ( preg_match( '/@' . $name . '\s+([a-z-_]+)/', $this->docComment, $matches ) )
+               if ( preg_match( '|^@' . $name . '\s+([a-z-_]+)|m', $this->docComment, $matches ) )
                        return $matches[1];
 
                return false;
        }
 
        function get_synopsis() {
-               if ( !preg_match( '/@synopsis\s+([^\n]+)/', $this->docComment, $matches ) )
+               if ( !preg_match( '|^@synopsis\s+(.+)|m', $this->docComment, $matches ) )
                        return false;
 
                return $matches[1];