Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: c:/www/apache/doc2//parser/PhpdocParserCore.php
PHPDOC 2000/12/03 - 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 variabledeclarations.

AuthorsUlf Wendel <ulf.wendel@phpdoc.de>
Version$Id: $

 
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, [ mixed $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, $application, $warn, $flag_output

Public Method Details

getModulesAndClasses

public array getModulesAndClasses( string $phpcode )

  Does a quick prescan to find modules an classes.

Parameter
string $phpcode
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, [ mixed $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 ofphpcode 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 elementgets extracted. It does not take the code from the class definition and it's openingcurly brace to the closing one. PHPDoc just extracts the class definition itself andif available a trailing doc comment. This has some drawbacks: phpdoc can't handlefiles that contain more than one class it wouldn't know which method/class variable belongs toa 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 expressionsthere'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 wasfaster. This one takes 13s on my machine to scan the current (14/08/2000) code (7130 lines), thebig RegExp way took more than 5 Minutes, the preg_match_all + looking backwards 52s.

Parameter
string $phpcode
code to scan.
mixed $keywords = >>"none"<<
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 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
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 hugememory intensive hashes. Now it scans for classes, builds a classtree anddoes the parsing step by step, writing information to the destination(renderer, exporter) as soon as possible. This reduces the memory consumptiondramatically. getPhpdocParagraphs() could be used to extract the class definitionsas well but this specialized function is somewhat faster.

Parameter
string $phpcode
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
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 functionreturns an array of the short description and long description.

Parameter
string $phpdoc
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 valuebecause the value might contain unescaped charaters that end the value.Value means something like "array ( ";", '\;' );" or "'phpdoc; ';" wherethe delimiter would be ";".

Parameter
string $code
php code to examine.
mixed $delimiter
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 findtype and value. This is used to analyse class variable declarations andoptional function arguments.Note that all regular expressions in this function start with "^". That meansyou have to do some preparations to the code snippet you're passing to thisfunction.

Parameter
string $code
code to analyse
boolean $flag_args = >>true<<
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