mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Revert "Added Unix-like piping. Allows chaining of function calls where every succeeding call receives as first argument the result of all preceding expressions."
This reverts commit 7ee10e06be
.
This commit is contained in:
parent
4dd40034ed
commit
eaf4a71d32
6 changed files with 169 additions and 257 deletions
|
@ -67,7 +67,7 @@
|
||||||
// CoffeeScript is the **Expression** -- you'll notice that there is no
|
// CoffeeScript is the **Expression** -- you'll notice that there is no
|
||||||
// "statement" nonterminal. Expressions serve as the building blocks
|
// "statement" nonterminal. Expressions serve as the building blocks
|
||||||
// of many other rules, making them somewhat circular.
|
// of many other rules, making them somewhat circular.
|
||||||
Expression: [o("Value"), o("Pipe"), o("Call"), o("Curry"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("Throw"), o("Return"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Splat"), o("Existence"), o("Comment"), o("Extension")],
|
Expression: [o("Value"), o("Call"), o("Curry"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("Throw"), o("Return"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Splat"), o("Existence"), o("Comment"), o("Extension")],
|
||||||
// A an indented block of expressions. Note that the [Rewriter](rewriter.html)
|
// A an indented block of expressions. Note that the [Rewriter](rewriter.html)
|
||||||
// will convert some postfix forms into blocks for us, by adjusting the
|
// will convert some postfix forms into blocks for us, by adjusting the
|
||||||
// token stream.
|
// token stream.
|
||||||
|
@ -272,14 +272,6 @@
|
||||||
return $2;
|
return $2;
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
// Unix-like pipe for chained function calls. Reverts to `OpNode` for bitwise
|
|
||||||
// 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`,
|
// The three flavors of function call: normal, object instantiation with `new`,
|
||||||
// and calling `super()`
|
// and calling `super()`
|
||||||
Call: [o("Invocation"), o("NEW Invocation", function() {
|
Call: [o("Invocation"), o("NEW Invocation", function() {
|
||||||
|
@ -573,6 +565,8 @@
|
||||||
return new OpNode('>>>', $1, $3);
|
return new OpNode('>>>', $1, $3);
|
||||||
}), o("Expression & Expression", function() {
|
}), o("Expression & Expression", function() {
|
||||||
return new OpNode('&', $1, $3);
|
return new OpNode('&', $1, $3);
|
||||||
|
}), o("Expression | Expression", function() {
|
||||||
|
return new OpNode('|', $1, $3);
|
||||||
}), o("Expression ^ Expression", function() {
|
}), o("Expression ^ Expression", function() {
|
||||||
return new OpNode('^', $1, $3);
|
return new OpNode('^', $1, $3);
|
||||||
}), o("Expression <= Expression", function() {
|
}), o("Expression <= Expression", function() {
|
||||||
|
|
22
lib/nodes.js
22
lib/nodes.js
|
@ -1,5 +1,5 @@
|
||||||
(function(){
|
(function(){
|
||||||
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, CurryNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, ObjectNode, OpNode, ParentheticalNode, PipeNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, ValueNode, WhileNode, compact, del, flatten, helpers, literal, merge, statement;
|
var AccessorNode, ArrayNode, AssignNode, BaseNode, CallNode, ClassNode, ClosureNode, CodeNode, CommentNode, CurryNode, ExistenceNode, Expressions, ExtendsNode, ForNode, IDENTIFIER, IfNode, IndexNode, LiteralNode, ObjectNode, OpNode, ParentheticalNode, PushNode, RangeNode, ReturnNode, Scope, SliceNode, SplatNode, TAB, TRAILING_WHITESPACE, ThrowNode, TryNode, ValueNode, WhileNode, compact, del, flatten, helpers, literal, merge, statement;
|
||||||
var __extends = function(child, parent) {
|
var __extends = function(child, parent) {
|
||||||
var ctor = function(){ };
|
var ctor = function(){ };
|
||||||
ctor.prototype = parent.prototype;
|
ctor.prototype = parent.prototype;
|
||||||
|
@ -1711,26 +1711,6 @@
|
||||||
};
|
};
|
||||||
return IfNode;
|
return IfNode;
|
||||||
}).call(this);
|
}).call(this);
|
||||||
//### PipeNode
|
|
||||||
// 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) {
|
|
||||||
this.children = [(this.left = left), (this.right = right)];
|
|
||||||
this.fallback = fallback;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
__extends(PipeNode, BaseNode);
|
|
||||||
PipeNode.prototype.type = 'Pipe';
|
|
||||||
PipeNode.prototype.compile_node = function compile_node(o) {
|
|
||||||
if (this.right instanceof CallNode && !(this.right.is_new || this.right.is_super)) {
|
|
||||||
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);
|
|
||||||
// Faux-Nodes
|
// Faux-Nodes
|
||||||
// ----------
|
// ----------
|
||||||
//### PushNode
|
//### PushNode
|
||||||
|
|
332
lib/parser.js
332
lib/parser.js
File diff suppressed because one or more lines are too long
|
@ -73,7 +73,6 @@ grammar: {
|
||||||
# of many other rules, making them somewhat circular.
|
# of many other rules, making them somewhat circular.
|
||||||
Expression: [
|
Expression: [
|
||||||
o "Value"
|
o "Value"
|
||||||
o "Pipe"
|
|
||||||
o "Call"
|
o "Call"
|
||||||
o "Curry"
|
o "Curry"
|
||||||
o "Code"
|
o "Code"
|
||||||
|
@ -260,13 +259,6 @@ grammar: {
|
||||||
o "INDENT AssignList , OUTDENT", -> $2
|
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`,
|
# The three flavors of function call: normal, object instantiation with `new`,
|
||||||
# and calling `super()`
|
# and calling `super()`
|
||||||
Call: [
|
Call: [
|
||||||
|
@ -499,6 +491,7 @@ 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
|
||||||
|
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
|
||||||
|
|
|
@ -1277,23 +1277,6 @@ exports.IfNode: class IfNode extends BaseNode
|
||||||
else_part: if @else_body then @else_body.compile(o) else 'null'
|
else_part: if @else_body then @else_body.compile(o) else 'null'
|
||||||
"$if_part : $else_part"
|
"$if_part : $else_part"
|
||||||
|
|
||||||
#### PipeNode
|
|
||||||
|
|
||||||
# Unix-like piping. Allows chaining of function calls where every succeeding
|
|
||||||
# call receives as first argument the result of all preceding expressions.
|
|
||||||
exports.PipeNode: class PipeNode extends BaseNode
|
|
||||||
type: 'Pipe'
|
|
||||||
|
|
||||||
constructor: (left, right, fallback) ->
|
|
||||||
@children: [@left: left, @right: right]
|
|
||||||
@fallback: fallback
|
|
||||||
|
|
||||||
compile_node: (o) ->
|
|
||||||
if @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
|
|
||||||
|
|
||||||
# Faux-Nodes
|
# Faux-Nodes
|
||||||
# ----------
|
# ----------
|
||||||
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
map: (list, fn) -> fn item for item in list
|
|
||||||
first: (list, fn) -> (return item) for item in list when fn item
|
|
||||||
|
|
||||||
add: (x, y) -> x + y
|
|
||||||
times: (x, y) -> x * y
|
|
||||||
|
|
||||||
y: 1 | add(8) | times(8)
|
|
||||||
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
|
|
||||||
|
|
||||||
results: ['Hello', 'World!', 'How do you do?'] | grep /^H/
|
|
||||||
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.'
|
|
||||||
ok results is 'GREP empty.'
|
|
||||||
|
|
||||||
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…
Add table
Add a link
Reference in a new issue