Skip to content

Commit

Permalink
add PEG macro flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
marcioAlmada committed Feb 27, 2017
1 parent 83ec752 commit d20c1fc
Show file tree
Hide file tree
Showing 13 changed files with 612 additions and 37 deletions.
8 changes: 6 additions & 2 deletions src/Ast.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ function isEmpty() : bool {
return !\count($this->ast) || null === $this->ast;
}

function as(/*string|null*/ $label = null) : self {
if (null !== $label && null === $this->label) $this->label = $label;
function as(string $label = null) : self {
if (null !== $label) $this->label = $label;

return $this;
}

function label() {
return $this->label;
}

function withParent(self $parent) : self {
$this->parent = $parent;

Expand Down
9 changes: 8 additions & 1 deletion src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ function __construct() {
->onCommit(function(Ast $macroAst) {
$scope = Map::fromEmpty();
$tags = Map::fromValues(array_map('strval', $macroAst->{'tags'}));
$pattern = new Pattern($macroAst->{'declaration'}->line(), $macroAst->{'body pattern'}, $tags, $scope);

if ($tags->contains('·grammar')) {
$pattern = new GrammarPattern($macroAst->{'declaration'}->line(), $macroAst->{'body pattern'}, $tags, $scope);
}
else {
$pattern = new Pattern($macroAst->{'declaration'}->line(), $macroAst->{'body pattern'}, $tags, $scope);
}

$expansion = new Expansion($macroAst->{'body expansion'}, $tags, $scope);
$macro = new Macro($tags, $pattern, $expansion);

Expand Down
8 changes: 0 additions & 8 deletions src/Expansion.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@

class Expansion extends MacroMember {

const
PRETTY_PRINT =
JSON_PRETTY_PRINT
| JSON_BIGINT_AS_STRING
| JSON_UNESCAPED_UNICODE
| JSON_UNESCAPED_SLASHES
;

const
E_BAD_EXPANSION = "Bad macro expansion identifier '%s' on line %d.",
E_BAD_EXPANDER = "Bad macro expander '%s' on line %d.",
Expand Down
Loading

0 comments on commit d20c1fc

Please sign in to comment.