finished default parser
This commit is contained in:
53
src/Domain/Modules/Interpreter/Lexicon/EndOfTune.php
Normal file
53
src/Domain/Modules/Interpreter/Lexicon/EndOfTune.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace XaiCorp\AbcParser\Domain\Modules\Interpreter\Lexicon;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\UnsignedIntegerAtom;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Builder;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
|
||||
|
||||
class EndOfTune implements Lex
|
||||
{
|
||||
use LineKeyDataTrait;
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
public function __construct(Builder $builder)
|
||||
{
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
* @throws \Enzyme\Axiom\Exceptions\AtomException
|
||||
*/
|
||||
public function handle(Context $context, \Closure $next)
|
||||
{
|
||||
$line = $context->current();
|
||||
// list($key, $data) = $this->getKeyDataFromLine($line);
|
||||
|
||||
if ($this->isEndOfFile($context) || $this->isEndOfMusic($context, $line)) {
|
||||
$this->builder->handleEndOfMusic();
|
||||
}
|
||||
|
||||
return $next($context);
|
||||
}
|
||||
|
||||
protected function isEndOfFile(Context $context)
|
||||
{
|
||||
$key = $context->key();
|
||||
return $context->count() <= $key+1;
|
||||
}
|
||||
|
||||
private function isEndOfMusic(Context $context, string $line)
|
||||
{
|
||||
return $context->isState(Context::MODE_TUNE_BODY)
|
||||
&& preg_match('/^\s*$/', $line);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user