Parenthetical -> Parens

This commit is contained in:
satyr 2010-10-07 12:53:26 +09:00
parent 2d9cff3af6
commit 250ec12646
5 changed files with 44 additions and 44 deletions

View File

@ -375,9 +375,9 @@
],
Parenthetical: [
o("( Line )", function() {
return new Parenthetical($2);
return new Parens($2);
}), o("( )", function() {
return new Parenthetical(new Literal(''));
return new Parens(new Literal(''));
})
],
WhileSource: [
@ -598,7 +598,7 @@
}), o("Value COMPOUND_ASSIGN INDENT Expression OUTDENT", function() {
return new Op($2, $1, $4);
}), o("Expression RELATION Expression", function() {
return $2.charAt(0) === '!' ? ($2 === '!in' ? new Op('!', new In($1, $3)) : new Op('!', new Parenthetical(new Op($2.slice(1), $1, $3)))) : ($2 === 'in' ? new In($1, $3) : new Op($2, $1, $3));
return $2.charAt(0) === '!' ? ($2 === '!in' ? new Op('!', new In($1, $3)) : new Op('!', new Parens(new Op($2.slice(1), $1, $3)))) : ($2 === 'in' ? new In($1, $3) : new Op($2, $1, $3));
})
]
};

View File

@ -1,5 +1,5 @@
(function() {
var Accessor, ArrayLiteral, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, Literal, NO, NUMBER, ObjectLiteral, Op, Param, Parenthetical, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, _ref, compact, del, ends, flatten, include, indexOf, last, merge, starts, utility;
var Accessor, ArrayLiteral, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, Literal, NO, NUMBER, ObjectLiteral, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, _ref, compact, del, ends, flatten, include, indexOf, last, merge, starts, utility;
var __extends = function(child, parent) {
var ctor = function() {};
ctor.prototype = parent.prototype;
@ -360,7 +360,7 @@
base = new Value(this.base, this.properties.slice(0, -1));
if (base.isComplex()) {
bref = new Literal(o.scope.freeVariable('base'));
base = new Value(new Parenthetical(new Assign(bref, base)));
base = new Value(new Parens(new Assign(bref, base)));
}
if (!(name)) {
return [base, bref];
@ -408,7 +408,7 @@
snd = new Value(this.base, this.properties.slice(i));
if (fst.isComplex()) {
ref = new Literal(o.scope.freeVariable('ref'));
fst = new Parenthetical(new Assign(ref, fst));
fst = new Parens(new Assign(ref, fst));
snd.base = ref;
}
ifn = new If(new Existence(fst), snd, {
@ -1272,7 +1272,7 @@
While.__super__.constructor.call(this);
if (((opts != null) ? opts.invert : undefined)) {
if (condition instanceof Op) {
condition = new Parenthetical(condition);
condition = new Parens(condition);
}
condition = new Op('!', condition);
}
@ -1333,7 +1333,7 @@
this.operator = this.CONVERSIONS[this.operator] || this.operator;
this.flip = !!flip;
if (this.first instanceof Value && this.first.base instanceof ObjectLiteral) {
this.first = new Parenthetical(this.first);
this.first = new Parens(this.first);
} else if (this.operator === 'new' && this.first instanceof Call) {
return this.first.newInstance();
}
@ -1399,10 +1399,10 @@
return this.compileExistence(o);
}
if (this.first instanceof Op && this.first.isMutator()) {
this.first = new Parenthetical(this.first);
this.first = new Parens(this.first);
}
if (this.second instanceof Op && this.second.isMutator()) {
this.second = new Parenthetical(this.second);
this.second = new Parens(this.second);
}
return [this.first.compile(o), this.operator, this.second.compile(o)].join(' ');
};
@ -1423,7 +1423,7 @@
var fst, ref;
if (this.first.isComplex()) {
ref = o.scope.freeVariable('ref');
fst = new Parenthetical(new Assign(new Literal(ref), this.first));
fst = new Parens(new Assign(new Literal(ref), this.first));
} else {
fst = this.first;
ref = fst.compile(o);
@ -1555,27 +1555,27 @@
};
return Existence;
})();
exports.Parenthetical = (function() {
Parenthetical = (function() {
return function Parenthetical(_arg) {
exports.Parens = (function() {
Parens = (function() {
return function Parens(_arg) {
this.expression = _arg;
Parenthetical.__super__.constructor.call(this);
Parens.__super__.constructor.call(this);
return this;
};
})();
__extends(Parenthetical, Base);
Parenthetical.prototype.children = ['expression'];
Parenthetical.prototype.isStatement = function(o) {
__extends(Parens, Base);
Parens.prototype.children = ['expression'];
Parens.prototype.isStatement = function(o) {
return this.expression.isStatement(o);
};
Parenthetical.prototype.isComplex = function() {
Parens.prototype.isComplex = function() {
return this.expression.isComplex();
};
Parenthetical.prototype.topSensitive = YES;
Parenthetical.prototype.makeReturn = function() {
Parens.prototype.topSensitive = YES;
Parens.prototype.makeReturn = function() {
return this.expression.makeReturn();
};
Parenthetical.prototype.compileNode = function(o) {
Parens.prototype.compileNode = function(o) {
var code, top;
top = del(o, 'top');
this.expression.parenthetical = true;
@ -1588,7 +1588,7 @@
}
return "(" + code + ")";
};
return Parenthetical;
return Parens;
})();
exports.For = (function() {
For = (function() {
@ -1768,7 +1768,7 @@
for (_j = 0, _len2 = (_ref4 = flatten([conditions])).length; _j < _len2; _j++) {
condition = _ref4[_j];
if (this.tags.subjectless) {
condition = new Op('!!', new Parenthetical(condition));
condition = new Op('!!', new Parens(condition));
}
code += ("\n" + (this.idt(1)) + "case " + (condition.compile(o)) + ":");
}
@ -1796,7 +1796,7 @@
if (this.condition instanceof Op && this.condition.isInvertible()) {
this.condition.invert();
} else {
this.condition = new Op('!', new Parenthetical(this.condition));
this.condition = new Op('!', new Parens(this.condition));
}
}
this.elseBody = null;
@ -1904,7 +1904,7 @@
if (expressions.containsPureStatement()) {
return expressions;
}
func = new Parenthetical(new Code([], Expressions.wrap([expressions])));
func = new Parens(new Code([], Expressions.wrap([expressions])));
args = [];
if ((mentionsArgs = expressions.contains(this.literalArgs)) || (expressions.contains(this.literalThis))) {
meth = new Literal(mentionsArgs ? 'apply' : 'call');

View File

@ -313,9 +313,9 @@ case 148:this.$ = [$$[$0-3+2-1], $$[$0-3+3-1]];
break;
case 149:this.$ = new yy.Throw($$[$0-2+2-1]);
break;
case 150:this.$ = new yy.Parenthetical($$[$0-3+2-1]);
case 150:this.$ = new yy.Parens($$[$0-3+2-1]);
break;
case 151:this.$ = new yy.Parenthetical(new yy.Literal(''));
case 151:this.$ = new yy.Parens(new yy.Literal(''));
break;
case 152:this.$ = new yy.While($$[$0-2+2-1]);
break;
@ -497,7 +497,7 @@ case 214:this.$ = new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]);
break;
case 215:this.$ = new yy.Op($$[$0-5+2-1], $$[$0-5+1-1], $$[$0-5+4-1]);
break;
case 216:this.$ = $$[$0-3+2-1].charAt(0) === '!' ? ($$[$0-3+2-1] === '!in' ? new yy.Op('!', new yy.In($$[$0-3+1-1], $$[$0-3+3-1])) : new yy.Op('!', new yy.Parenthetical(new yy.Op($$[$0-3+2-1].slice(1), $$[$0-3+1-1], $$[$0-3+3-1])))) : ($$[$0-3+2-1] === 'in' ? new yy.In($$[$0-3+1-1], $$[$0-3+3-1]) : new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]));
case 216:this.$ = $$[$0-3+2-1].charAt(0) === '!' ? ($$[$0-3+2-1] === '!in' ? new yy.Op('!', new yy.In($$[$0-3+1-1], $$[$0-3+3-1])) : new yy.Op('!', new yy.Parens(new yy.Op($$[$0-3+2-1].slice(1), $$[$0-3+1-1], $$[$0-3+3-1])))) : ($$[$0-3+2-1] === 'in' ? new yy.In($$[$0-3+1-1], $$[$0-3+3-1]) : new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]));
break;
}
},

View File

@ -411,8 +411,8 @@ grammar =
# where only values are accepted, wrapping it in parentheses will always do
# the trick.
Parenthetical: [
o "( Line )", -> new Parenthetical $2
o "( )", -> new Parenthetical new Literal ''
o "( Line )", -> new Parens $2
o "( )", -> new Parens new Literal ''
]
# The condition portion of a while loop.
@ -557,7 +557,7 @@ grammar =
if $2 is '!in'
new Op '!', new In $1, $3
else
new Op '!', new Parenthetical new Op $2[1..], $1, $3
new Op '!', new Parens new Op $2[1..], $1, $3
else
if $2 is 'in' then new In $1, $3 else new Op $2, $1, $3
]

View File

@ -353,7 +353,7 @@ exports.Value = class Value extends Base
base = new Value @base, @properties.slice 0, -1
if base.isComplex() # `a().b`
bref = new Literal o.scope.freeVariable 'base'
base = new Value new Parenthetical new Assign bref, base
base = new Value new Parens new Assign bref, base
return [base, bref] unless name # `a()`
if name.isComplex() # `a[b()]`
nref = new Literal o.scope.freeVariable 'name'
@ -391,7 +391,7 @@ exports.Value = class Value extends Base
snd = new Value @base, @properties.slice i
if fst.isComplex()
ref = new Literal o.scope.freeVariable 'ref'
fst = new Parenthetical new Assign ref, fst
fst = new Parens new Assign ref, fst
snd.base = ref
ifn = new If new Existence(fst), snd, operation: yes
ifn.soakNode = on
@ -1103,7 +1103,7 @@ exports.While = class While extends Base
constructor: (condition, opts) ->
super()
if opts?.invert
condition = new Parenthetical condition if condition instanceof Op
condition = new Parens condition if condition instanceof Op
condition = new Op('!', condition)
@condition = condition
@guard = opts?.guard
@ -1174,7 +1174,7 @@ exports.Op = class Op extends Base
@operator = @CONVERSIONS[@operator] or @operator
@flip = !!flip
if @first instanceof Value and @first.base instanceof ObjectLiteral
@first = new Parenthetical @first
@first = new Parens @first
else if @operator is 'new' and @first instanceof Call
return @first.newInstance()
@first.tags.operation = yes
@ -1207,8 +1207,8 @@ exports.Op = class Op extends Base
return @compileAssignment(o) if indexOf(@ASSIGNMENT, @operator) >= 0
return @compileUnary(o) if @isUnary()
return @compileExistence(o) if @operator is '?'
@first = new Parenthetical(@first) if @first instanceof Op and @first.isMutator()
@second = new Parenthetical(@second) if @second instanceof Op and @second.isMutator()
@first = new Parens @first if @first instanceof Op and @first.isMutator()
@second = new Parens @second if @second instanceof Op and @second.isMutator()
[@first.compile(o), @operator, @second.compile(o)].join ' '
# Mimic Python's chained comparisons when multiple comparison operators are
@ -1233,7 +1233,7 @@ exports.Op = class Op extends Base
compileExistence: (o) ->
if @first.isComplex()
ref = o.scope.freeVariable 'ref'
fst = new Parenthetical new Assign new Literal(ref), @first
fst = new Parens new Assign new Literal(ref), @first
else
fst = @first
ref = fst.compile o
@ -1338,14 +1338,14 @@ exports.Existence = class Existence extends Base
"#{code} != null"
if @parenthetical then code else "(#{code})"
#### Parenthetical
#### Parens
# An extra set of parentheses, specified explicitly in the source. At one time
# we tried to clean up the results by detecting and removing redundant
# parentheses, but no longer -- you can put in as many as you please.
#
# Parentheses are a good way to force any statement to become an expression.
exports.Parenthetical = class Parenthetical extends Base
exports.Parens = class Parens extends Base
children: ['expression']
@ -1498,7 +1498,7 @@ exports.Switch = class Switch extends Base
[conditions, block] = pair
exprs = block.expressions
for condition in flatten [conditions]
condition = new Op '!!', new Parenthetical condition if @tags.subjectless
condition = new Op '!!', new Parens condition if @tags.subjectless
code += "\n#{ @idt(1) }case #{ condition.compile o }:"
code += "\n#{ block.compile o }"
code += "\n#{ idt }break;" unless last(exprs) instanceof Return
@ -1526,7 +1526,7 @@ exports.If = class If extends Base
if @condition instanceof Op and @condition.isInvertible()
@condition.invert()
else
@condition = new Op '!', new Parenthetical @condition
@condition = new Op '!', new Parens @condition
@elseBody = null
@isChain = false
@ -1621,7 +1621,7 @@ Closure =
# then make sure that the closure wrapper preserves the original values.
wrap: (expressions, statement) ->
return expressions if expressions.containsPureStatement()
func = new Parenthetical new Code [], Expressions.wrap [expressions]
func = new Parens new Code [], Expressions.wrap [expressions]
args = []
if (mentionsArgs = expressions.contains @literalArgs) or
( expressions.contains @literalThis)