#!/usr/bin/env php
<?php declare(strict_types=1);

/**
 * Script that outputs debug tokens based on a list of files
 */

namespace Cucumber\Gherkin;

require __DIR__ . '/../vendor/autoload.php';

assert(is_array($argv), "Script must be run from the command line");

$options = [];

$selectedOptions = getopt('', $options, $restIndex);

assert($selectedOptions !== false, "getopt returns false only when it cannot find the argv array.");

$paths = array_slice($argv, $restIndex);

$parser = new Parser(new TokenFormatterBuilder());

foreach($paths as $path) {
    $data = file_get_contents($path);

    if ($data === false) {
        throw new \RuntimeException(\sprintf('Could not read file "%s".', $path));
    }

    $result = $parser->parse(
            $path,
            new StringTokenScanner($data),
            new TokenMatcher(),
    );
    echo $result;
}
