コード例 #1
0
ファイル: Builder.php プロジェクト: ftdebugger/jungle
 /**
  * @return PropertyGenerator
  */
 protected function getActionTableProperty(Table $table)
 {
     $property = new PropertyGenerator('action', [], PropertyGenerator::FLAG_PROTECTED);
     $property->setDocBlock(new DocBlockGenerator('Syntax analyse action table'));
     $property->setDefaultValue(new PropertyValueGenerator($table->getTable()));
     return $property;
 }
コード例 #2
0
ファイル: TransitionSet.php プロジェクト: ftdebugger/jungle
 /**
  * Process
  */
 public function process()
 {
     $situation = new Situation($this->table, $this->table->getStartRule());
     $this->addState($situation->closure());
     while (!$this->stateQueue->isEmpty()) {
         /** @var State $state */
         $state = $this->stateQueue->dequeue();
         foreach ($state->getSituationSet()->getNextTokens() as $next) {
             $transition = $this->addState($state->getSituationSet()->transition($next));
             $state->addTransition($next, $transition);
         }
     }
 }
コード例 #3
0
 public function testClosure()
 {
     $ruleA = new Rule('a', ['b', 'c']);
     $ruleB = new Rule('b', ['a']);
     $ruleC = new Rule('c', ['b']);
     $table = new Table();
     $table->addRule($ruleA, 'a');
     $table->addRule($ruleB, 'b');
     $table->addRule($ruleC, 'c');
     $situation = new Situation($table, $ruleA);
     $state = new SituationSet();
     $state->add($situation);
     $result = $state->closure();
     $this->assertInstanceOf('Jungle\\SLR\\SituationSet', $result);
     $this->assertCount(2, $result);
 }
コード例 #4
0
ファイル: TableTest.php プロジェクト: ftdebugger/jungle
 public function testGetReduce()
 {
     $object = new Table();
     $this->assertEquals($object->getReduce('abc'), $object->getReduce('abc'));
     $this->assertEquals($object->getReduce(' abc'), $object->getReduce('abc '));
     $this->assertNotEquals($object->getReduce('abc'), $object->getReduce('abcd'));
 }
コード例 #5
0
ファイル: ParseCommand.php プロジェクト: ftdebugger/jungle
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $reader = new Syntax\Reader();
     $schema = $reader->parseFile($input->getArgument('schema'));
     $syntax = new Syntax($schema);
     $table = new Table();
     $table->fromSyntax($syntax);
     $processorBuilder = new Processor\Builder();
     $class = $processorBuilder->build($syntax, $table);
     if ($input->getOption('class')) {
         $class->setName($input->getOption('class'));
     }
     $content = '<?php' . PHP_EOL . PHP_EOL . $class->generate();
     if ($input->getOption('output')) {
         file_put_contents($input->getOption('output'), $content);
     } else {
         echo $content;
     }
 }