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.
Example #1
0
 /**
  *    Sets up the lexer with case insensitive matching
  *    and adds the HTML handlers.
  *    @param SimpleSaxParser $parser  Handling strategy by
  *                                    reference.
  *    @access public
  */
 function __construct($parser, $tags = null)
 {
     if (is_array($tags)) {
         $this->parsedTags = $tags;
     }
     parent::__construct($parser, 'text');
     $this->mapHandler('text', 'acceptTextToken');
     $this->addSkipping();
     foreach ($this->getParsedTags() as $tag) {
         $this->addTag($tag);
     }
     $this->addInTagTokens();
 }
Example #2
0
 /**
  *    Sets up the lexer with case insensitive matching
  *    and adds the HTML handlers.
  *    @param SimpleSaxParser $parser  Handling strategy by
  *                                    reference.
  *    @access public
  */
 function __construct($parser)
 {
     parent::__construct($parser, 'text');
     $this->mapHandler('text', 'acceptTextToken');
     $this->addSkipping();
     foreach ($this->getParsedTags() as $tag) {
         $this->addTag($tag);
     }
     $this->addInTagTokens();
 }
Example #3
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 #4
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 #5
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'));
 }