1 | FBP flow definition language parser [![Build Status](https://travis-ci.org/noflo/fbp.png?branch=master)](https://travis-ci.org/noflo/fbp)
|
2 | ===================================
|
3 |
|
4 | The *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 |
|
8 | You can use the FBP parser in your JavaScript code with the following:
|
9 |
|
10 | ```javascript
|
11 | var parser = require('fbp');
|
12 |
|
13 | // Some FBP syntax code
|
14 | var fbpData = "'hello, world!' -> IN Display(Output)";
|
15 |
|
16 | // Parse into a Graph definition JSON object
|
17 | var graphDefinition = parser.parse(fbpData);
|
18 | ```
|
19 |
|
20 | After this the graph definition can be loaded into a compatible flow-based runtime environment like NoFlo.
|
21 |
|
22 | ### Command-line
|
23 |
|
24 | The *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 |
|
30 | FBP 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 |
|
35 | You can connect multiple components and ports together on one line, and separate connection definitions with a newline or a comma (`,`).
|
36 |
|
37 | Components only have to be specified the first time you mention a new process. Afterwards, simply append empty parentheses (`()`) after the process name.
|
38 |
|
39 | Example:
|
40 |
|
41 | ```fbp
|
42 | 'somefile.txt' -> SOURCE Read(ReadFile) OUT -> IN Split(SplitStr)
|
43 | Split() OUT -> IN Count(Counter) COUNT -> IN Display(Output)
|
44 | Read() ERROR -> IN Display()
|
45 | ```
|
46 |
|
47 | ### Exporting ports
|
48 |
|
49 | When 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 |
|
51 | Example:
|
52 |
|
53 | ```fbp
|
54 | EXPORT=READ.IN:FILENAME
|
55 | Read(ReadFile) OUT -> IN Display(Output)
|
56 | ```
|
57 |
|
58 | This line would export the *IN* port of the *Read* node as *FILENAME*.
|
59 |
|
60 | ### Node metadata
|
61 |
|
62 | It is possible to append metadata to Nodes when declaring them by adding the metadata string to the Component part after a colon (`:`).
|
63 |
|
64 | Example:
|
65 |
|
66 | ```fbp
|
67 | 'somefile.txt' -> SOURCE Read(ReadFile:main)
|
68 | Read() OUT -> IN Split(SplitStr:main)
|
69 | Split() OUT -> IN Count(Counter:main)
|
70 | Count() COUNT -> IN Display(Output:main)
|
71 | Read() ERROR -> IN Display()
|
72 | ```
|
73 |
|
74 | In this case the route leading from *Read* to *Display* through *Split* and *Count* would be identified with the string *main*.
|