addPattern() public method

The pattern does not change the current mode.
public addPattern ( string $pattern, string $mode = 'accept' )
$pattern string Perl style regex, but ( and ) lose the usual meaning.
$mode string Should only apply this pattern when dealing with this type of input.
Example #1
0
 function testModeMapping()
 {
     $handler = new MockTestParser();
     $handler->setReturnValue("a", true);
     $handler->expectAt(0, "a", array("aa", LEXER_MATCHED));
     $handler->expectAt(1, "a", array("(", LEXER_ENTER));
     $handler->expectAt(2, "a", array("bb", LEXER_MATCHED));
     $handler->expectAt(3, "a", array("a", LEXER_UNMATCHED));
     $handler->expectAt(4, "a", array("bb", LEXER_MATCHED));
     $handler->expectAt(5, "a", array(")", LEXER_EXIT));
     $handler->expectAt(6, "a", array("b", LEXER_UNMATCHED));
     $handler->expectCallCount("a", 7);
     $lexer = new SimpleLexer($handler, "mode_a");
     $lexer->addPattern("a+", "mode_a");
     $lexer->addEntryPattern("(", "mode_a", "mode_b");
     $lexer->addPattern("b+", "mode_b");
     $lexer->addExitPattern(")", "mode_b");
     $lexer->mapHandler("mode_a", "a");
     $lexer->mapHandler("mode_b", "a");
     $this->assertTrue($lexer->parse("aa(bbabb)b"));
 }
Example #2
0
 /**
  *    Matches attributes that are either single quoted,
  *    double quoted or unquoted.
  *    @param SimpleLexer $lexer     Lexer to add patterns to.
  *    @access private
  *    @static
  */
 function _addAttributeTokens(&$lexer)
 {
     $lexer->mapHandler('dq_attribute', 'acceptAttributeToken');
     $lexer->addEntryPattern('=\\s*"', 'tag', 'dq_attribute');
     $lexer->addPattern("\\\\\"", 'dq_attribute');
     $lexer->addExitPattern('"', 'dq_attribute');
     $lexer->mapHandler('sq_attribute', 'acceptAttributeToken');
     $lexer->addEntryPattern("=\\s*'", 'tag', 'sq_attribute');
     $lexer->addPattern("\\\\'", 'sq_attribute');
     $lexer->addExitPattern("'", 'sq_attribute');
     $lexer->mapHandler('uq_attribute', 'acceptAttributeToken');
     $lexer->addSpecialPattern('=\\s*[^>\\s]*', 'tag', 'uq_attribute');
 }
Example #3
0
 public function testModeMapping()
 {
     $handler = new MockTestParser();
     $handler->returnsByValue('a', true);
     $handler->expectAt(0, 'a', array('aa', LEXER_MATCHED));
     $handler->expectAt(1, 'a', array('(', LEXER_ENTER));
     $handler->expectAt(2, 'a', array('bb', LEXER_MATCHED));
     $handler->expectAt(3, 'a', array('a', LEXER_UNMATCHED));
     $handler->expectAt(4, 'a', array('bb', LEXER_MATCHED));
     $handler->expectAt(5, 'a', array(')', LEXER_EXIT));
     $handler->expectAt(6, 'a', array('b', LEXER_UNMATCHED));
     $handler->expectCallCount('a', 7);
     $lexer = new SimpleLexer($handler, 'mode_a');
     $lexer->addPattern('a+', 'mode_a');
     $lexer->addEntryPattern('(', 'mode_a', 'mode_b');
     $lexer->addPattern('b+', 'mode_b');
     $lexer->addExitPattern(')', 'mode_b');
     $lexer->mapHandler('mode_a', 'a');
     $lexer->mapHandler('mode_b', 'a');
     $this->assertTrue($lexer->parse('aa(bbabb)b'));
 }