WACT_TEMPLATE
[ class tree: WACT_TEMPLATE ] [ index: WACT_TEMPLATE ] [ all elements ]

Class: ExpressionLexer

Source Location: /framework/template/compiler/expressionlexer.inc.php

Class Overview


Accepts text and breaks it into tokens.

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

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.


Class Variables


$_case =

Type:   mixed

$_mode =

Type:   mixed

$_mode_handlers =

Type:   mixed

$_parser =

Type:   mixed

$_regexes =

Type:   mixed

Class Methods


constructor ExpressionLexer

Sets up the lexer in case insensitive matching by default.



ExpressionLexer ExpressionLexer( ExpressionParser &$parser, [string $start = "accept"], [boolean $case = false])

API Tags:

access:  public

Parameters:

ExpressionParser   $parser   Handling strategy by reference.
string   $start   Starting handler.
boolean   $case   True for case sensitive.

method addEntryPattern

Adds a pattern that will enter a new parsing mode.

Useful for entering parenthesis, strings, tags, etc.



void addEntryPattern( string $pattern, string $mode, string $new_mode)

API Tags:

access:  public

Parameters:

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.

method addExitPattern

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



void addExitPattern( string $pattern, string $mode)

API Tags:

access:  public

Parameters:

string   $pattern   Perl style regex, but ( and ) lose the usual meaning.
string   $mode   Mode to leave.

method addPattern

Adds a token search pattern for a particular parsing mode.

The pattern does not change the current mode.



void addPattern( string $pattern, [string $mode = "accept"])

API Tags:

access:  public

Parameters:

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.

method addSpecialPattern

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.



void addSpecialPattern( string $pattern, string $mode, string $special)

API Tags:

access:  public

Parameters:

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.

method mapHandler

Adds a mapping from a mode to another handler.



void mapHandler( string $mode, string $handler)

API Tags:

access:  public

Parameters:

string   $mode   Mode to be remapped.
string   $handler   New target handler.

method parse

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.



boolean parse( string $raw)

API Tags:

return:  True on success, else false.
access:  public

Parameters:

string   $raw   Raw HTML text.

method _decodeSpecial

Strips the magic underscore marking single token modes.



string _decodeSpecial( string $mode)

API Tags:

return:  Underlying mode name.
access:  private

Parameters:

string   $mode   Mode to decode.

method _dispatchTokens

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



boolean _dispatchTokens( string $unmatched, string $matched, [string $mode = false])

API Tags:

return:  False if there was any error from the parser.
access:  private

Parameters:

string   $unmatched   Unmatched leading portion.
string   $matched   Actual token match.
string   $mode   Mode after match. A boolean false mode causes no change.

method _invokeParser

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.



void _invokeParser( string $content, boolean $is_match)

API Tags:

access:  private

Parameters:

string   $content   Text parsed.
boolean   $is_match   Token is recognised rather than unparsed data.

method _isModeEnd

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



boolean _isModeEnd( string $mode)

API Tags:

return:  True if this is the exit mode.
access:  private

Parameters:

string   $mode   Mode to test.

method _isSpecialMode

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



boolean _isSpecialMode( string $mode)

API Tags:

return:  True if this is the exit mode.
access:  private

Parameters:

string   $mode   Mode to test.

method _reduce

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.



array _reduce( string &$raw)

API Tags:

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

Parameters:

string   $raw   The subject to parse. This is the content that will be eaten.
WACT: Copyright 2003 Procata, Inc. Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
Documentation generated on Sun, 28 Nov 2004 19:46:28 -0800 by phpDocumentor 1.2.3