protected function execute(InputInterface $input, OutputInterface $output) { $file = 'test.elph'; if ($input->getOption('file')) { $file = $input->getOption('file'); } $raw = $input->getArgument('raw'); if ($raw) { $content = $raw; } else { $content = file_get_contents(dirname(dirname(dirname(dirname(__FILE__)))) . '/tests/test.elph'); } $output->writeln("<fg=green>Input value:\t" . $content . "</fg=green>"); try { $lexer = new Lexer(); $parser = new Parser($lexer); if ($input->getOption('debug')) { Parser::Trace(fopen('php://output', 'w'), 'Trace: '); } $lexer->tokenizeAll($content); foreach ($lexer->tokens as $token) { //$output->writeln("Parsing {$token->symbol} Token {$token->value}"); $parser->parse($token); } $parser->parse(null); } catch (\Exception $e) { $output->writeln($e->getMessage()); $lexer->debugPrintReport(); } $output->writeln(''); $output->writeln("<fg=green>Output value:\t" . $parser->retvalue . "</fg=green>"); }
public function rewrite($content) { $lexer = new Lexer(); $parser = new Parser($lexer); $lexer->tokenizeAll($content); foreach ($lexer->tokens as $token) { $parser->parse($token); } $parser->parse(null); return $parser->retvalue; }