代码之家  ›  专栏  ›  技术社区  ›  Christian

Delphi JavaDoc分析器

  •  2
  • Christian  · 技术社区  · 15 年前

    我需要用Delphi7解析JavaDoc(文档)注释语法。 它在Java世界中是众所周知的“JavaDoc”,但实际上我是为PHP做这件事的,即在一些PHP代码中解析JavaDoc。如果你想叫它phpdoc。 要了解这些注释是如何工作的,您可以看到rad-ides,如netbeans等。

    添加函数的javadoc示例:

    /**
     * Adds to numbers together.
     * @param integer $a The first number.
     * @param integer $b The second number.
     * @return integer The resulting number.
     */
    function add($a,$b){
      return $a+$b;
    }
    

    请注意,解析器不必是完整的,即解析所有的PHP代码。 我是说,如果它接受了评论文本,那就太好了 只有

    干杯, 克里斯。

    4 回复  |  直到 15 年前
        1
  •  2
  •   migajek    15 年前

    我必须为自己的php ide实现phpdoc解析格式。我要做的只是逐字符分析,pascal代码类似于:

    len := length(fCode);
    i:= 1;
    inComment:= false;
    while i < len do
    begin
      case fCode[i] of
       '*': begin 
            if (fCode[i-1] = '/') and (fCode[i+1] = '*') then
            begin
              inComment:= true;
            end
            else if fCode[i+1] = '/' then
            begin
              inComment:= false;
            end;
       '@' : begin
                j:= i;
                while (fCode[i] in ['a'..'z','A'..'Z']) do
                    inc(i);
                tagName:= copy(fCode, j, i - j +1);
                // do it again for type, name and the rest MIGHT be description! check for liebreak!
             end;
      end;
     inc(i);
    end;
    

    代码并不完美(应该有更多的检查索引是否为>0和<len等),但应该让您了解我在说什么。

    代码没有被测试,甚至没有被编译-写在so;)的“你的答案”框中;)

        2
  •  3
  •   philnext    15 年前

    您可能会受到DelpicodeToDoc的启发: http://dephicodetodoc.sourceforge.net/ 它是一个Delphi的文档系统,使用JavaDoc语法。 它不完全是您想要的(您需要它作为PHP源),但是支持是好的和反应性的,并且可能是您的需求将包含在下一个版本中。

        3
  •  0
  •   Mark Baker    15 年前

    你在谷歌上搜索过吗 PHPDocumentor ?

        4
  •  0
  •   user160694    15 年前

    您可以使用正则表达式引擎(JCL中包含一个基于PCRE的IIRC)轻松解析注释并提取所需的信息。

    推荐文章