Added Unix-like piping. Allows chaining of function calls where every succeeding call receives as first argument the result of all preceding expressions.

This commit is contained in:
Stan Angeloff
2010-03-27 15:49:33 +02:00
parent 8f3ea1d0c5
commit 7ee10e06be
6 changed files with 257 additions and 169 deletions

View File

@@ -73,6 +73,7 @@ grammar: {
# of many other rules, making them somewhat circular.
Expression: [
o "Value"
o "Pipe"
o "Call"
o "Curry"
o "Code"
@@ -259,6 +260,13 @@ grammar: {
o "INDENT AssignList , OUTDENT", -> $2
]
# Unix-like pipe for chained function calls. Reverts to `OpNode` for bitwise
# operations.
Pipe: [
o "Expression | Expression", -> new PipeNode $1, $3
o "Expression | || Expression", -> new PipeNode $1, $4, true
]
# The three flavors of function call: normal, object instantiation with `new`,
# and calling `super()`
Call: [
@@ -491,7 +499,6 @@ grammar: {
o "Expression >> Expression", -> new OpNode '>>', $1, $3
o "Expression >>> Expression", -> new OpNode '>>>', $1, $3
o "Expression & Expression", -> new OpNode '&', $1, $3
o "Expression | Expression", -> new OpNode '|', $1, $3
o "Expression ^ Expression", -> new OpNode '^', $1, $3
o "Expression <= Expression", -> new OpNode '<=', $1, $3