/
HandlebarsParser.php
37 lines (30 loc) · 1.01 KB
/
HandlebarsParser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Xgettext\Parser;
// http://stackoverflow.com/questions/26725207/find-every-string-between-quotes-inside-specific-curly-braces
class HandlebarsParser extends AbstractRegexParser implements ParserInterface
{
public function extractCalls($line)
{
$calls = array();
preg_match_all('`(' . implode('|', array_keys($this->keywords)) . ')(.*?["\'].*)\s*\}{2}`', $line, $matches);
foreach ($matches[1] as $index => $keyword) {
$calls[] = array(
'keyword' => $keyword,
'arguments' => $matches[2][$index],
);
}
return $calls;
}
public function extractArguments($arguments)
{
$args = array();
preg_match_all('`(["\'])(.*?)\1`', $arguments, $matches);
foreach ($matches[1] as $index => $delimiter) {
$args[] = array(
'delimiter' => $delimiter,
'arguments' => $matches[2][$index],
);
}
return $args;
}
}