Skip to content

Commit a1b42ee

Browse files
author
Marc Aschmann
committed
Add more explanations concerning FBP DSL to README, fix tests
1 parent 3611076 commit a1b42ee

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

README.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# phpflo-fbp: load, parse, dump
2-
Flowbased programming protocol (fbp) config file loader
2+
Flowbased programming protocol (FBP) config file loader, using the FBP domain specific language (DSL).
33

44
[![Build Status](https://travis-ci.org/phpflo/phpflo-fbp.svg?branch=master)](https://travis-ci.org/phpflo)
55
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phpflo/phpflo-fbp/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phpflo/phpflo-fbp/?branch=master)
@@ -9,36 +9,36 @@ Flowbased programming protocol (fbp) config file loader
99

1010
## Introduction
1111

12-
This library allows you to load and parse configuration for your phpflo project. It also works standalone if you want to convert your old json configs to fbp spec.
13-
Supported config formats are json (.json), yaml (.yml) and fbp (.fbp), output is an object of type FbpDefinition. This allows you to output your parsed content in different formats, ranging from array over fbp, json to yaml.
12+
This library allows you to load and parse configuration for your phpflo project. It also works standalone if you want to convert your old JSON configs to FBP spec.
13+
Supported config formats are JSON (.json), YAML (.yml) and FBP (.fbp), output is an object of type FbpDefinition. This allows you to output your parsed content in different formats, ranging from array over FBP, JSON to YAML.
1414

1515
## Code Samples
1616

1717
Basic usage:
1818
```php
19-
// load fbp config
20-
$defintiion = \PhpFlo\Loader\Loader::load('my/fbp/config/file.fbp');
19+
// load FBP config
20+
$defintiion = PhpFlo\Loader\Loader::load('my/fbp/config/file.fbp');
2121
```
22-
You can load json, yml and fbp that way.
22+
You can load JSON, YAML and FBP that way.
2323

2424
Parser by itself:
2525
```php
2626
$myFbpConfig = <<<EOF
2727
'test.file' -> IN ReadFile(ReadFile)
2828
ReadFile(ReadFile) OUT -> IN SplitbyLines(SplitStr)
29-
ReadFile ERROR -> IN Display(Output)
30-
SplitbyLines OUT -> IN CountLines(Counter)
31-
CountLines COUNT -> IN Display
29+
ReadFile() ERROR -> IN Display(Output)
30+
SplitbyLines() OUT -> IN CountLines(Counter)
31+
CountLines() COUNT -> IN Display()
3232
EOF;
3333

34-
$parser = new \PhpFlo\Fbp\FbpParser();
34+
$parser = new PhpFlo\Fbp\FbpParser();
3535
$definition = $parser->run($myFbpConfig);
3636
```
3737
Dump your flow to a format:
3838
```php
39-
$json = \PhpFlo\Fbp\FbpDumper::toJson($definition);
40-
$yaml = \PhpFlo\Fbp\FbpDumper::toYaml($definition);
41-
$fbp = \PhpFlo\Fbp\FbpDumper::toFbp($definition);
39+
$json = PhpFlo\Fbp\FbpDumper::toJson($definition);
40+
$yaml = PhpFlo\Fbp\FbpDumper::toYaml($definition);
41+
$fbp = PhpFlo\Fbp\FbpDumper::toFbp($definition);
4242
```
4343

4444
The definition has following schema:
@@ -76,6 +76,41 @@ $schema = [
7676
],
7777
]
7878
```
79+
### FBP DSL defintions
80+
81+
If you want to write definition files, here are the rules:
82+
83+
*General syntax*:
84+
```
85+
// <process_alias>(<optional_process_name>) <port><[optional_port_number]> -> <port><[optional_port_number]> <process_alias>(<optional_process_name>)
86+
// examples
87+
ReadFile(ReadFile) OUT -> IN SplitbyLines(SplitStr)
88+
ReadFile() OUT -> IN SplitbyLines()
89+
ReadFile() out[1] -> In[3] SplitbyLines()
90+
```
91+
* All elements are _case sensitive_
92+
* The parentheses at the end of a process definition are mandatory (even if empty): ```<process>()```
93+
* Process names are w+
94+
* Port names can be [a-zA-Z_]
95+
* Each line determines a new chain of events, meaning at least two processes with two connecting ports, separated by a " -> " like ```<process>() <port> -> <port> <process>()```
96+
* Otherwise there is a ```<initializer> -> <port> <process>()```
97+
98+
For better understanding, the whole RegEx used for definition examination is:
99+
```
100+
((?P<inport>[a-zA-Z_]+(\[(?P<inport_no>[0-9]+)\])?)\s)?((?P<process>[\w\/]+)(\((?P<component>[\w\/\\\.]+)?\))?)(\s(?P<outport>[a-zA-Z_]+(\[(?P<outport_no>[0-9]+)\])?))?
101+
```
102+
103+
*Initializer:*
104+
You can have initial values for a graph:
105+
```
106+
'test.file' -> IN ReadFile()
107+
```
108+
109+
*Multiple definitions*:
110+
You can have a complete chain of definitions in one line to enhance visibility of a chain of events:
111+
```
112+
GreetUser() DATA -> OPTIONS Render() OUT -> STRING WriteResponse()
113+
```
79114

80115
## Installation
81116

tests/PhpFlo/Fbp/FbpParserTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public function testSimpleSingleDef()
2020

2121
$file = <<<EOF
2222
ReadFile(ReadFile) OUT -> IN SplitbyLines(SplitStr)
23-
ReadFile ERROR -> IN Display(Output)
24-
SplitbyLines OUT -> IN CountLines(Counter)
25-
CountLines COUNT -> IN Display
23+
ReadFile() ERROR -> IN Display(Output)
24+
SplitbyLines() OUT -> IN CountLines(Counter)
25+
CountLines() COUNT -> IN Display()
2626
EOF;
2727

2828
$expected = [
@@ -295,9 +295,9 @@ public function testSingleDefWithInitializer()
295295
$file = <<<EOF
296296
'yadda' -> IN ReadFile(ReadFile)
297297
ReadFile(ReadFile) OUT -> IN SplitbyLines(SplitStr)
298-
ReadFile ERROR -> IN Display(Output)
299-
SplitbyLines OUT -> IN CountLines(Counter)
300-
CountLines COUNT -> IN Display
298+
ReadFile() ERROR -> IN Display(Output)
299+
SplitbyLines() OUT -> IN CountLines(Counter)
300+
CountLines() COUNT -> IN Display()
301301
EOF;
302302

303303
$expected = [

0 commit comments

Comments
 (0)