/**
  * Processes the query.
  *
  * @param array $lexemes The lexemes
  * @returns xfCriterion
  */
 private function process(array $lexemes)
 {
     if (count($lexemes) == 0) {
         return new xfCriterionEmpty();
     }
     $this->builder = new xfCriterionBuilder($lexemes);
     $this->setupFiniteStateMachine();
     while ($lexeme = $this->builder->next()) {
         $this->fsm->process($lexeme->getType());
     }
     if ($this->fsm->getState() != self::ST_QUERY) {
         throw new xfParserException('Unexpected end of query.');
     }
     return $this->builder->getMaster();
 }
 /**
  * Creates the lexemes.
  */
 private function process()
 {
     while (false !== ($char = $this->builder->next())) {
         $this->fsm->process($this->translateCharacter($char));
     }
     $this->fsm->process(self::IN_WHITE);
     if ($this->fsm->getState() !== self::ST_WHITE) {
         throw new xfParserException('Unexpected end of query.');
     }
 }
}
$t->diag('->setState()');
$fsm->setState('on');
$t->is($fsm->getState(), 'on', '->setState() changes the state');
$fsm->setState(null);
$t->is($fsm->getState(), 'off', '->setState() to null sets the initial state');
try {
    $msg = '->setState() fails if the state does not exist.';
    $fsm->setState('exploded');
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}
$t->diag('->process()');
$t->is($fsm->getState(), 'off', '->getState() returns the inital state');
$t->is($fsm->process('push')->getState(), 'on', '->process() changes the state according to the transitions');
$t->is($fsm->process('smash')->getState(), 'broken', '->process() changes the state according to the transitions');
$t->is($fsm->processMany(array('replace', 'push', 'short out'))->getState(), 'burned out', '->processMany() processes multiple states');
try {
    $msg = '->process() fails when there is no transition defined for an input';
    $fsm->process('twist');
    $t->fail($msg);
} catch (Exception $e) {
    $t->pass($msg);
}
$fsm->setDefaultTransition('broken');
$t->is($fsm->process('twist')->getState(), 'broken', '->process() uses the default transition if possible');
$fsm->setDefaultTransition(null);
$fsm->reset();
$t->is($fsm->getState(), 'off', '->reset() resets the state');
$t->diag('exit actions');