Class StringParser

Description

Generic string parser class

This is an abstract class for any type of string parser.

Located in /stringparser.class.php (line 68)


	
			
Direct descendents
Class Description
 class StringParser_BBCode BB code string parser class
Variable Summary
 boolean $strict
 integer $_cpos
 integer $_length
 boolean $_parsing
 array $_prefilters
 mixed $_root
 array $_stack
 int $_status
 string $_text
Method Summary
 StringParser StringParser ()
 bool addFilter (int $type, mixed $callback)
 bool clearFilters (int $type)
 mixed parse (string $text)
 bool _appendText (string $text)
 bool _appendToLastTextChild (string $text)
 void _applyPostfilters (mixed $text)
 void _applyPrefilters (mixed $text)
 bool _handleStatus (int $status, string $needle)
 bool _loop ()
 bool _modifyTree ()
 bool _outputTree ()
 void _parserInit ()
 bool _popNode ()
 bool _pushNode (object &$node)
 bool _searchLoop ()
 void _setStatus (mixed $status)
 mixed _strDetect (array $needles, int $offset)
 array _strpos (array $needles, int $offset)
 mixed _topNode ()
 mixed _topNodeVar (mixed $var)
Variables
boolean $strict = false (line 144)

Strict mode

Whether to stop parsing if a parse error occurs.

  • access: public
array $_charactersAllowed = array () (line 169)

Characters currently allowed

Note that this will only be evaluated in loop mode; in search mode this would ruin every performance increase. Note that only single characters are permitted here, no strings. Please also note that in loop mode, StringParser::_charactersSearch is evaluated before this variable.

If in strict mode, parsing is stopped if a character that is not allowed is encountered. If not in strict mode, the character is simply ignored.

  • access: private
array $_charactersSearch = array () (line 151)

Characters or strings to look for

  • access: private
integer $_cpos = -1 (line 109)

Current position in raw text

  • access: private
integer $_length = -1 (line 123)

Length of the text

  • access: private
int $_parserMode = STRINGPARSER_MODE_SEARCH (line 88)

String parser mode

There are two possible modes: searchmode and loop mode. In loop mode every single character is looked at in a loop and it is then decided what action to take. This is the most straight-forward approach to string parsing but due to the nature of PHP as a scripting language, it can also cost performance. In search mode the class posseses a list of relevant characters for parsing and uses the http://www.php.net/strpos function to search for the next relevant character. The search mode will be faster than the loop mode in most circumstances but it is also more difficult to implement. The subclass that does the string parsing itself will define which mode it will implement.


Redefined in descendants as:
boolean $_parsing = false (line 134)

Flag if this object is already parsing a text

This flag is to prevent recursive calls to the parse() function that would cause very nasty things.

  • access: private
array $_postfilters = array () (line 190)

Postfilters

  • access: private
array $_prefilters = array () (line 183)

Prefilters

  • access: private
bool $_recentlyReparsed = false (line 197)

Recently reparsed?

  • access: private
mixed $_root = null (line 116)

Root node

  • access: private
array $_stack = array () (line 102)

Parse stack

  • access: private
int $_status = 0 (line 176)

Current parser status

  • access: private
string $_text = '' (line 95)

Raw text

  • access: private
Methods
Constructor StringParser (line 204)

Constructor

  • access: public
StringParser StringParser ()
addFilter (line 216)

Add a filter

bool addFilter (int $type, mixed $callback)
  • int $type: The type of the filter
  • mixed $callback: The callback to call
clearFilters (line 244)

Remove all filters

bool clearFilters (int $type)
  • int $type: The type of the filter or 0 for all
parse (line 272)

This function parses the text

  • return: Either the root object of the tree if no output method is defined, the tree reoutput to e.g. a string or false if an internal error occured, such as a parse error if in strict mode or the object is already parsing a text.
  • access: public
mixed parse (string $text)
  • string $text: The text to parse
_appendText (line 667)

Abstract method Append text depending on current status

  • return: On success, the function returns true, else false
  • access: private
bool _appendText (string $text)
  • string $text: The text to append

Redefined in descendants as:
_appendToLastTextChild (line 681)

Append text to last text child of current top parser stack node

  • return: On success, the function returns true, else false
  • access: private
bool _appendToLastTextChild (string $text)
  • string $text: The text to append
_applyPostfilters (line 398)

Apply postfilters

It is possible to specify postfilters for the parser to do some manipulating of the string afterwards.

void _applyPostfilters (mixed $text)
_applyPrefilters (line 380)

Apply prefilters

It is possible to specify prefilters for the parser to do some manipulating of the string beforehand.

void _applyPrefilters (mixed $text)
_closeRemainingBlocks (line 479)

Abstract method: Close remaining blocks

  • access: private
void _closeRemainingBlocks ()

Redefined in descendants as:
_handleStatus (line 526)

Abstract method: Handle status

  • access: private
bool _handleStatus (int $status, string $needle)
  • int $status: The current status
  • string $needle: The needle that was found

Redefined in descendants as:
_loop (line 605)

Loop mode loop

  • access: private
bool _loop ()
_modifyTree (line 415)

Abstract method: Manipulate the tree

  • access: private
bool _modifyTree ()

Redefined in descendants as:
_outputTree (line 424)

Abstract method: Output tree

  • access: private
bool _outputTree ()

Redefined in descendants as:
_parserInit (line 501)

Abstract method: Initialize the parser

  • access: private
void _parserInit ()
_popNode (line 766)

Removes a node from the current parse stack

  • return: True on success, else false.
  • see: StringParser_Node, StringParser::_stack
  • access: private
bool _popNode ()
_pushNode (line 749)

Adds a node to the current parse stack

  • return: True on success, else false.
  • see: StringParser_Node, StringParser::_stack
  • access: private
bool _pushNode (object &$node)
  • object $node: The node that is to be added
_reparseAfterCurrentBlock (line 438)

Restart parsing after current block

To achieve this the current top stack object is removed from the tree. Then the current item

  • access: protected
bool _reparseAfterCurrentBlock ()

Redefined in descendants as:
_searchLoop (line 537)

Search mode loop

  • access: private
bool _searchLoop ()
_setStatus (line 509)

Abstract method: Set a specific status

  • access: private
void _setStatus (mixed $status)

Redefined in descendants as:
_strDetect (line 730)

Detects a string at the current position

  • return: The string that was detected or the needle
  • access: private
mixed _strDetect (array $needles, int $offset)
  • array $needles: The strings that are to be detected
  • int $offset: The current offset
_strpos (line 705)

Searches StringParser::_text for every needle that is

specified by using the http://www.php.net/strpos function. It returns an associative array with the key

  1. 'needle'
pointing at the string that was found first and the key
  1. 'offset'
pointing at the offset at which the string was found first. If no needle was found, the
  1. 'needle'
element is
  1. false
and the
  1. 'offset'
element is
  1. -1
.

  • see: StringParser::_text
  • access: private
array _strpos (array $needles, int $offset)
  • array $needles
  • int $offset
_topNode (line 778)

Execute a method on the top element

  • access: private
mixed _topNode ()
_topNodeVar (line 798)

Get a variable of the top element

  • access: private
mixed _topNodeVar (mixed $var)

Documentation generated on Sun, 14 Aug 2005 14:26:36 +0200 by phpDocumentor 1.3.0RC3