Skip to content
This repository was archived by the owner on Oct 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #14 from PackageFactory/task/useFusionDslExtension…
Browse files Browse the repository at this point in the history
…Point

FEATURE: Use fusions new dsl-extension-point instead of aspecting the parser
  • Loading branch information
mficzel authored Jul 17, 2017
2 parents 1e98802 + 92ed957 commit 1316a2e
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 233 deletions.
46 changes: 0 additions & 46 deletions Classes/Aspects/FusionParserAspect.php

This file was deleted.

143 changes: 0 additions & 143 deletions Classes/Command/AfxCommandController.php

This file was deleted.

33 changes: 33 additions & 0 deletions Classes/Dsl/AfxDslImplementation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace PackageFactory\AtomicFusion\AFX\Dsl;

use Neos\Flow\Annotations as Flow;
use Neos\Fusion;
use Neos\Fusion\Core\DslInterface;
use PackageFactory\AtomicFusion\AFX\Service\AfxService;
use PackageFactory\AtomicFusion\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 FusionException(sprintf('Error during AFX-parsing: %s', $afxException->getMessage()));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

namespace PackageFactory\AtomicFusion\AFX\Exception;

class Exception extends \Exception
class AfxException extends \Exception
{

}
17 changes: 0 additions & 17 deletions Classes/Package.php

This file was deleted.

25 changes: 9 additions & 16 deletions Classes/Service/AfxService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
use Neos\Flow\Annotations as Flow;
use Neos\Utility\Arrays;
use PackageFactory\Afx\Parser as AfxParser;
use PackageFactory\Afx\Exception as AfxException;
use Neos\Fusion\Exception as FusionException;

use PackageFactory\AtomicFusion\AFX\Exception\Exception;
use PackageFactory\AtomicFusion\AFX\Exception\AfxException;

/**
* Class AfxService
* @package PackageFactory\AtomicFusion\AFX\Service
*
* @Flow\Scope("singleton")
*/
class AfxService
Expand All @@ -26,14 +23,10 @@ class AfxService
*/
public static function convertAfxToFusion($afxCode, $indentation = '')
{
try {
$parser = new AfxParser(trim($afxCode));
$ast = $parser->parse();
$fusion = self::astNodeListToFusion($ast, $indentation);
return $fusion;
} catch (AfxException $afxException) {
throw new FusionException(sprintf('Error during AFX-parsing: %s', $afxException->getMessage()));
}
$parser = new AfxParser(trim($afxCode));
$ast = $parser->parse();
$fusion = self::astNodeListToFusion($ast, $indentation);
return $fusion;
}

/**
Expand All @@ -60,7 +53,7 @@ protected static function astToFusion($ast, $indentation = '')
return self::astNodeToFusion($ast['payload'], $indentation);
break;
default:
throw new Exception(sprintf('ast type %s is unkonwn', $ast['type']));
throw new AfxException(sprintf('ast type %s is unkonwn', $ast['type']));
}
}

Expand Down Expand Up @@ -157,7 +150,7 @@ protected static function astNodeToFusion($payload, $indentation = '')
if ($childrenProp['type'] == 'string') {
$childrenPropertyName = $childrenProp['payload'];
} else {
throw new Exception(
throw new AfxException(
sprintf('@children only supports string payloads %s found', $childrenProp['type'])
);
}
Expand Down Expand Up @@ -214,7 +207,7 @@ protected static function astNodeListToFusion($payload, $indentation = '')
if ($keyProperty['type'] == 'string') {
$fusionName = $keyProperty['payload'];
} else {
throw new Exception(
throw new AfxException(
sprintf(
'@key only supports string payloads %s was given',
$astNode['props']['@key']['type']
Expand Down
4 changes: 4 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Neos:
Fusion:
dsl:
afx: PackageFactory\AtomicFusion\AFX\Dsl\AfxDslImplementation
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ prototypes because the generated fusion-code can be overwritten and controlled f

## Installation

PackageFactory.AtomicFusion.AFX is available via packagist. Just add `"packagefactory/atomicfusion-afx" : "~2.0.0"`
PackageFactory.AtomicFusion.AFX is available via packagist. Just add `"packagefactory/atomicfusion-afx" : "~3.0.0"`
to the require-section of the composer.json or run `composer require packagefactory/atomicfusion-afx`.

__We use semantic-versioning so every breaking change will increase the major-version number.__
Expand Down Expand Up @@ -69,13 +69,6 @@ prototype(PackageFactory.AtomicFusion.AFX:Example) < prototype(PackageFactory.At
}
```

## CLI - Usage

The package contains the following cli-commands.

1. `./flow afx:show` - Show the afx detection and expansion to pure fusion, this is useful for learning and understanding.
2. `./flow afx:eject` - Expand afx in fusion code to pure fusion, this is usefull before removing the afx package.

## AFX Language Rules

All whitepaces around the outer elements are ignored. Whitepaces that are connected to a newline are considered irrelevant and are ignored.
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
"name": "Martin Ficzel",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "Wilhelm Behncke",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"neos/fusion": "^3.0.1 || dev-master",
"neos/fusion": "^3.2.0 || dev-master",
"packagefactory/afx": "~2.0.1"
},
"autoload": {
Expand Down

0 comments on commit 1316a2e

Please sign in to comment.