removing the special case for | or
This commit is contained in:
parent
7ee10e06be
commit
9763839ed1
|
@ -276,8 +276,6 @@
|
|||
// operations.
|
||||
Pipe: [o("Expression | Expression", function() {
|
||||
return new PipeNode($1, $3);
|
||||
}), o("Expression | || Expression", function() {
|
||||
return new PipeNode($1, $4, true);
|
||||
})
|
||||
],
|
||||
// The three flavors of function call: normal, object instantiation with `new`,
|
||||
|
|
12
lib/nodes.js
12
lib/nodes.js
|
@ -1715,19 +1715,21 @@
|
|||
// Unix-like piping. Allows chaining of function calls where every succeeding
|
||||
// call receives as first argument the result of all preceding expressions.
|
||||
exports.PipeNode = (function() {
|
||||
PipeNode = function PipeNode(left, right, fallback) {
|
||||
PipeNode = function PipeNode(left, right) {
|
||||
this.children = [(this.left = left), (this.right = right)];
|
||||
this.fallback = fallback;
|
||||
return this;
|
||||
};
|
||||
__extends(PipeNode, BaseNode);
|
||||
PipeNode.prototype.type = 'Pipe';
|
||||
PipeNode.prototype.compile_bitwise_or = function compile_bitwise_or(o) {
|
||||
return new OpNode('|', this.left, this.right).compile(o);
|
||||
};
|
||||
PipeNode.prototype.compile_node = function compile_node(o) {
|
||||
if (this.right instanceof CallNode && !(this.right.is_new || this.right.is_super)) {
|
||||
if (!(this.right instanceof CallNode && !(this.right.is_new || this.right.is_super))) {
|
||||
return compile_bitwise_or(o);
|
||||
}
|
||||
this.right.args.unshift(this.left);
|
||||
return this.right.compile(o);
|
||||
}
|
||||
return new OpNode((this.fallback && this.left instanceof PipeNode ? '||' : '|'), this.left, this.right).compile(o);
|
||||
};
|
||||
return PipeNode;
|
||||
}).call(this);
|
||||
|
|
212
lib/parser.js
212
lib/parser.js
File diff suppressed because one or more lines are too long
|
@ -264,7 +264,6 @@ grammar: {
|
|||
# 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`,
|
||||
|
|
|
@ -1284,15 +1284,16 @@ exports.IfNode: class IfNode extends BaseNode
|
|||
exports.PipeNode: class PipeNode extends BaseNode
|
||||
type: 'Pipe'
|
||||
|
||||
constructor: (left, right, fallback) ->
|
||||
constructor: (left, right) ->
|
||||
@children: [@left: left, @right: right]
|
||||
@fallback: fallback
|
||||
|
||||
compile_bitwise_or: (o) ->
|
||||
new OpNode('|', @left, @right).compile o
|
||||
|
||||
compile_node: (o) ->
|
||||
if @right instanceof CallNode and not (@right.is_new or @right.is_super)
|
||||
return compile_bitwise_or o unless @right instanceof CallNode and not (@right.is_new or @right.is_super)
|
||||
@right.args.unshift @left
|
||||
return @right.compile o
|
||||
new OpNode((if @fallback and @left instanceof PipeNode then '||' else '|'), @left, @right).compile o
|
||||
@right.compile o
|
||||
|
||||
# Faux-Nodes
|
||||
# ----------
|
||||
|
|
|
@ -10,6 +10,7 @@ z: [1, 2, 3, 4] | map((x) -> x * x) | first (x) -> x > 10
|
|||
ok y is 8 * (8 + 1)
|
||||
ok z is 16
|
||||
|
||||
|
||||
grep: (list, regex) ->
|
||||
matches: item for item in list when item.match regex
|
||||
if matches.length then matches else null
|
||||
|
@ -20,15 +21,16 @@ deepEqual results, ['Hello', 'How do you do?']
|
|||
reversed: [1, 2, 3, 4] | Array::reverse.call()
|
||||
deepEqual reversed, [4, 3, 2, 1]
|
||||
|
||||
results: ['a', 'b', 'c', 'd'] | grep(/\d/) | or 'GREP empty.'
|
||||
results: ['a', 'b', 'c', 'd'] | grep(/\d/) or 'GREP empty.'
|
||||
ok results is 'GREP empty.'
|
||||
|
||||
y: 1 | add(8) | times(0) | or 2 | times 2
|
||||
|
||||
y: 1 | add(8) | times(0) or 2 | times 2
|
||||
ok y is 4
|
||||
|
||||
|
||||
z: [1, 2, 3, 4] |
|
||||
map((x) -> x * x) |
|
||||
Array::reverse.call() |
|
||||
or [1, 2, 3, 4] |
|
||||
first (x) -> x > 10
|
||||
ok z is 16
|
Loading…
Reference in New Issue