Permalink
Browse files

happy new year

  • Loading branch information...
1 parent 937413b commit f4854ec2cf42c3a867f8b5eb88a44e3cc55aa718 @satyr committed Dec 31, 2011
Showing with 26 additions and 27 deletions.
  1. +8 −7 lib/ast.js
  2. +11 −13 src/ast.co
  3. +6 −6 src/doc.co
  4. +1 −1 src/lexer.co
View
@@ -2451,6 +2451,10 @@ exports.Jump = Jump = (function(superclass){
}
return this.show() + ';';
};
+ Jump.extended = function(sub){
+ sub.prototype.children = ['it'];
+ this[sub.displayName.toLowerCase()] = sub;
+ };
return Jump;
}(Node));
exports.Throw = Throw = (function(superclass){
@@ -2462,13 +2466,11 @@ exports.Throw = Throw = (function(superclass){
_this.it = it;
return _this;
}
- prototype.children = ['it'];
prototype.getJump = VOID;
prototype.compileNode = function(o){
var _ref;
return "throw " + (((_ref = this.it) != null ? _ref.compile(o, LEVEL_PAREN) : void 8) || 'null') + ";";
};
- Jump['throw'] = Throw;
return Throw;
}(Jump));
exports.Return = Return = (function(superclass){
@@ -2487,9 +2489,8 @@ exports.Return = Return = (function(superclass){
var that;
return "return" + ((that = this.it) ? ' ' + that.compile(o, LEVEL_PAREN) : '') + ";";
};
- Jump['return'] = Return;
return Return;
-}(Throw));
+}(Jump));
exports.While = While = (function(superclass){
While.displayName = 'While';
var prototype = __extend(While, superclass).prototype, constructor = While;
@@ -2558,14 +2559,14 @@ exports.While = While = (function(superclass){
return head + ') {' + this.compileBody((o.indent += TAB, o));
};
prototype.compileBody = function(o, potest){
- var lines, ret, code, last, res, run, that;
+ var lines, ret, code, that, res, run;
o['break'] = true;
o['continue'] = true;
lines = this.body.lines;
code = ret = '';
if (this.returns) {
- if ((last = lines[lines.length - 1]) && !(last instanceof Throw)) {
- lines[lines.length - 1] = last.makeReturn(res = o.scope.assign('_results', '[]'));
+ if (that = lines[lines.length - 1]) {
+ lines[lines.length - 1] = that.makeReturn(res = o.scope.assign('_results', '[]'));
}
ret = "\n" + this.tab + "return " + (res || '[]') + ";";
}
View
@@ -72,7 +72,7 @@
[tmp; asn.compile o, if ret then LEVEL_CALL else LEVEL_PAREN]
# Passes each child to a function, returning its return value if exists.
- eachChild: !(fn) ->
+ eachChild: (fn) ->
for name of @children then if child = @[name]
if \length in child
then return that if fn(node )? for node of child
@@ -461,7 +461,7 @@ class exports.Chain extends Node
news + base + rest
# Unfolds a soak into an __If__: `a?.b` => `a.b if a?`
- unfoldSoak: !(o) ->
+ unfoldSoak: (o) ->
if @head.unfoldSoak o
that.then.tails.push ...@tails
return that
@@ -479,7 +479,7 @@ class exports.Chain extends Node
Existence test
return If(test, this) <<< {+soak, @cond, @void}
- unfoldAssign: !(o) ->
+ unfoldAssign: (o) ->
if @head.unfoldAssign o
that.right.tails.push ...@tails
return that
@@ -1351,7 +1351,7 @@ class exports.Class extends Node
isCallable: YES
- ripName: -> @name = it.varName(); void
+ ripName: !-> @name = it.varName!
compile: (o, level) ->
{fun, title} = this; {lines} = fun.body
@@ -1473,29 +1473,27 @@ class exports.Jump extends Node
else o[@verb] or @carp "stray #{@verb}"
@show! + \;
+ @extended = !(sub) ->
+ sub::children = [\it]
+ @[sub.displayName.toLowerCase!] = sub
+
#### Throw
class exports.Throw extends Jump
(@it) ~>
- children: [\it]
-
getJump: VOID
compileNode: (o) -> "throw #{ @it?compile o, LEVEL_PAREN or \null };"
- Jump.throw = this
-
#### Return
-class exports.Return extends Throw
+class exports.Return extends Jump
~> import {it} if it and it.value is not \void
getJump: THIS
compileNode: (o) ->
"return#{ if @it then ' ' + that.compile o, LEVEL_PAREN else '' };"
- Jump.return = this
-
#### While
# The traditional `while`/`for`/`do` loop.
# Returns an array of values collected from the last expression when requested.
@@ -1544,8 +1542,8 @@ class exports.While extends Node
o <<< {+\break, +\continue}
{lines} = @body; code = ret = ''
if @returns
- if (last = lines[*-1]) and last not instanceof Throw
- lines[*-1] = last.makeReturn res = o.scope.assign \_results '[]'
+ if lines[*-1]
+ lines[*-1] = that.makeReturn res = o.scope.assign \_results '[]'
ret = "\n#{@tab}return #{ res or '[]' };"
lines.unshift JS "#{ run = o.scope.temporary \run } = true;" if @else
code += "\n#that\n#{@tab}" if @body.compile o, LEVEL_TOP
View
@@ -7,7 +7,7 @@
{title} = document
doc = document.getElementById \doc or lmn \div id: \doc
-nav = document.getElementById \nav or do ->
+nav = document.getElementById \nav or let
h = '<div class=pointee>&#x2935;</div>'
h += "<h1>#title</h1>" if title
for co of sources
@@ -20,7 +20,7 @@ htms = __proto__: null
# [showdown](http://attacklab.net/showdown/) converts the Markdown comments.
sdcv = new Showdown.converter
-do @onhashchange = ->
+do @onhashchange = !->
unless page = /^\D+(?=(\d*)$)/exec location.hash.slice 1
document <<< {title}
nav.className = doc.innerHTML = ''
@@ -32,19 +32,19 @@ do @onhashchange = ->
xhr = new XMLHttpRequest
xhr.open \GET if name is not \Cokefile then name + \.co else name, true
xhr.overrideMimeType? \text/plain
- xhr.onreadystatechange = ->
+ xhr.onreadystatechange = !->
load page, htms[name] = build name, xhr.responseText if xhr.readyState is 4
xhr.send null
function lmn name, attrs
document.body.appendChild document.createElement(name) <<<< attrs
-function load [name, sect], doc.innerHTML
+!function load [name, sect], doc.innerHTML
document.title = name + (title and ' - ' + title)
- document.getElementById(sect)scrollIntoView() if sect
+ document.getElementById(sect)scrollIntoView! if sect
# [google-code-prettify](http://code.google.com/p/google-code-prettify/)
# highlights the code, with the help of our [lang-co](#lang-co) plugin.
- prettyPrint()
+ prettyPrint!
function build name, source
htm = comment = code = i = ''
View
@@ -950,7 +950,7 @@ OPENERS = <[ ( [ { CALL( PARAM( INDENT ]>
CLOSERS = <[ ) ] } )CALL )PARAM DEDENT ]>
# The inverse mappings of {OPEN,CLOS}ERS to look things up from either end.
-INVERSES = new -> import {(c = CLOSERS[i]): o, (o): c} for o, i of OPENERS
+INVERSES = new -> import (c = CLOSERS[i]): o, (o): c for o, i of OPENERS
# Tokens that can start a dot/call chain.
CHAIN = <[ ( { [ ID STRNUM LITERAL LET WITH WORDS ]>

0 comments on commit f4854ec

Please sign in to comment.