Permalink
Browse files

Parse INPORTS and OUTPORTS, refs noflo/noflo#118

  • Loading branch information...
1 parent 22066e6 commit 79bc495c0105c35db98ec8b052a793f5c6fc1780 @bergie bergie committed Feb 18, 2014
Showing with 504 additions and 85 deletions.
  1. +2 −0 Gruntfile.coffee
  2. +2 −2 README.md
  3. +22 −5 grammar/fbp.peg
  4. +389 −43 lib/fbp.js
  5. +89 −35 spec/fbp.coffee
View
@@ -34,6 +34,8 @@ module.exports = ->
cafemocha:
nodejs:
src: ['spec/*.coffee']
+ options:
+ reporter: 'spec'
# CoffeeScript compilation
coffee:
View
@@ -61,12 +61,12 @@ Read() ERROR -> IN Display()
### Exporting ports
-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.
+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` and `OUTPORT` statements.
Example:
```fbp
-EXPORT=READ.IN:FILENAME
+INPORT=Read.IN:FILENAME
Read(ReadFile) OUT -> IN Display(Output)
```
View
@@ -7,10 +7,11 @@
var parser, edges, nodes;
parser = this;
+ delete parser.exports;
+ delete parser.inports;
+ delete parser.outports;
edges = parser.edges = [];
-
- parser.exports = []
nodes = {};
@@ -28,7 +29,7 @@
}
parser.getResult = function () {
- return {processes:nodes, connections:parser.processEdges(), exports:parser.exports};
+ return {processes:nodes, connections:parser.processEdges(), exports:parser.exports, inports: parser.inports, outports: parser.outports};
}
var flatten = function (array, isShallow) {
@@ -50,8 +51,23 @@
}
parser.registerExports = function (priv, pub) {
+ if (!parser.exports) {
+ parser.exports = [];
+ }
parser.exports.push({private:priv.toLowerCase(), public:pub.toLowerCase()})
}
+ parser.registerInports = function (node, port, pub) {
+ if (!parser.inports) {
+ parser.inports = [];
+ }
+ parser.inports.push({process:node, port:port.toLowerCase(), public:pub.toLowerCase()})
+ }
+ parser.registerOutports = function (node, port, pub) {
+ if (!parser.outports) {
+ parser.outports = [];
+ }
+ parser.outports.push({process:node, port:port.toLowerCase(), public:pub.toLowerCase()})
+ }
parser.registerEdges = function (edges) {
@@ -81,11 +97,12 @@ start
= (line)* { return parser.getResult(); }
line
- = _ "EXPORT=" priv:[A-Z.0-9_]+ ":" pub:[A-Z0-9_]+ _ LineTerminator? {return parser.registerExports(priv.join(""),pub.join(""))}
+ = _ "EXPORT=" priv:[A-Za-z.0-9_]+ ":" pub:[A-Z0-9_]+ _ LineTerminator? {return parser.registerExports(priv.join(""),pub.join(""))}
+ / _ "INPORT=" node:[A-Za-z0-9_]+ "." port:[A-Z0-9_]+ ":" pub:[A-Z0-9_]+ _ LineTerminator? {return parser.registerInports(node.join(""),port.join(""),pub.join(""))}
+ / _ "OUTPORT=" node:[A-Za-z0-9_]+ "." port:[A-Z0-9_]+ ":" pub:[A-Z0-9_]+ _ LineTerminator? {return parser.registerOutports(node.join(""),port.join(""),pub.join(""))}
/ comment [\n\r\u2028\u2029]?
/ _ [\n\r\u2028\u2029]
/ _ edges:connection _ LineTerminator? {return parser.registerEdges(edges);}
-
LineTerminator
= _ ","? comment? [\n\r\u2028\u2029]?
Oops, something went wrong.

0 comments on commit 79bc495

Please sign in to comment.