addSpecialPattern() public method

Acts as an entry and exit pattern in one go, effectively calling a special parser handler for this token only.
public addSpecialPattern ( string $pattern, string $mode, string $special )
$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.
$special string Use this mode for this one token.
コード例 #1
0
 function testSingular()
 {
     $handler = new MockTestParser();
     $handler->setReturnValue("a", true);
     $handler->setReturnValue("b", true);
     $handler->expectAt(0, "a", array("aa", LEXER_MATCHED));
     $handler->expectAt(1, "a", array("aa", LEXER_MATCHED));
     $handler->expectAt(2, "a", array("xx", LEXER_UNMATCHED));
     $handler->expectAt(3, "a", array("xx", LEXER_UNMATCHED));
     $handler->expectAt(0, "b", array("b", LEXER_SPECIAL));
     $handler->expectAt(1, "b", array("bbb", LEXER_SPECIAL));
     $handler->expectCallCount("a", 4);
     $handler->expectCallCount("b", 2);
     $lexer = new SimpleLexer($handler, "a");
     $lexer->addPattern("a+", "a");
     $lexer->addSpecialPattern("b+", "a", "b");
     $this->assertTrue($lexer->parse("aabaaxxbbbxx"));
 }
コード例 #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');
 }
コード例 #3
0
 public function testSingular()
 {
     $handler = new MockTestParser();
     $handler->returnsByValue('a', true);
     $handler->returnsByValue('b', true);
     $handler->expectAt(0, 'a', array('aa', LEXER_MATCHED));
     $handler->expectAt(1, 'a', array('aa', LEXER_MATCHED));
     $handler->expectAt(2, 'a', array('xx', LEXER_UNMATCHED));
     $handler->expectAt(3, 'a', array('xx', LEXER_UNMATCHED));
     $handler->expectAt(0, 'b', array('b', LEXER_SPECIAL));
     $handler->expectAt(1, 'b', array('bbb', LEXER_SPECIAL));
     $handler->expectCallCount('a', 4);
     $handler->expectCallCount('b', 2);
     $lexer = new SimpleLexer($handler, 'a');
     $lexer->addPattern('a+', 'a');
     $lexer->addSpecialPattern('b+', 'a', 'b');
     $this->assertTrue($lexer->parse('aabaaxxbbbxx'));
 }