Permalink
Browse files

added comma as delimiter on single line blocks

  • Loading branch information...
1 parent 0b2c212 commit 21b259935e394586902967799369ac710e34be27 Jonah Fox committed Nov 22, 2010
@@ -17,7 +17,7 @@ module.exports = function(stream) {
var token = new Token.word(word)
token.was_at_symbol = true
this.replaceWith(token)
- if(token.next.word || token.next.lbracket)
+ if(token.next.word && !token.next.lbracket)
token.after(new Token.operator("."))
return token
}
@@ -14,14 +14,26 @@ module.exports = function(stream) {
var pair = Token.bracket.pair("()")
+ var tok = this
+
var end = this.find(function(token) {
if(token.lbracket && token.curly) return true
if(token.lbracket) return token.matching
if(token.next.text == "return") return true
if(token.newline) return true
-// if(token.operator && token.op == ",") return true
+ if(token.text == ",") {
+ if(token.prev.prev != tok) {
+ return true
+ }
+ }
})
+ if(end.text == ",") {
+ end.spitRight()
+ end = end.next
+ end.prev.remove()
+ }
+
if(!end.whitespace)
end.spitRight()
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -26,7 +26,7 @@ compiles:
@[k]
to:
-this[]
+this[k]
compiles:
@(x)
View
@@ -6,81 +6,3 @@ to:
add(3, 4, function(sum) {
ok(sum == 7)
})
-
-compiles:
-
-nested!()
-nested!()
-nested!(1, 2)
-x
-to:
-
-nested(function() {
- nested(function() {
- nested(1, 2, function() {
- x
- })
- })
-})
-
-compiles:
-
-nested!()
-@x = 1
-this.x = 1
-nested!()
-@x = 2
-
-to:
-var _this = this;
-nested(function() {
- _this.x = 1
- this.x = 1
- nested(function() {
- _this.x = 2
- })
-})
-
-compiles:
-aysnc!()
-@x = 1
-function() { @x }
-to:
-var _this = this;
-aysnc(function() {
- _this.x = 1
- function() { this.x }
-})
-
-
-
-/*
-maybe later:
-
-compiles:
-if ! User.exists! @name {
- User.create! {name: @name}
-}
-
-to:
-__user = User.exists! @name
-if ! __user {
- User.create! {name: @name}
-}
-...
-
-
-
-compiles:
-callback(User.find! @name)
-
-to:
-__u = User.find! @name
-callback __u
-to:
-
-User.find(@name, function(__u) {
- callback(__u)
-})
-
-*/
@@ -80,8 +80,21 @@ function() {
}
compiles:
-if x == 2 return true
+if x == 2, return true
x
to:
if(x == 2) return true
-x
+x
+
+compiles:
+if x, y += 1
+x
+to:
+if(x) y += 1
+x
+
+compiles:
+for i, v in A, i++
+
+to:
+for(i, v in A) i++
View
@@ -14,7 +14,7 @@ module.exports = function(stream) {
var token = new Token.word(word)
token.was_at_symbol = true
this.replaceWith(token)
- if(token.next.word || token.next.lbracket)
+ if(token.next.word && !token.next.lbracket)
token.after(new Token.operator("."))
return token
}
@@ -11,14 +11,25 @@ module.exports = function(stream) {
var pair = Token.bracket.pair("()")
+ var tok = this
+
var end = this.find(function(token) {
if(token.lbracket && token.curly) return true
if(token.lbracket) return token.matching
- if(token.next.text == "return") return true
if(token.newline) return true
-// if(token.operator && token.op == ",") return true
+ if(token.text == ",") {
+ if(token.prev.prev != tok) {
+ return true
+ }
+ }
})
+ if(end.text == ",") {
+ end.spitRight()
+ end = end.next
+ end.prev.remove()
+ }
+
if(!end.whitespace)
end.spitRight()

0 comments on commit 21b2599

Please sign in to comment.