1 | <?php |
||
13 | final class RegexParser implements ParserInterface |
||
14 | { |
||
15 | /** @var SyntaxInterface */ |
||
16 | private $syntax; |
||
17 | private $shortcodeRegex; |
||
18 | private $singleShortcodeRegex; |
||
19 | private $parametersRegex; |
||
20 | |||
21 | 61 | public function __construct(SyntaxInterface $syntax = null) |
|
28 | |||
29 | /** |
||
30 | * @param string $text |
||
31 | * |
||
32 | * @return ParsedShortcode[] |
||
33 | */ |
||
34 | 102 | public function parse($text) |
|
47 | |||
48 | 93 | private function parseSingle($text, $offset) |
|
49 | { |
||
50 | 93 | preg_match($this->singleShortcodeRegex, $text, $matches, PREG_OFFSET_CAPTURE); |
|
51 | |||
52 | 93 | $name = $matches['name'][0]; |
|
53 | 93 | $parameters = isset($matches['parameters'][0]) ? $this->parseParameters($matches['parameters'][0]) : array(); |
|
54 | 93 | $bbCode = isset($matches['bbCode'][0]) && $matches['bbCode'][1] !== -1 |
|
55 | 93 | ? $this->extractValue($matches['bbCode'][0]) |
|
56 | 93 | : null; |
|
57 | 93 | $content = isset($matches['content'][0]) && $matches['content'][1] !== -1 ? $matches['content'][0] : null; |
|
58 | |||
59 | 93 | return new ParsedShortcode(new Shortcode($name, $parameters, $content, $bbCode), $text, $offset); |
|
60 | } |
||
61 | |||
62 | 93 | private function parseParameters($text) |
|
75 | |||
76 | 35 | private function parseValue($value) |
|
80 | |||
81 | 39 | private function extractValue($value) |
|
87 | |||
88 | 39 | private function isDelimitedValue($value) |
|
93 | } |
||
94 |