[ Index ] |
PHP Cross Reference of DokuWiki |
[Source view] [Print] [Project Stats]
Lexer adapted from Simple Test: http://sourceforge.net/projects/simpletest/ For an intro to the Lexer see: https://web.archive.org/web/20120125041816/http://www.phppatterns.com/docs/develop/simple_test_lexer_notes
Author: | Marcus Baker http://www.lastcraft.com |
File Size: | 349 lines (11 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
Lexer:: (15 methods):
__construct()
addPattern()
addEntryPattern()
addExitPattern()
addSpecialPattern()
mapHandler()
parse()
getModeStack()
dispatchTokens()
isModeEnd()
isSpecialMode()
decodeSpecial()
invokeHandler()
reduce()
escape()
__construct($handler, $start = "accept", $case = false) X-Ref |
Sets up the lexer in case insensitive matching by default. param: \Doku_Handler $handler Handling strategy by reference. param: string $start Starting handler. param: boolean $case True for case sensitive. |
addPattern($pattern, $mode = "accept") X-Ref |
Adds a token search pattern for a particular parsing mode. The pattern does not change the current mode. param: string $pattern Perl style regex, but ( and ) param: string $mode Should only apply this |
addEntryPattern($pattern, $mode, $new_mode) X-Ref |
Adds a pattern that will enter a new parsing mode. Useful for entering parenthesis, strings, tags, etc. param: string $pattern Perl style regex, but ( and ) lose the usual meaning. param: string $mode Should only apply this pattern when dealing with this type of input. param: string $new_mode Change parsing to this new nested mode. |
addExitPattern($pattern, $mode) X-Ref |
Adds a pattern that will exit the current mode and re-enter the previous one. param: string $pattern Perl style regex, but ( and ) lose the usual meaning. param: string $mode Mode to leave. |
addSpecialPattern($pattern, $mode, $special) X-Ref |
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. param: string $pattern Perl style regex, but ( and ) lose the usual meaning. param: string $mode Should only apply this pattern when dealing with this type of input. param: string $special Use this mode for this one token. |
mapHandler($mode, $handler) X-Ref |
Adds a mapping from a mode to another handler. param: string $mode Mode to be remapped. param: string $handler New target handler. |
parse($raw) X-Ref |
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: boolean True on success, else false. param: string $raw Raw HTML text. |
getModeStack() X-Ref |
Gives plugins access to the mode stack return: StateStack |
dispatchTokens($unmatched, $matched, $mode, $initialPos, $matchPos) X-Ref |
Sends the matched token and any leading unmatched text to the parser changing the lexer to a new mode if one is listed. return: boolean False if there was any error from the parser. param: string $unmatched Unmatched leading portion. param: string $matched Actual token match. param: bool|string $mode Mode after match. A boolean false mode causes no change. param: int $initialPos param: int $matchPos Current byte index location in raw doc thats being parsed |
isModeEnd($mode) X-Ref |
Tests to see if the new mode is actually to leave the current mode and pop an item from the matching mode stack. return: boolean True if this is the exit mode. param: string $mode Mode to test. |
isSpecialMode($mode) X-Ref |
Test to see if the mode is one where this mode is entered for this token only and automatically leaves immediately afterwoods. return: boolean True if this is the exit mode. param: string $mode Mode to test. |
decodeSpecial($mode) X-Ref |
Strips the magic underscore marking single token modes. return: string Underlying mode name. param: string $mode Mode to decode. |
invokeHandler($content, $is_match, $pos) X-Ref |
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. return: bool param: string $content Text parsed. param: boolean $is_match Token is recognised rather param: int $pos Current byte index location in raw doc |
reduce(&$raw) X-Ref |
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: array|bool Three item list of unparsed content followed by the param: string $raw The subject to parse. This is the content that will be eaten. |
escape($str) X-Ref |
Escapes regex characters other than (, ) and / return: string param: string $str |