#!/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");

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

// first element is the script name
array_shift($argv);

foreach($argv as $fileName) {
    $input = file_get_contents($fileName);

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

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