finished default parser

This commit is contained in:
2018-04-24 21:11:23 -04:00
parent 8a1c752045
commit 3817394951
39 changed files with 3725 additions and 328 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace XaiCorp\AbcParser\Application\UseCases;
use Enzyme\Axiom\Atoms\StringAtom;
use XaiCorp\AbcParser\Domain\Core\TuneCollection;
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Builder;
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
use XaiCorp\AbcParser\Domain\Modules\Interpreter\DefaultInterpreter;
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Interpreter;
class ImportAbcFile
{
/**
* @var Builder
*/
protected $builderTemplate;
/**
* @param Builder|null $builderTemplate
*/
public function __construct(Builder $builderTemplate = null)
{
$this->builderTemplate = $builderTemplate ?: new Builder();
}
/**
* @param string $abc
* @return TuneCollection
* @throws \Enzyme\Axiom\Exceptions\AtomException
*/
public function import(string $abc) : TuneCollection
{
$context = new Context(new StringAtom($abc));
$parser = $this->getBestParser($context);
$result = $parser->execute($context);
return $result;
}
/**
* @param Context $context
* @return Interpreter
*/
public function getBestParser(Context $context) : Interpreter
{
$builder = clone $this->builderTemplate;
switch($context->getVersion()) {
default:
$interpreter = new DefaultInterpreter($builder);
}
return $interpreter;
}
}