Class StringParser

Description

Generic string parser class

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

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


	
			
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 = 0])
 mixed parse (string $text)
 bool _appendText (string $text)
 bool _appendToLastTextChild (string $text)
 void _applyPostfilters ( $text)
 void _applyPrefilters ( $text)
 bool _handleStatus (int $status, string $needle)
 bool _loop ()
 bool _modifyTree ()
 bool _outputTree ()
 void _parserInit ()
 bool _popNode ()
 bool _pushNode ( &$node, object $node)
 bool _searchLoop ()
 void _setStatus ( $status)
 mixed _strDetect (array $needles, int $offset)
 array _strpos (array $needles, int $offset)
 mixed _topNode ()
 mixed _topNodeVar ( $var)
Variables
boolean $strict = false (line 142)

Strict mode

Whether to stop parsing if a parse error occurs.

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

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: protected
array $_charactersSearch = array () (line 149)

Characters or strings to look for

  • access: protected
integer $_cpos = -1 (line 107)

Current position in raw text

  • access: protected
integer $_length = -1 (line 121)

Length of the text

  • access: protected
int $_parserMode = STRINGPARSER_MODE_SEARCH (line 86)

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 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 132)

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: protected
array $_postfilters = array () (line 188)

Postfilters

  • access: protected
array $_prefilters = array () (line 181)

Prefilters

  • access: protected
bool $_recentlyReparsed = false (line 195)

Recently reparsed?

  • access: protected
mixed $_root = null (line 114)

Root node

  • access: protected
array $_stack = array () (line 100)

Parse stack

  • access: protected
int $_status = 0 (line 174)

Current parser status

  • access: protected
string $_text = '' (line 93)

Raw text

  • access: protected
Methods
Constructor StringParser (line 202)

Constructor

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

Add a filter

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

Remove all filters

bool clearFilters ([int $type = 0])
  • int $type: The type of the filter or 0 for all
parse (line 270)

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 665)

Abstract method Append text depending on current status

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

Redefined in descendants as:
_appendToLastTextChild (line 679)

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

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

Apply postfilters

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

void _applyPostfilters ( $text)
  • $text
_applyPrefilters (line 378)

Apply prefilters

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

void _applyPrefilters ( $text)
  • $text
_closeRemainingBlocks (line 477)

Abstract method: Close remaining blocks

  • access: protected
void _closeRemainingBlocks ()

Redefined in descendants as:
_handleStatus (line 524)

Abstract method: Handle status

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

Redefined in descendants as:
_loop (line 603)

Loop mode loop

  • access: protected
bool _loop ()
_modifyTree (line 413)

Abstract method: Manipulate the tree

  • access: protected
bool _modifyTree ()

Redefined in descendants as:
_outputTree (line 422)

Abstract method: Output tree

  • access: protected
bool _outputTree ()

Redefined in descendants as:
_parserInit (line 499)

Abstract method: Initialize the parser

  • access: protected
void _parserInit ()
_popNode (line 764)

Removes a node from the current parse stack

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

Adds a node to the current parse stack

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

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 535)

Search mode loop

  • access: protected
bool _searchLoop ()
_setStatus (line 507)

Abstract method: Set a specific status

  • access: protected
void _setStatus ( $status)
  • $status

Redefined in descendants as:
_strDetect (line 728)

Detects a string at the current position

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

Searches StringParser::_text for every needle that is

specified by using the 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: protected
array _strpos (array $needles, int $offset)
  • array $needles
  • int $offset
_topNode (line 776)

Execute a method on the top element

  • access: protected
mixed _topNode ()
_topNodeVar (line 796)

Get a variable of the top element

  • access: protected
mixed _topNodeVar ( $var)
  • $var

Documentation generated on Mon, 10 Dec 2007 13:29:39 +0100 by phpDocumentor 1.4.0