Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: /home/cch/www/pear/PHPDoc/parser/PhpdocParserCore.php
PEAR Repository - PHPDoc

PhpdocParserCore

PhpdocObject
   |
  +-- PhpdocParserRegExp
     |
    +-- PhpdocParserTags
       |
      +-- PhpdocParserCore

Provides basic parser functions.

 

private class PhpdocParserCore extends PhpdocParserTags

Provides basic parser functions.

Provides basic parser functions to extract doc comments, analyse tags and variable
declarations.

AuthorsUlf Wendel <ulf@redsys.de>
Version0.3

 
Direct known subclasses: PhpdocUseParser

Methods inherited from PhpdocParserTags

analysetags, analyseseetagregs, gettags, gettagpos, checkparsererrors

Methods inherited from PhpdocParserRegExp

buildcomplexregexps

Methods inherited from PhpdocObject

setflagoutput, out, nametourl, outl, introspection

Public Method Summary

array

getModulesAndClasses(string $phpcode)

Does a quick prescan to find modules an classes.

Private Method Summary

array

getPhpdocParagraphs(string $phpcode, [ string $keywords ])

Scans code for documented and undocumented phpdoc keywords (classes, functions, class variables, uses, constants).
array

getModuleDoc(string $phpcode)

Tries to extract a module doc.
array

getClasses(string $phpcode)

Returns a list of classes found in the given code.
string

extractPhpdoc(string $paragraph)

Strips "/xx", "x/" and x from doc comments (x means asterix).
array

getDescription(string $phpdoc)

Extract the description from a PHPDoc doc comment.
string

getValue(string $code, mixed $delimiter)

Scans a code passage for a value.
array

getVariableTypeAndValue(string $code, [ boolean $flag_args ])

Analyses a code snipped and returns the type and value of the first variable found.

Fields inherited from PhpdocParserRegExp

$phpdoc_tags, $c_base, $c_complex, $php_base, $php_complex, $tags

Fields inherited from PhpdocObject

$err, $flag_output, $application, $warn

Public Method Details

getModulesAndClasses

public array getModulesAndClasses( string $phpcode )

  Does a quick prescan to find modules an classes.

Parameter
string $phpcode
Code to scan
Returns array

Hash of modules and classes found in the given code

See Also getPhpdocParagraphs()

Private Method Details

getPhpdocParagraphs

private array getPhpdocParagraphs( string $phpcode, [ string $keywords ] )

  Scans code for documented and undocumented phpdoc keywords (classes, functions, class variables, uses, constants).

This method is somewhat the heart of the phpdoc parser. It takes a string of
phpcode and extracts all classes, functions, class variables, uses (include and friends),
and constants (define) from it. Extract does not mean that the whole class or another element
gets extracted. It does not take the code from the class definition and it's opening
curly brace to the closing one. PHPDoc just extracts the class definition itself and
if available a trailing doc comment. This has some drawbacks: phpdoc can't handle
files that contain more than one class it wouldn't know which method/class variable belongs to
a certain class. It's possible to provide a workaround but phpdoc would slow down dramatically.
As PHPDoc does not have a real parser but does a simple grep using a bunch of regular expressions
there're indeed more limitations. Nevertheless I doubt that you'll have problems with "normal" code.

The search algorithm looks pretty strange but belive me it's fast. I have tried several other ways
(really complex regexps >500 chars, preg_match_all + looking backwards for comments, ...) but none was
faster. This one takes 13s on my machine to scan the current (14/08/2000) code (7130 lines), the
big RegExp way took more than 5 Minutes, the preg_match_all + looking backwards 52s.

Parameter
string $phpcode
PHP code to scan.
string $keywords = >>"none"<<
String of one keyword or array of keywords not to scan for. Known keywords are:
"classes", "functions", "variables", "uses", "consts".
Returns array

Hash of phpdoc elements found, indexed by "variables", "functions", "classes", "consts", "uses".

See Also $PHP_BASE, $PHP_COMPLEX, $C_BASE, $C_COMPLEX, extractPhpdoc(), getModuleDoc()

getModuleDoc

private array getModuleDoc( string $phpcode )

  Tries to extract a module doc.

The syntax for modules is not final yet. The implementation and meaning of "module"
might change at every time! Please do not ask for implementation details.

Parameter
string $phpcode
PHP Code to scan
Returns array $module

$module[0] = array with module data,
$module[1] = php code without the leading module doc


getClasses

private array getClasses( string $phpcode )

  Returns a list of classes found in the given code.

In early versions PHPdoc parsed all the code at once which restulted in huge
memory intensive hashes. Now it scans for classes, builds a classtree and
does the parsing step by step, writing information to the destination
(renderer, exporter) as soon as possible. This reduces the memory consumption
dramatically. getPhpdocParagraphs() could be used to extract the class definitions
as well but this specialized function is somewhat faster.

Parameter
string $phpcode
PHP code to scan.
Returns array $classes

Array of classes found in the code. $classes[classname] = extends


extractPhpdoc

private string extractPhpdoc( string $paragraph )

  Strips "/xx", "x/" and x from doc comments (x means asterix).

Parameter
string $paragraph
Doc comment to clean up.
Returns string $phpdoc


getDescription

private array getDescription( string $phpdoc )

  Extract the description from a PHPDoc doc comment.

Every PHPDoc doc comment has the same syntax: /xx[break][x]short description
[break][[x]multiple line long description[break]][[x]@list of tags[. This function
returns an array of the short description and long description.

Parameter
string $phpdoc
Doc comment to examine.
Returns array $description

$description[0] = short description (first line),
$description[1] = long description (second line upto the first tag)


getValue

private string getValue( string $code, mixed $delimiter )

  Scans a code passage for a value.

There some cases where you can hardly use a regex to grep a value
because the value might contain unescaped charaters that end the value.
Value means something like "array ( ";", '\;' );" or "'phpdoc; ';" where
the delimiter would be ";".

Parameter
string $code
The php code to examine.
mixed $delimiter
String of one delimiter or array of delimiters.
Returns string

Value found in the code


getVariableTypeAndValue

private array getVariableTypeAndValue( string $code, [ boolean $flag_args ] )

  Analyses a code snipped and returns the type and value of the first variable found.

With version 0.3 PHPDoc tries to analyse variable declarations to find
type and value. This is used to analyse class variable declarations and
optional function arguments.

Note that all regular expressions in this function start with "^". That means
you have to do some preparations to the code snippet you're passing to this
function.

Parameter
string $code
PHP code to analyse
boolean $flag_args = >>true<<
Flag indicating the "type" of code to analyse. Optional
function parameters and class variables have a slightly
different syntax for arrays. By default function parameters
are expected.
Returns array $vartype

$vartype[0] = type, $vartype[1] = value, $vartype[2] = raw value



Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta