Class SimpleLexer

Description

Accepts text and breaks it into tokens.

Some optimisation to make the sure the content is only scanned by the PHP regex parser once. Lexer modes must not start with leading underscores.

Located in /libraries/pear/simpletest/parser.php (line 178)


	
			
Variable Summary
 mixed $_case
 mixed $_mode
 mixed $_parser
 mixed $_regexes
Method Summary
 SimpleLexer SimpleLexer (SimpleSaxParser &$parser, [string $start = "accept"], [boolean $case = false])
 void addEntryPattern (string $pattern, string $mode, string $new_mode)
 void addExitPattern (string $pattern, string $mode)
 void addPattern (string $pattern, [string $mode = "accept"])
 void addSpecialPattern (string $pattern, string $mode, string $special)
 void mapHandler (string $mode, string $handler)
 boolean parse (string $raw)
 string _decodeSpecial (string $mode)
 boolean _dispatchTokens (string $unmatched, string $matched, [string $mode = false])
 void _invokeParser (string $content, boolean $is_match)
 boolean _isModeEnd (string $mode)
 boolean _isSpecialMode (string $mode)
 array _reduce (string &$raw)
Variables
mixed $_case (line 183)
mixed $_mode (line 181)
mixed $_mode_handlers (line 182)
mixed $_parser (line 180)
mixed $_regexes (line 179)
Methods
Constructor SimpleLexer (line 194)

Sets up the lexer in case insensitive matching by default.

  • access: public
SimpleLexer SimpleLexer (SimpleSaxParser &$parser, [string $start = "accept"], [boolean $case = false])
  • SimpleSaxParser $parser: Handling strategy by reference.
  • string $start: Starting handler.
  • boolean $case: True for case sensitive.
addEntryPattern (line 233)

Adds a pattern that will enter a new parsing mode. Useful for entering parenthesis, strings, tags, etc.

  • access: public
void addEntryPattern (string $pattern, string $mode, string $new_mode)
  • string $pattern: Perl style regex, but ( and ) lose the usual meaning.
  • string $mode: Should only apply this pattern when dealing with this type of input.
  • string $new_mode: Change parsing to this new nested mode.
addExitPattern (line 248)

Adds a pattern that will exit the current mode and re-enter the previous one.

  • access: public
void addExitPattern (string $pattern, string $mode)
  • string $pattern: Perl style regex, but ( and ) lose the usual meaning.
  • string $mode: Mode to leave.
addPattern (line 213)

Adds a token search pattern for a particular parsing mode. The pattern does not change the current mode.

  • access: public
void addPattern (string $pattern, [string $mode = "accept"])
  • string $pattern: Perl style regex, but ( and ) lose the usual meaning.
  • string $mode: Should only apply this pattern when dealing with this type of input.
addSpecialPattern (line 267)

Adds a pattern that has a special mode. Acts as an entry and exit pattern in one go, effectively calling a special parser handler for this token only.

  • access: public
void addSpecialPattern (string $pattern, string $mode, string $special)
  • string $pattern: Perl style regex, but ( and ) lose the usual meaning.
  • string $mode: Should only apply this pattern when dealing with this type of input.
  • string $special: Use this mode for this one token.
mapHandler (line 280)

Adds a mapping from a mode to another handler.

  • access: public
void mapHandler (string $mode, string $handler)
  • string $mode: Mode to be remapped.
  • string $handler: New target handler.
parse (line 294)

Splits the page text into tokens. Will fail

if the handlers report an error or if no content is consumed. If successful then each unparsed and parsed token invokes a call to the held listener.

  • return: True on success, else false.
  • access: public
boolean parse (string $raw)
  • string $raw: Raw HTML text.
_decodeSpecial (line 382)

Strips the magic underscore marking single token modes.

  • return: Underlying mode name.
  • access: private
string _decodeSpecial (string $mode)
  • string $mode: Mode to decode.
_dispatchTokens (line 327)

Sends the matched token and any leading unmatched text to the parser changing the lexer to a new mode if one is listed.

  • return: False if there was any error from the parser.
  • access: private
boolean _dispatchTokens (string $unmatched, string $matched, [string $mode = false])
  • string $unmatched: Unmatched leading portion.
  • string $matched: Actual token match.
  • string $mode: Mode after match. A boolean false mode causes no change.
_invokeParser (line 395)

Calls the parser method named after the current mode. Empty content will be ignored. The lexer has a parser handler for each mode in the lexer.

  • access: private
void _invokeParser (string $content, boolean $is_match)
  • string $content: Text parsed.
  • boolean $is_match: Token is recognised rather than unparsed data.
_isModeEnd (line 359)

Tests to see if the new mode is actually to leave the current mode and pop an item from the matching mode stack.

  • return: True if this is the exit mode.
  • access: private
boolean _isModeEnd (string $mode)
  • string $mode: Mode to test.
_isSpecialMode (line 371)

Test to see if the mode is one where this mode is entered for this token only and automatically leaves immediately afterwoods.

  • return: True if this is the exit mode.
  • access: private
boolean _isSpecialMode (string $mode)
  • string $mode: Mode to test.
_reduce (line 420)

Tries to match a chunk of text and if successful removes the recognised chunk and any leading unparsed data. Empty strings will not be matched.

  • return: Three item list of unparsed content followed by the recognised token and finally the action the parser is to take. True if no match, false if there is a parsing error.
  • access: private
array _reduce (string &$raw)
  • string $raw: The subject to parse. This is the content that will be eaten.

Documentation generated on Fri, 10 Dec 2004 18:26:06 +0000 by phpDocumentor 1.3.0RC3