Skip to content

Commit

Permalink
MERGE: Merge Neos.Fusion.Afx into collection
Browse files Browse the repository at this point in the history
See #2878
  • Loading branch information
kdambekalns committed Dec 4, 2020
2 parents f39591c + d600a4f commit baedca1
Show file tree
Hide file tree
Showing 23 changed files with 4,453 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Neos.Fusion.Afx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
/Packages
/composer.lock
1 change: 1 addition & 0 deletions Neos.Fusion.Afx/.styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preset: psr2
6 changes: 6 additions & 0 deletions Neos.Fusion.Afx/.travis.yml
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
43 changes: 43 additions & 0 deletions Neos.Fusion.Afx/Classes/Dsl/AfxDslImplementation.php
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()));
}
}
}
20 changes: 20 additions & 0 deletions Neos.Fusion.Afx/Classes/Exception/AfxException.php
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
{
}
22 changes: 22 additions & 0 deletions Neos.Fusion.Afx/Classes/Parser/AfxParserException.php
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
{
}
54 changes: 54 additions & 0 deletions Neos.Fusion.Afx/Classes/Parser/Expression/Comment.php
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();
}
}
}
62 changes: 62 additions & 0 deletions Neos.Fusion.Afx/Classes/Parser/Expression/Expression.php
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();
}
}
}
60 changes: 60 additions & 0 deletions Neos.Fusion.Afx/Classes/Parser/Expression/Identifier.php
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);
}
}
}
}
Loading

0 comments on commit baedca1

Please sign in to comment.