-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MERGE: Merge Neos.Fusion.Afx into collection
See #2878
- Loading branch information
Showing
23 changed files
with
4,453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor | ||
/Packages | ||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
preset: psr2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: php | ||
php: | ||
- '7.2' | ||
- '7.3' | ||
- '7.4' | ||
script: composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
namespace Neos\Fusion\Afx\Dsl; | ||
|
||
/* | ||
* This file is part of the Neos.Fusion.Afx package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Fusion; | ||
use Neos\Fusion\Core\DslInterface; | ||
use Neos\Fusion\Afx\Service\AfxService; | ||
use Neos\Fusion\Afx\Exception\AfxException; | ||
|
||
/** | ||
* Class Fusion AFX Dsl | ||
* | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class AfxDslImplementation implements DslInterface | ||
{ | ||
|
||
/** | ||
* Transpile the given dsl-code to fusion-code | ||
* | ||
* @param string $code | ||
* @return string | ||
* @throws Fusion\Exception | ||
*/ | ||
public function transpile($code) | ||
{ | ||
try { | ||
return AfxService::convertAfxToFusion($code); | ||
} catch (AfxException $afxException) { | ||
throw new Fusion\Exception(sprintf('Error during AFX-parsing: %s', $afxException->getMessage())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace Neos\Fusion\Afx\Exception; | ||
|
||
/* | ||
* This file is part of the Neos.Fusion.Afx package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
/** | ||
* Class AfxException | ||
* @package Neos\Fusion\Afx\Exception | ||
*/ | ||
class AfxException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Fusion\Afx\Parser; | ||
|
||
/* | ||
* This file is part of the Neos.Fusion.Afx package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
/** | ||
* Class AfxParserException | ||
* @package Neos\Fusion\Afx\Parser | ||
*/ | ||
class AfxParserException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Fusion\Afx\Parser\Expression; | ||
|
||
/* | ||
* This file is part of the Neos.Fusion.Afx package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Fusion\Afx\Parser\AfxParserException; | ||
use Neos\Fusion\Afx\Parser\Lexer; | ||
|
||
/** | ||
* Class Expression | ||
* @package Neos\Fusion\Afx\Parser\Expression | ||
*/ | ||
class Comment | ||
{ | ||
/** | ||
* @param Lexer $lexer | ||
* @return string | ||
* @throws AfxParserException | ||
*/ | ||
public static function parse(Lexer $lexer) | ||
{ | ||
if ($lexer->isOpeningBracket() && $lexer->peek(4) === '<!--') { | ||
$lexer->consume(); | ||
$lexer->consume(); | ||
$lexer->consume(); | ||
$lexer->consume(); | ||
} else { | ||
throw new AfxParserException(sprintf('Unexpected comment start')); | ||
} | ||
$currentComment = ''; | ||
while (true) { | ||
if ($lexer->isMinus() && $lexer->peek(3) === '-->') { | ||
$lexer->consume(); | ||
$lexer->consume(); | ||
$lexer->consume(); | ||
return $currentComment; | ||
} | ||
if ($lexer->isEnd()) { | ||
throw new AfxParserException(sprintf('Comment not closed.')); | ||
} | ||
$currentComment .= $lexer->consume(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Fusion\Afx\Parser\Expression; | ||
|
||
/* | ||
* This file is part of the Neos.Fusion.Afx package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Fusion\Afx\Parser\AfxParserException; | ||
use Neos\Fusion\Afx\Parser\Lexer; | ||
|
||
/** | ||
* Class Expression | ||
* @package Neos\Fusion\Afx\Parser\Expression | ||
*/ | ||
class Expression | ||
{ | ||
/** | ||
* @param Lexer $lexer | ||
* @return string | ||
* @throws AfxParserException | ||
*/ | ||
public static function parse(Lexer $lexer): string | ||
{ | ||
$contents = ''; | ||
$braceCount = 0; | ||
|
||
if ($lexer->isOpeningBrace()) { | ||
$lexer->consume(); | ||
} else { | ||
throw new AfxParserException('Expression without braces', 1557860467); | ||
} | ||
|
||
while (true) { | ||
if ($lexer->isEnd()) { | ||
throw new AfxParserException(sprintf('Unfinished Expression "%s"', $contents), 1557860496); | ||
} | ||
|
||
if ($lexer->isOpeningBrace()) { | ||
$braceCount++; | ||
} | ||
|
||
if ($lexer->isClosingBrace()) { | ||
if ($braceCount === 0) { | ||
$lexer->consume(); | ||
return $contents; | ||
} | ||
|
||
$braceCount--; | ||
} | ||
|
||
$contents .= $lexer->consume(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Fusion\Afx\Parser\Expression; | ||
|
||
/* | ||
* This file is part of the Neos.Fusion.Afx package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Fusion\Afx\Parser\AfxParserException; | ||
use Neos\Fusion\Afx\Parser\Lexer; | ||
|
||
/** | ||
* Class Identifier | ||
* @package Neos\Fusion\Afx\Parser\Expression | ||
*/ | ||
class Identifier | ||
{ | ||
/** | ||
* @param Lexer $lexer | ||
* @return string | ||
* @throws AfxParserException | ||
*/ | ||
public static function parse(Lexer $lexer): string | ||
{ | ||
$identifier = ''; | ||
|
||
while (true) { | ||
switch (true) { | ||
case $lexer->isAlphaNumeric(): | ||
case $lexer->isDot(): | ||
case $lexer->isColon(): | ||
case $lexer->isMinus(): | ||
case $lexer->isUnderscore(): | ||
case $lexer->isAt(): | ||
$identifier .= $lexer->consume(); | ||
break; | ||
case $lexer->isEqualSign(): | ||
case $lexer->isWhiteSpace(): | ||
case $lexer->isClosingBracket(): | ||
case $lexer->isForwardSlash(): | ||
return $identifier; | ||
break; | ||
default: | ||
$unexpected_character = $lexer->consume(); | ||
throw new AfxParserException(sprintf( | ||
'Unexpected character "%s" in identifier "%s"', | ||
$unexpected_character, | ||
$identifier | ||
), 1557860650); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.