1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

nodes: @soakNode -> @soak

This commit is contained in:
satyr 2010-10-25 22:31:52 +09:00
parent 2aa093b65c
commit 27cdafb2d0
5 changed files with 22 additions and 22 deletions

View file

@ -178,7 +178,7 @@
return new Index($2); return new Index($2);
}), o('INDEX_SOAK Index', function() { }), o('INDEX_SOAK Index', function() {
return extend($2, { return extend($2, {
soakNode: true soak: true
}); });
}), o('INDEX_PROTO Index', function() { }), o('INDEX_PROTO Index', function() {
return extend($2, { return extend($2, {

View file

@ -106,7 +106,7 @@
} }
return _result; return _result;
}).call(this)).join(''); }).call(this)).join('');
klass = override || this.constructor.name + (this.soakNode ? '?' : ''); klass = override || this.constructor.name + (this.soak ? '?' : '');
return '\n' + idt + klass + children; return '\n' + idt + klass + children;
}; };
Base.prototype.eachChild = function(func) { Base.prototype.eachChild = function(func) {
@ -363,7 +363,7 @@
_ref2 = this.properties.concat(this.base); _ref2 = this.properties.concat(this.base);
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
node = _ref2[_i]; node = _ref2[_i];
if (node.soakNode || node instanceof Call) { if (node.soak || node instanceof Call) {
return false; return false;
} }
} }
@ -425,8 +425,8 @@
_ref2 = this.properties; _ref2 = this.properties;
for (i = 0, _len = _ref2.length; i < _len; i++) { for (i = 0, _len = _ref2.length; i < _len; i++) {
prop = _ref2[i]; prop = _ref2[i];
if (prop.soakNode) { if (prop.soak) {
prop.soakNode = false; prop.soak = false;
fst = new Value(this.base, this.properties.slice(0, i)); fst = new Value(this.base, this.properties.slice(0, i));
snd = new Value(this.base, this.properties.slice(i)); snd = new Value(this.base, this.properties.slice(i));
if (fst.isComplex()) { if (fst.isComplex()) {
@ -464,7 +464,7 @@
exports.Call = (function() { exports.Call = (function() {
Call = (function() { Call = (function() {
function Call(variable, _arg, _arg2) { function Call(variable, _arg, _arg2) {
this.soakNode = _arg2; this.soak = _arg2;
this.args = _arg; this.args = _arg;
Call.__super__.constructor.call(this); Call.__super__.constructor.call(this);
this.isNew = false; this.isNew = false;
@ -495,7 +495,7 @@
}; };
Call.prototype.unfoldSoak = function(o) { Call.prototype.unfoldSoak = function(o) {
var _i, _len, _ref2, _ref3, call, ifn, left, list, rite; var _i, _len, _ref2, _ref3, call, ifn, left, list, rite;
if (this.soakNode) { if (this.soak) {
if (this.variable) { if (this.variable) {
if (ifn = If.unfoldSoak(o, this, 'variable')) { if (ifn = If.unfoldSoak(o, this, 'variable')) {
return ifn; return ifn;
@ -615,7 +615,7 @@
this.name = _arg; this.name = _arg;
Accessor.__super__.constructor.call(this); Accessor.__super__.constructor.call(this);
this.proto = tag === 'prototype' ? '.prototype' : ''; this.proto = tag === 'prototype' ? '.prototype' : '';
this.soakNode = tag === 'soak'; this.soak = tag === 'soak';
return this; return this;
} }
return Accessor; return Accessor;
@ -1695,7 +1695,7 @@
this.body = _arg; this.body = _arg;
this.tags = tags || (tags = {}); this.tags = tags || (tags = {});
this.condition = tags.invert ? condition.invert() : condition; this.condition = tags.invert ? condition.invert() : condition;
this.soakNode = tags.soak; this.soak = tags.soak;
this.elseBody = null; this.elseBody = null;
this.isChain = false; this.isChain = false;
return this; return this;
@ -1767,7 +1767,7 @@
return o.level >= LEVEL_COND ? "(" + code + ")" : code; return o.level >= LEVEL_COND ? "(" + code + ")" : code;
}; };
If.prototype.unfoldSoak = function() { If.prototype.unfoldSoak = function() {
return this.soakNode && this; return this.soak && this;
}; };
If.unfoldSoak = function(o, parent, name) { If.unfoldSoak = function(o, parent, name) {
var ifn; var ifn;

View file

@ -172,7 +172,7 @@ break;
case 81:this.$ = new yy.Index($$[$0-3+2-1]); case 81:this.$ = new yy.Index($$[$0-3+2-1]);
break; break;
case 82:this.$ = yy.extend($$[$0-2+2-1], { case 82:this.$ = yy.extend($$[$0-2+2-1], {
soakNode: true soak: true
}); });
break; break;
case 83:this.$ = yy.extend($$[$0-2+2-1], { case 83:this.$ = yy.extend($$[$0-2+2-1], {

View file

@ -247,7 +247,7 @@ grammar =
# Indexing into an object or array using bracket notation. # Indexing into an object or array using bracket notation.
Index: [ Index: [
o 'INDEX_START Expression INDEX_END', -> new Index $2 o 'INDEX_START Expression INDEX_END', -> new Index $2
o 'INDEX_SOAK Index', -> extend $2, soakNode: yes o 'INDEX_SOAK Index', -> extend $2, soak : yes
o 'INDEX_PROTO Index', -> extend $2, proto: yes o 'INDEX_PROTO Index', -> extend $2, proto: yes
] ]

View file

@ -111,7 +111,7 @@ exports.Base = class Base
toString: (idt, override) -> toString: (idt, override) ->
idt or= '' idt or= ''
children = (child.toString idt + TAB for child in @collectChildren()).join('') children = (child.toString idt + TAB for child in @collectChildren()).join('')
klass = override or @constructor.name + if @soakNode then '?' else '' klass = override or @constructor.name + if @soak then '?' else ''
'\n' + idt + klass + children '\n' + idt + klass + children
# Passes each child to a function, breaking when the function returns `false`. # Passes each child to a function, breaking when the function returns `false`.
@ -325,7 +325,7 @@ exports.Value = class Value extends Base
isSimpleNumber : -> @base instanceof Literal and SIMPLENUM.test @base.value isSimpleNumber : -> @base instanceof Literal and SIMPLENUM.test @base.value
isAtomic : -> isAtomic : ->
for node in @properties.concat @base for node in @properties.concat @base
return no if node.soakNode or node instanceof Call return no if node.soak or node instanceof Call
yes yes
isStatement : (o) -> not @properties.length and @base.isStatement o isStatement : (o) -> not @properties.length and @base.isStatement o
@ -372,8 +372,8 @@ exports.Value = class Value extends Base
if ifn = @base.unfoldSoak o if ifn = @base.unfoldSoak o
Array::push.apply ifn.body.properties, @properties Array::push.apply ifn.body.properties, @properties
return ifn return ifn
for prop, i in @properties when prop.soakNode for prop, i in @properties when prop.soak
prop.soakNode = off prop.soak = off
fst = new Value @base, @properties.slice 0, i fst = new Value @base, @properties.slice 0, i
snd = new Value @base, @properties.slice i snd = new Value @base, @properties.slice i
if fst.isComplex() if fst.isComplex()
@ -406,7 +406,7 @@ exports.Call = class Call extends Base
children: ['variable', 'args'] children: ['variable', 'args']
constructor: (variable, @args, @soakNode) -> constructor: (variable, @args, @soak) ->
super() super()
@isNew = false @isNew = false
@isSuper = variable is 'super' @isSuper = variable is 'super'
@ -431,7 +431,7 @@ exports.Call = class Call extends Base
# Soaked chained invocations unfold into if/else ternary structures. # Soaked chained invocations unfold into if/else ternary structures.
unfoldSoak: (o) -> unfoldSoak: (o) ->
if @soakNode if @soak
if @variable if @variable
return ifn if ifn = If.unfoldSoak o, this, 'variable' return ifn if ifn = If.unfoldSoak o, this, 'variable'
[left, rite] = new Value(@variable).cacheReference o [left, rite] = new Value(@variable).cacheReference o
@ -527,8 +527,8 @@ exports.Accessor = class Accessor extends Base
constructor: (@name, tag) -> constructor: (@name, tag) ->
super() super()
@proto = if tag is 'prototype' then '.prototype' else '' @proto = if tag is 'prototype' then '.prototype' else ''
@soakNode = tag is 'soak' @soak = tag is 'soak'
compile: (o) -> compile: (o) ->
name = @name.compile o name = @name.compile o
@ -1389,7 +1389,7 @@ exports.If = class If extends Base
constructor: (condition, @body, tags) -> constructor: (condition, @body, tags) ->
@tags = tags or= {} @tags = tags or= {}
@condition = if tags.invert then condition.invert() else condition @condition = if tags.invert then condition.invert() else condition
@soakNode = tags.soak @soak = tags.soak
@elseBody = null @elseBody = null
@isChain = false @isChain = false
@ -1448,7 +1448,7 @@ exports.If = class If extends Base
@elseBodyNode()?.compile o, LEVEL_LIST @elseBodyNode()?.compile o, LEVEL_LIST
if o.level >= LEVEL_COND then "(#{code})" else code if o.level >= LEVEL_COND then "(#{code})" else code
unfoldSoak: -> @soakNode and this unfoldSoak: -> @soak and this
# Unfold a node's child if soak, then tuck the node under created `If` # Unfold a node's child if soak, then tuck the node under created `If`
@unfoldSoak: (o, parent, name) -> @unfoldSoak: (o, parent, name) ->