mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 09:17:55 -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
|
||||
|
||||
if car.speed < speed_limit then accelerate().
|
||||
if car.speed < speed_limit then accelerate()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Eat lunch.
|
||||
lunch: food.eat() for food in ['toast', 'cheese', 'wine'].
|
||||
lunch: food.eat() for food in ['toast', 'cheese', 'wine']
|
||||
|
||||
# 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
|
||||
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()
|
||||
@@ -2,8 +2,8 @@ grade: student =>
|
||||
if student.excellent_work
|
||||
"A+"
|
||||
else if student.okay_stuff
|
||||
if student.tried_hard then "B" else "B-".
|
||||
if student.tried_hard then "B" else "B-"
|
||||
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.
|
||||
cube: x => square(x) * x.
|
||||
square: x => x * x
|
||||
cube: x => square(x) * x
|
||||
@@ -6,7 +6,7 @@ opposite_day: true
|
||||
number: -42 if opposite_day
|
||||
|
||||
# Functions:
|
||||
square: x => x * x.
|
||||
square: x => x * x
|
||||
|
||||
# Arrays:
|
||||
list: [1, 2, 3, 4, 5]
|
||||
@@ -15,8 +15,8 @@ list: [1, 2, 3, 4, 5]
|
||||
math: {
|
||||
root: Math.sqrt
|
||||
square: square
|
||||
cube: x => x * square(x).
|
||||
cube: x => x * square(x)
|
||||
}
|
||||
|
||||
# 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
|
||||
change_numbers: =>
|
||||
num: 2
|
||||
new_num: 3.
|
||||
new_num: 3
|
||||
new_num: change_numbers()
|
||||
@@ -1,18 +1,18 @@
|
||||
Animal: => .
|
||||
Animal: =>
|
||||
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.prototype.move: =>
|
||||
alert("Slithering...")
|
||||
super(5).
|
||||
super(5)
|
||||
|
||||
Horse: name => this.name: name.
|
||||
Horse: name => this.name: name
|
||||
Horse extends Animal
|
||||
Horse.prototype.move: =>
|
||||
alert("Galloping...")
|
||||
super(45).
|
||||
super(45)
|
||||
|
||||
sam: new Snake("Sammy the Python")
|
||||
tom: new Horse("Tommy the Palomino")
|
||||
|
||||
@@ -4,6 +4,6 @@ when "Wednesday" then go_to_the_park()
|
||||
when "Saturday"
|
||||
if day is bingo_day
|
||||
go_to_bingo()
|
||||
go_dancing().
|
||||
go_dancing()
|
||||
when "Sunday" then go_to_church()
|
||||
else go_to_work().
|
||||
else go_to_work()
|
||||
@@ -4,4 +4,4 @@ try
|
||||
catch error
|
||||
print(error)
|
||||
finally
|
||||
clean_up().
|
||||
clean_up()
|
||||
@@ -1,5 +1,5 @@
|
||||
while demand > supply
|
||||
sell()
|
||||
restock().
|
||||
restock()
|
||||
|
||||
while supply > demand then buy().
|
||||
while supply > demand then buy()
|
||||
@@ -32,8 +32,8 @@ prechigh
|
||||
left '.'
|
||||
right INDENT
|
||||
left OUTDENT
|
||||
right THROW FOR IN WHILE WHEN NEW SUPER IF THEN ELSE
|
||||
left UNLESS EXTENDS
|
||||
right THROW FOR IN WHILE WHEN NEW SUPER THEN ELSE
|
||||
left UNLESS EXTENDS IF
|
||||
left ASSIGN '||=' '&&='
|
||||
right RETURN '=>'
|
||||
preclow
|
||||
@@ -284,14 +284,14 @@ rule
|
||||
# Try/catch/finally exception handling blocks.
|
||||
Try:
|
||||
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
|
||||
FINALLY Block { result = TryNode.new(val[1], val[2][0], val[2][1], val[4]) }
|
||||
;
|
||||
|
||||
# A catch clause.
|
||||
Catch:
|
||||
/* nothing */ { result = [nil, nil] }
|
||||
| CATCH IDENTIFIER Block { result = [val[1], val[2]] }
|
||||
CATCH IDENTIFIER Block { result = [val[1], val[2]] }
|
||||
;
|
||||
|
||||
# Throw an exception.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -45,7 +45,7 @@ class ParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
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.body.literal == 'i'
|
||||
assert nodes.first.filter.operator == '==='
|
||||
@@ -78,6 +78,7 @@ class ParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_no_wrapping_parens_around_statements
|
||||
@par.parse("try thing() catch error fail()").compile
|
||||
assert_raises(SyntaxError) do
|
||||
@par.parse("(try thing() catch error fail())").compile
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user