/**
  * To
  *
  * @param string|State  $state
  * @param string        $type
  *
  * @return $this
  */
 public function to($state, $type = State::TYPE_NORMAL)
 {
     if (!$state instanceof State) {
         $state = $this->definition->getState($state, $type);
     }
     $this->to = $state;
     return $this;
 }
Esempio n. 2
0
 /**
  * @param array $args
  *
  * @return Input|false
  */
 public function parse($args = null)
 {
     $fsm = new BacktrackingRunner($this->usageDefinition->getInitialState(), new UsageParserContext());
     $symbols = $this->getInputSequence($args);
     if (!$symbols) {
         return false;
     }
     $result = $fsm->input($symbols);
     return $result === false ? false : new Input($result, $this->optionRepository);
 }
 private function groupSequences()
 {
     if (empty($this->sequences) && empty($this->sequence)) {
         return null;
     }
     $group = new Definition('Group');
     $choices = array_merge($this->sequences, [$this->sequence]);
     foreach ($choices as $choice) {
         if (count($choice) == 0) {
             continue;
         }
         $group->getState('start')->addTransition(new ShortcutTransition($choice[0]->getState('start')));
         end($choice)->getState('end')->addTransition(new ShortcutTransition($group->getState('end')));
     }
     return $group;
 }