/** * @see xfLexeme */ public function setType($type) { $lexeme = strtolower($this->getLexeme()); if ($type == self::SYNTAX) { if ($lexeme == '[') { $type = self::RANGE_START_INCLUSIVE; } elseif ($lexeme == '{') { $type = self::RANGE_START_EXCLUSIVE; } elseif ($lexeme == ']') { $type = self::RANGE_END_INCLUSIVE; } elseif ($lexeme == '}') { $type = self::RANGE_END_EXCLUSIVE; } } elseif ($type == self::WORD) { if ($lexeme == 'to') { $type = self::RANGE_SEPARATOR; } elseif ($lexeme == 'and') { $type = self::SYNTAX; } elseif ($lexeme == 'or') { $type = self::SYNTAX; } elseif ($lexeme == 'not') { $type = self::SYNTAX; } elseif (false !== strpos($lexeme, '*') || false !== strpos($lexeme, '?')) { $type = self::WILDCARD; } } parent::setType($type); }
<?php /** * This file is part of the sfSearch package. * (c) Carl Vondrick <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require dirname(__FILE__) . '/../../bootstrap/unit.php'; require 'lexer/xfLexeme.class.php'; $t = new lime_test(4, new lime_output_color()); $lexeme = new xfLexeme('lexeme', 'type', 42); $t->is($lexeme->getType(), 'type', '->getType() returns the type'); $t->is($lexeme->getLexeme(), 'lexeme', '->getLexeme() returns the lexeme'); $t->is($lexeme->getPosition(), 42, '->getPosition() returns the position'); $lexeme->setType('typer'); $t->is($lexeme->getType(), 'typer', '->setType() changes the type');