Skip to content

Commit

Permalink
parameter and bbcode simple values now allow non-conflicting syntax t…
Browse files Browse the repository at this point in the history
…okens inside
  • Loading branch information
thunderer committed Dec 9, 2018
1 parent ccf16e8 commit f1660ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
29 changes: 25 additions & 4 deletions src/Parser/RegularParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,9 @@ private function value()
return $this->match(self::TOKEN_DELIMITER, false) ? $value : false;
}

if($tmp = $this->match(self::TOKEN_STRING, false)) {
$value .= $tmp;
while($tmp = $this->match(self::TOKEN_STRING, false)) {
$value .= $tmp;
if($this->lookahead(self::TOKEN_STRING) || $this->lookahead(self::TOKEN_MARKER)) {
while(false === ($this->lookahead(self::TOKEN_WS) || $this->lookahead(self::TOKEN_CLOSE) || $this->lookaheadN(array(self::TOKEN_MARKER, self::TOKEN_CLOSE)))) {
$value .= $this->match(null, false);
}

return $value;
Expand Down Expand Up @@ -252,6 +251,28 @@ private function lookahead($type)
return $this->position < $this->tokensCount && $this->tokens[$this->position][0] === $type;
}

private function lookaheadN(array $types)
{
$count = count($types);
if($this->position + $count > $this->tokensCount) {
return false;
}

$position = $this->position;
foreach($types as $type) {
// note: automatically skips whitespace tokens
if($this->tokens[$position][0] === self::TOKEN_WS) {
$position++;
}
if($type !== $this->tokens[$position][0]) {
return false;
}
$position++;
}

return true;
}

private function match($type, $ws)
{
if($this->position >= $this->tokensCount) {
Expand Down
8 changes: 7 additions & 1 deletion tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ public function provideShortcodes()
new ParsedShortcode(new Shortcode('y', array(), ' ] [] [ [z] [/#] [/z] [ [] ] [/] ', null), '[y] ] [] [ [z] [/#] [/z] [ [] ] [/] [/y]', 27),
new ParsedShortcode(new Shortcode('z', array(), ' [ [/ [/] /] ] ', null), '[z] [ [/ [/] /] ] [/z]', 70),
)),
array($s, '[x=/[/] [y a=/"//] [z=http://url/] [a=http://url ]', array(
new ParsedShortcode(new Shortcode('x', array(), null, '/['), '[x=/[/]', 0),
new ParsedShortcode(new Shortcode('y', array('a' => '/"/'), null, null), '[y a=/"//]', 8),
new ParsedShortcode(new Shortcode('z', array(), null, 'http://url'), '[z=http://url/]', 19),
new ParsedShortcode(new Shortcode('a', array(), null, 'http://url'), '[a=http://url ]', 35),
)),
);

/**
Expand All @@ -239,7 +245,7 @@ public function provideShortcodes()
*
* Tests cases from array above with identifiers in the array below must be skipped.
*/
$wordpressSkip = array(3, 6, 16, 21, 22, 23, 25, 32, 33, 34, 46, 47, 49);
$wordpressSkip = array(3, 6, 16, 21, 22, 23, 25, 32, 33, 34, 46, 47, 49, 51);
$result = array();
foreach($tests as $key => $test) {
$syntax = array_shift($test);
Expand Down

0 comments on commit f1660ae

Please sign in to comment.