Skip to content

Commit

Permalink
Merge pull request #8 from mficzel/feature/returnNodeListInsteadOfSin…
Browse files Browse the repository at this point in the history
…gleNode

feat: Parser returns nodeList instead of singleNode

The parser now returns a nodeList instead of a single node as result.
This enables the parsing of multiple elements that are not encapsulated in a container.
  • Loading branch information
mficzel authored May 30, 2017
2 parents 3747404 + e145094 commit 930e052
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 161 deletions.
2 changes: 1 addition & 1 deletion src/Expression/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function parse(Lexer $lexer)
throw new Exception(sprintf('Tag "%s" did not end with closing bracket.', $identifier));
}

$children = Children::parse($lexer);
$children = NodeList::parse($lexer);

if ($lexer->isOpeningBracket()) {
$lexer->consume();
Expand Down
16 changes: 9 additions & 7 deletions src/Expression/Children.php → src/Expression/NodeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
use PackageFactory\Afx\Exception;
use PackageFactory\Afx\Lexer;

class Children
class NodeList
{
public static function parse(Lexer $lexer)
{
$contents = [];
$currentText = '';
while (true) {
if ($lexer->isEnd()) {
throw new Exception('Unfinished child-list');
}
while (!$lexer->isEnd()) {

if ($lexer->isOpeningBracket()) {
$lexer->consume();
Expand Down Expand Up @@ -61,11 +58,16 @@ public static function parse(Lexer $lexer)
continue;
}



$currentText .= $lexer->consume();
}

if ($lexer->isEnd() && $currentText) {
$contents[] = [
'type' => 'text',
'payload' => $currentText
];
}

return $contents;
}
}
2 changes: 1 addition & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public function __construct($string)

public function parse()
{
return Expression\Node::parse($this->lexer);
return Expression\NodeList::parse($this->lexer);
}
}
Loading

0 comments on commit 930e052

Please sign in to comment.