Parser for the .fbp flow definition language
npm install fbp
|6||downloads in the last day|
|95||downloads in the last week|
|366||downloads in the last month|
|Version||1.1.0 last updated 18 days ago|
var parser = require('fbp'); // Some FBP syntax code var fbpData = "'hello, world!' -> IN Display(Output)"; // Parse into a Graph definition JSON object var graphDefinition = parser.parse(fbpData);
After this the graph definition can be loaded into a compatible flow-based runtime environment like NoFlo.
The fbp package also provides a command-line tool for converting FBP files into JSON:
$ fbp somefile.fbp > somefile.json
Language for Flow-Based Programming
FBP is a Domain-Specific Language (DSL) for easy graph definition. The syntax is the following:
'somedata' -> PORT Process(Component)sends initial data somedata to port PORT of process Process that runs component Component
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
You can connect multiple components and ports together on one line, and separate connection definitions with a newline or a comma (
Components only have to be specified the first time you mention a new process. Afterwards, simply append empty parentheses (
()) after the process name.
'somefile.txt' -> SOURCE Read(ReadFile) OUT -> IN Split(SplitStr) Split() OUT -> IN Count(Counter) COUNT -> IN Display(Output) Read() ERROR -> IN Display()
The syntax also supports blank lines and comments. Comments start with the
Example with the same graph than above :
# Read the content of "somefile.txt" and split it by line 'somefile.txt' -> SOURCE Read(ReadFile) OUT -> IN Split(SplitStr) # Count the lines and display the result Split() OUT -> IN Count(Counter) COUNT -> IN Display(Output) # The read errors are also displayed Read() ERROR -> IN Display()
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
INPORT=Read.IN:FILENAME Read(ReadFile) OUT -> IN Display(Output)
This line would export the IN port of the Read node as FILENAME.
It is possible to append metadata to Nodes when declaring them by adding the metadata string to the Component part after a colon (
'somefile.txt' -> SOURCE Read(ReadFile:main) Read() OUT -> IN Split(SplitStr:main) Split() OUT -> IN Count(Counter:main) Count() COUNT -> IN Display(Output:main) Read() ERROR -> IN Display()
In this case the route leading from Read to Display through Split and Count would be identified with the string main.