railt/compiler

View on GitHub
src/Compiler/Grammar/Builder/Terminal.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
/**
 * This file is part of Railt package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
declare(strict_types=1);

namespace Railt\Component\Compiler\Grammar\Builder;

use Railt\Component\Parser\Rule\Rule;
use Railt\Component\Parser\Rule\Terminal as TerminalRule;

/**
 * Class Terminal
 */
class Terminal extends AbstractBuilder
{
    /**
     * @var bool
     */
    private $kept;

    /**
     * Terminal constructor.
     * @param $name
     * @param string $tokenName
     * @param bool $kept
     */
    public function __construct($name, string $tokenName, bool $kept = false)
    {
        $this->kept = $kept;
        parent::__construct($name, null, $tokenName);
    }

    /**
     * @return Rule
     */
    public function build(): Rule
    {
        return new TerminalRule($this->name, $this->nodeId, $this->kept);
    }
}