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")); }
/** * 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'); }
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')); }