1<?php
2
3declare(strict_types=1);
4
5namespace JMS\Serializer\Type;
6
7use Hoa\Exception\Exception;
8use Hoa\Visitor\Visit;
9use JMS\Serializer\Type\Exception\SyntaxError;
10
11final class Parser implements ParserInterface
12{
13    /** @var InnerParser */
14    private $parser;
15
16    /** @var Visit */
17    private $visitor;
18
19    public function __construct()
20    {
21        $this->parser = new InnerParser();
22        $this->visitor = new TypeVisitor();
23    }
24
25    public function parse(string $type): array
26    {
27        try {
28            $ast = $this->parser->parse($type, 'type');
29
30            return $this->visitor->visit($ast);
31        } catch (Exception $e) {
32            throw new SyntaxError($e->getMessage(), 0, $e);
33        }
34    }
35}
36