UNPKG

2.79 kBMarkdownView Raw
1FBP flow definition language parser [![Build Status](https://travis-ci.org/noflo/fbp.png?branch=master)](https://travis-ci.org/noflo/fbp)
2===================================
3
4The *fbp* library provides a parser for the [FBP domain-specific language](https://github.com/bergie/noflo#language-for-flow-based-programming) used for defining graphs for flowbased programming environments like [NoFlo](http://noflojs.org).
5
6## Usage
7
8You can use the FBP parser in your JavaScript code with the following:
9
10```javascript
11var parser = require('fbp');
12
13// Some FBP syntax code
14var fbpData = "'hello, world!' -> IN Display(Output)";
15
16// Parse into a Graph definition JSON object
17var graphDefinition = parser.parse(fbpData);
18```
19
20After this the graph definition can be loaded into a compatible flow-based runtime environment like NoFlo.
21
22### Command-line
23
24The *fbp* package also provides a command-line tool for converting FBP files into JSON:
25
26 $ fbp somefile.fbp > somefile.json
27
28## Language for Flow-Based Programming
29
30FBP is a Domain-Specific Language (DSL) for easy graph definition. The syntax is the following:
31
32* `'somedata' -> PORT Process(Component)` sends initial data _somedata_ to port _PORT_ of process _Process_ that runs component _Component_
33* `A(Component1) X -> Y B(Component2)` sets up a connection between port _X_ of process _A_ that runs component _Component1_ and port _Y_ of process _B_ that runs component _Component2_
34
35You can connect multiple components and ports together on one line, and separate connection definitions with a newline or a comma (`,`).
36
37Components only have to be specified the first time you mention a new process. Afterwards, simply append empty parentheses (`()`) after the process name.
38
39Example:
40
41```fbp
42'somefile.txt' -> SOURCE Read(ReadFile) OUT -> IN Split(SplitStr)
43Split() OUT -> IN Count(Counter) COUNT -> IN Display(Output)
44Read() ERROR -> IN Display()
45```
46
47### Exporting ports
48
49When FBP-defined graphs are used as subgraphs in other flows, it is often desirable to give more user-friendly names to their available ports. In the FBP language this is done by `EXPORT` statements.
50
51Example:
52
53```fbp
54EXPORT=READ.IN:FILENAME
55Read(ReadFile) OUT -> IN Display(Output)
56```
57
58This line would export the *IN* port of the *Read* node as *FILENAME*.
59
60### Node metadata
61
62It is possible to append metadata to Nodes when declaring them by adding the metadata string to the Component part after a colon (`:`).
63
64Example:
65
66```fbp
67'somefile.txt' -> SOURCE Read(ReadFile:main)
68Read() OUT -> IN Split(SplitStr:main)
69Split() OUT -> IN Count(Counter:main)
70Count() COUNT -> IN Display(Output:main)
71Read() ERROR -> IN Display()
72```
73
74In this case the route leading from *Read* to *Display* through *Split* and *Count* would be identified with the string *main*.