Coco f10291f: parens can now take a sequence of expressions: a = (b; c)

This commit is contained in:
Jeremy Ashkenas
2010-11-20 20:22:05 -05:00
parent 93cf3bd922
commit 2f498162b0
6 changed files with 20 additions and 15 deletions

View File

@@ -324,7 +324,7 @@
}) })
], ],
Parenthetical: [ Parenthetical: [
o('( Expression )', function() { o('( Body )', function() {
return new Parens($2); return new Parens($2);
}) })
], ],

View File

@@ -1693,22 +1693,22 @@
}(); }();
exports.Parens = Parens = function() { exports.Parens = Parens = function() {
function Parens(_arg) { function Parens(_arg) {
this.expression = _arg; this.body = _arg;
} }
__extends(Parens, Base); __extends(Parens, Base);
Parens.prototype.children = ['expression']; Parens.prototype.children = ['body'];
Parens.prototype.unwrap = function() { Parens.prototype.unwrap = function() {
return this.expression; return this.body;
}; };
Parens.prototype.isComplex = function() { Parens.prototype.isComplex = function() {
return this.expression.isComplex(); return this.body.isComplex();
}; };
Parens.prototype.makeReturn = function() { Parens.prototype.makeReturn = function() {
return this.expression.makeReturn(); return this.body.makeReturn();
}; };
Parens.prototype.compileNode = function(o) { Parens.prototype.compileNode = function(o) {
var bare, code, expr; var bare, code, expr;
expr = this.expression; expr = this.body.unwrap();
if (expr instanceof Value && expr.isAtomic()) { if (expr instanceof Value && expr.isAtomic()) {
expr.front = this.front; expr.front = this.front;
return expr.compile(o); return expr.compile(o);

File diff suppressed because one or more lines are too long

View File

@@ -388,7 +388,7 @@ grammar =
# where only values are accepted, wrapping it in parentheses will always do # where only values are accepted, wrapping it in parentheses will always do
# the trick. # the trick.
Parenthetical: [ Parenthetical: [
o '( Expression )', -> new Parens $2 o '( Body )', -> new Parens $2
] ]
# The condition portion of a while loop. # The condition portion of a while loop.

View File

@@ -1363,16 +1363,16 @@ exports.Existence = class Existence extends Base
# #
# Parentheses are a good way to force any statement to become an expression. # Parentheses are a good way to force any statement to become an expression.
exports.Parens = class Parens extends Base exports.Parens = class Parens extends Base
constructor: (@expression) -> constructor: (@body) ->
children: ['expression'] children: ['body']
unwrap : -> @expression unwrap : -> @body
isComplex : -> @expression.isComplex() isComplex : -> @body.isComplex()
makeReturn: -> @expression.makeReturn() makeReturn: -> @body.makeReturn()
compileNode: (o) -> compileNode: (o) ->
expr = @expression expr = @body.unwrap()
if expr instanceof Value and expr.isAtomic() if expr instanceof Value and expr.isAtomic()
expr.front = @front expr.front = @front
return expr.compile o return expr.compile o

View File

@@ -56,3 +56,8 @@ obj =
eq obj.num, obj.func() eq obj.num, obj.func()
eq obj.num, obj.result eq obj.num, obj.result
# Multiple semicolon-separated statements in parentheticals.
eq 3, (1; 2; 3)
eq 3, (-> return (1; 2; 3))()