mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
removing dots from whitespace examples
This commit is contained in:
@@ -4,4 +4,4 @@ volume: 10 if band isnt spinal_tap
|
|||||||
|
|
||||||
let_the_wild_rumpus_begin() unless answer is no
|
let_the_wild_rumpus_begin() unless answer is no
|
||||||
|
|
||||||
if car.speed < speed_limit then accelerate().
|
if car.speed < speed_limit then accelerate()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Eat lunch.
|
# Eat lunch.
|
||||||
lunch: food.eat() for food in ['toast', 'cheese', 'wine'].
|
lunch: food.eat() for food in ['toast', 'cheese', 'wine']
|
||||||
|
|
||||||
# Zebra-stripe a table.
|
# Zebra-stripe a table.
|
||||||
highlight(row) for row, i in table if i % 2 is 0.
|
highlight(row) for row, i in table when i % 2 is 0
|
||||||
@@ -2,8 +2,8 @@ mood: greatly_improved if singing
|
|||||||
|
|
||||||
if happy and knows_it
|
if happy and knows_it
|
||||||
claps_hands()
|
claps_hands()
|
||||||
cha_cha_cha().
|
cha_cha_cha()
|
||||||
|
|
||||||
date: if friday then sue else jill.
|
date: if friday then sue else jill
|
||||||
|
|
||||||
expensive ||= do_the_math()
|
expensive ||= do_the_math()
|
||||||
@@ -2,8 +2,8 @@ grade: student =>
|
|||||||
if student.excellent_work
|
if student.excellent_work
|
||||||
"A+"
|
"A+"
|
||||||
else if student.okay_stuff
|
else if student.okay_stuff
|
||||||
if student.tried_hard then "B" else "B-".
|
if student.tried_hard then "B" else "B-"
|
||||||
else
|
else
|
||||||
"C"..
|
"C"
|
||||||
|
|
||||||
eldest: if 24 > 21 then "Liz" else "Ike".
|
eldest: if 24 > 21 then "Liz" else "Ike"
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
square: x => x * x.
|
square: x => x * x
|
||||||
cube: x => square(x) * x.
|
cube: x => square(x) * x
|
||||||
@@ -6,7 +6,7 @@ opposite_day: true
|
|||||||
number: -42 if opposite_day
|
number: -42 if opposite_day
|
||||||
|
|
||||||
# Functions:
|
# Functions:
|
||||||
square: x => x * x.
|
square: x => x * x
|
||||||
|
|
||||||
# Arrays:
|
# Arrays:
|
||||||
list: [1, 2, 3, 4, 5]
|
list: [1, 2, 3, 4, 5]
|
||||||
@@ -15,8 +15,8 @@ list: [1, 2, 3, 4, 5]
|
|||||||
math: {
|
math: {
|
||||||
root: Math.sqrt
|
root: Math.sqrt
|
||||||
square: square
|
square: square
|
||||||
cube: x => x * square(x).
|
cube: x => x * square(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Array comprehensions:
|
# Array comprehensions:
|
||||||
cubed_list: math.cube(num) for num in list.
|
cubed_list: math.cube(num) for num in list
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
num: 1
|
num: 1
|
||||||
change_numbers: =>
|
change_numbers: =>
|
||||||
num: 2
|
num: 2
|
||||||
new_num: 3.
|
new_num: 3
|
||||||
new_num: change_numbers()
|
new_num: change_numbers()
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
Animal: => .
|
Animal: =>
|
||||||
Animal.prototype.move: meters =>
|
Animal.prototype.move: meters =>
|
||||||
alert(this.name + " moved " + meters + "m.").
|
alert(this.name + " moved " + meters + "m.")
|
||||||
|
|
||||||
Snake: name => this.name: name.
|
Snake: name => this.name: name
|
||||||
Snake extends Animal
|
Snake extends Animal
|
||||||
Snake.prototype.move: =>
|
Snake.prototype.move: =>
|
||||||
alert("Slithering...")
|
alert("Slithering...")
|
||||||
super(5).
|
super(5)
|
||||||
|
|
||||||
Horse: name => this.name: name.
|
Horse: name => this.name: name
|
||||||
Horse extends Animal
|
Horse extends Animal
|
||||||
Horse.prototype.move: =>
|
Horse.prototype.move: =>
|
||||||
alert("Galloping...")
|
alert("Galloping...")
|
||||||
super(45).
|
super(45)
|
||||||
|
|
||||||
sam: new Snake("Sammy the Python")
|
sam: new Snake("Sammy the Python")
|
||||||
tom: new Horse("Tommy the Palomino")
|
tom: new Horse("Tommy the Palomino")
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ when "Wednesday" then go_to_the_park()
|
|||||||
when "Saturday"
|
when "Saturday"
|
||||||
if day is bingo_day
|
if day is bingo_day
|
||||||
go_to_bingo()
|
go_to_bingo()
|
||||||
go_dancing().
|
go_dancing()
|
||||||
when "Sunday" then go_to_church()
|
when "Sunday" then go_to_church()
|
||||||
else go_to_work().
|
else go_to_work()
|
||||||
@@ -4,4 +4,4 @@ try
|
|||||||
catch error
|
catch error
|
||||||
print(error)
|
print(error)
|
||||||
finally
|
finally
|
||||||
clean_up().
|
clean_up()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
while demand > supply
|
while demand > supply
|
||||||
sell()
|
sell()
|
||||||
restock().
|
restock()
|
||||||
|
|
||||||
while supply > demand then buy().
|
while supply > demand then buy()
|
||||||
@@ -32,8 +32,8 @@ prechigh
|
|||||||
left '.'
|
left '.'
|
||||||
right INDENT
|
right INDENT
|
||||||
left OUTDENT
|
left OUTDENT
|
||||||
right THROW FOR IN WHILE WHEN NEW SUPER IF THEN ELSE
|
right THROW FOR IN WHILE WHEN NEW SUPER THEN ELSE
|
||||||
left UNLESS EXTENDS
|
left UNLESS EXTENDS IF
|
||||||
left ASSIGN '||=' '&&='
|
left ASSIGN '||=' '&&='
|
||||||
right RETURN '=>'
|
right RETURN '=>'
|
||||||
preclow
|
preclow
|
||||||
@@ -284,14 +284,14 @@ rule
|
|||||||
# Try/catch/finally exception handling blocks.
|
# Try/catch/finally exception handling blocks.
|
||||||
Try:
|
Try:
|
||||||
TRY Block Catch { result = TryNode.new(val[1], val[2][0], val[2][1]) }
|
TRY Block Catch { result = TryNode.new(val[1], val[2][0], val[2][1]) }
|
||||||
|
| TRY Block FINALLY Block { result = TryNode.new(val[1], nil, nil, val[3]) }
|
||||||
| TRY Block Catch
|
| TRY Block Catch
|
||||||
FINALLY Block { result = TryNode.new(val[1], val[2][0], val[2][1], val[4]) }
|
FINALLY Block { result = TryNode.new(val[1], val[2][0], val[2][1], val[4]) }
|
||||||
;
|
;
|
||||||
|
|
||||||
# A catch clause.
|
# A catch clause.
|
||||||
Catch:
|
Catch:
|
||||||
/* nothing */ { result = [nil, nil] }
|
CATCH IDENTIFIER Block { result = [val[1], val[2]] }
|
||||||
| CATCH IDENTIFIER Block { result = [val[1], val[2]] }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
# Throw an exception.
|
# Throw an exception.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class ParserTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_parsing_array_comprehension
|
def test_parsing_array_comprehension
|
||||||
nodes = @par.parse("i for x, i in [10, 9, 8, 7, 6, 5] if i % 2 is 0").expressions
|
nodes = @par.parse("i for x, i in [10, 9, 8, 7, 6, 5] when i % 2 is 0").expressions
|
||||||
assert nodes.first.is_a? ForNode
|
assert nodes.first.is_a? ForNode
|
||||||
assert nodes.first.body.literal == 'i'
|
assert nodes.first.body.literal == 'i'
|
||||||
assert nodes.first.filter.operator == '==='
|
assert nodes.first.filter.operator == '==='
|
||||||
@@ -78,6 +78,7 @@ class ParserTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_no_wrapping_parens_around_statements
|
def test_no_wrapping_parens_around_statements
|
||||||
|
@par.parse("try thing() catch error fail()").compile
|
||||||
assert_raises(SyntaxError) do
|
assert_raises(SyntaxError) do
|
||||||
@par.parse("(try thing() catch error fail())").compile
|
@par.parse("(try thing() catch error fail())").compile
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user