views:

164

answers:

4

I need to parse JavaDoc (documentation) comment syntax with Delphi 7. It is well known in the java world as "JavaDoc", but I'm actually doing this for PHP, ie, parsing JavaDoc in some PHP code. Call it PHPDoc if you want to. To see how these comments work, you can see RAD IDEs like NetBeans etc.

Example of JavaDoc for addition function:

/**
 * 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;
}

Please note that the parser need not be full, ie, parsing all of the PHP code. I mean, it's perfectly fine if it accepted the comment text only as input.

Cheers, Chris.

A: 

Have you googled on PHPDocumentor?

Mark Baker
Sorry if I wasn't clear enough.I need to parser JavaDoc in PHP using Delphi.Converting PHPDocumenter to Delphi is obviously not an option (I've used the software and it's pretty big).
Christian Sciberras
+3  A: 

You may be inspired by DelpiCodeToDoc : http://dephicodetodoc.sourceforge.net/ It is a documentation system for Delphi, using the JavaDoc syntax. It is not exactly what you want (you need it for PHP sources) but the support is good & reactive and may be your needs will be included in a next version.

philnext
I'll give it a look.
Christian Sciberras
+2  A: 

Hi, I had to implement phpDoc parsing format for my own PHP IDE. What I'm doing is simply parsing char by char, the pascal code similar to this:

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;

the code is not perfect (there should be more checking whether indexes are > 0 and < len, etc) but should give you the idea of what I'm talking about.

the code has not been tested, nor even compiled - written in the "your answer" box of SO ;) ;)

migajek
Guess I'll just expand on this.
Christian Sciberras
Well, I always voted for "home-made" stuff. I think this ought to satisfy my question and needs.
Christian Sciberras
A: 

You could use a regular expression engine (one based IIRC on PCRE is included in JCL) to parse comments easily and extract the information you need.

ldsandon