Skip to content

Commit 9351dfa

Browse files
committed
WIP standard / aggressive value matching modes
1 parent f1660ae commit 9351dfa

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Parser/RegularParser.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ final class RegularParser implements ParserInterface
2929
const TOKEN_STRING = 6;
3030
const TOKEN_WS = 7;
3131

32+
const VALUE_REGULAR = 0x01;
33+
const VALUE_AGGRESSIVE = 0x02;
34+
35+
public $valueMode = self::VALUE_REGULAR;
36+
3237
public function __construct(SyntaxInterface $syntax = null)
3338
{
3439
$this->lexerRegex = $this->prepareLexer($syntax ?: new CommonSyntax());
@@ -201,7 +206,16 @@ private function value()
201206
}
202207

203208
if($this->lookahead(self::TOKEN_STRING) || $this->lookahead(self::TOKEN_MARKER)) {
204-
while(false === ($this->lookahead(self::TOKEN_WS) || $this->lookahead(self::TOKEN_CLOSE) || $this->lookaheadN(array(self::TOKEN_MARKER, self::TOKEN_CLOSE)))) {
209+
while(true) {
210+
if($this->lookahead(self::TOKEN_WS) || $this->lookahead(self::TOKEN_CLOSE)) {
211+
break;
212+
}
213+
if($this->lookaheadN(array(self::TOKEN_MARKER, self::TOKEN_CLOSE))) {
214+
if($this->valueMode === self::VALUE_AGGRESSIVE) {
215+
$value .= $this->match(null, false);
216+
}
217+
break;
218+
}
205219
$value .= $this->match(null, false);
206220
}
207221

tests/ParserTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,30 @@ public function provideShortcodes()
260260
return $result;
261261
}
262262

263+
public function testValueModeAggressive()
264+
{
265+
$parser = new RegularParser(new CommonSyntax());
266+
$parser->valueMode = RegularParser::VALUE_AGGRESSIVE;
267+
$parsed = $parser->parse('[x=/[/] [y a=/"//] [z=http://url/] [a=http://url ]');
268+
$tested = array(
269+
new ParsedShortcode(new Shortcode('x', array(), null, '/[/'), '[x=/[/]', 0),
270+
new ParsedShortcode(new Shortcode('y', array('a' => '/"//'), null, null), '[y a=/"//]', 8),
271+
new ParsedShortcode(new Shortcode('z', array(), null, 'http://url/'), '[z=http://url/]', 19),
272+
new ParsedShortcode(new Shortcode('a', array(), null, 'http://url'), '[a=http://url ]', 35),
273+
);
274+
275+
$count = count($tested);
276+
static::assertCount($count, $parsed, 'counts');
277+
for ($i = 0; $i < $count; $i++) {
278+
static::assertSame($tested[$i]->getName(), $parsed[$i]->getName(), 'name');
279+
static::assertSame($tested[$i]->getParameters(), $parsed[$i]->getParameters(), 'parameters');
280+
static::assertSame($tested[$i]->getContent(), $parsed[$i]->getContent(), 'content');
281+
static::assertSame($tested[$i]->getText(), $parsed[$i]->getText(), 'text');
282+
static::assertSame($tested[$i]->getOffset(), $parsed[$i]->getOffset(), 'offset');
283+
static::assertSame($tested[$i]->getBbCode(), $parsed[$i]->getBbCode(), 'bbCode');
284+
}
285+
}
286+
263287
public function testWordPress()
264288
{
265289
$parser = new WordpressParser();

0 commit comments

Comments
 (0)