haml-more 0.4.0.a
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +79 -0
- data/lib/haml/more/coffee_script.rb +137 -0
- data/lib/haml/more/content_for.rb +25 -0
- data/lib/haml/more.rb +45 -0
- data/lib/haml-more.rb +1 -0
- data/lib/sass/more.rb +16 -0
- data/lib/sass-more.rb +1 -0
- data/spec/sass/more_spec.rb +21 -0
- data/vendor/coffee-script/Cakefile +57 -0
- data/vendor/coffee-script/LICENSE +22 -0
- data/vendor/coffee-script/README +41 -0
- data/vendor/coffee-script/Rakefile +20 -0
- data/vendor/coffee-script/bin/cake +7 -0
- data/vendor/coffee-script/bin/coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/aliases.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/arguments.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/array_comprehensions.coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/assignment.coffee +2 -0
- data/vendor/coffee-script/documentation/coffee/cake_tasks.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/comparisons.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/conditionals.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/embedded.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/existence.coffee +8 -0
- data/vendor/coffee-script/documentation/coffee/expressions.coffee +9 -0
- data/vendor/coffee-script/documentation/coffee/expressions_assignment.coffee +1 -0
- data/vendor/coffee-script/documentation/coffee/expressions_comprehension.coffee +3 -0
- data/vendor/coffee-script/documentation/coffee/expressions_try.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/fat_arrow.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/functions.coffee +2 -0
- data/vendor/coffee-script/documentation/coffee/heredocs.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/multiple_return_values.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/object_comprehensions.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/object_extraction.coffee +13 -0
- data/vendor/coffee-script/documentation/coffee/objects_and_arrays.coffee +13 -0
- data/vendor/coffee-script/documentation/coffee/overview.coffee +29 -0
- data/vendor/coffee-script/documentation/coffee/parallel_assignment.coffee +4 -0
- data/vendor/coffee-script/documentation/coffee/range_comprehensions.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/scope.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/slices.coffee +6 -0
- data/vendor/coffee-script/documentation/coffee/soaks.coffee +1 -0
- data/vendor/coffee-script/documentation/coffee/splats.coffee +25 -0
- data/vendor/coffee-script/documentation/coffee/splices.coffee +5 -0
- data/vendor/coffee-script/documentation/coffee/strings.coffee +8 -0
- data/vendor/coffee-script/documentation/coffee/super.coffee +34 -0
- data/vendor/coffee-script/documentation/coffee/switch.coffee +10 -0
- data/vendor/coffee-script/documentation/coffee/try.coffee +7 -0
- data/vendor/coffee-script/documentation/coffee/while.coffee +10 -0
- data/vendor/coffee-script/documentation/css/docs.css +213 -0
- data/vendor/coffee-script/documentation/css/idle.css +63 -0
- data/vendor/coffee-script/documentation/css/logo.png +0 -0
- data/vendor/coffee-script/documentation/index.html.erb +967 -0
- data/vendor/coffee-script/documentation/js/aliases.js +14 -0
- data/vendor/coffee-script/documentation/js/arguments.js +8 -0
- data/vendor/coffee-script/documentation/js/array_comprehensions.js +26 -0
- data/vendor/coffee-script/documentation/js/assignment.js +5 -0
- data/vendor/coffee-script/documentation/js/cake_tasks.js +14 -0
- data/vendor/coffee-script/documentation/js/comparisons.js +5 -0
- data/vendor/coffee-script/documentation/js/conditionals.js +12 -0
- data/vendor/coffee-script/documentation/js/embedded.js +6 -0
- data/vendor/coffee-script/documentation/js/existence.js +7 -0
- data/vendor/coffee-script/documentation/js/expressions.js +13 -0
- data/vendor/coffee-script/documentation/js/expressions_assignment.js +4 -0
- data/vendor/coffee-script/documentation/js/expressions_comprehension.js +12 -0
- data/vendor/coffee-script/documentation/js/expressions_try.js +9 -0
- data/vendor/coffee-script/documentation/js/fat_arrow.js +15 -0
- data/vendor/coffee-script/documentation/js/functions.js +9 -0
- data/vendor/coffee-script/documentation/js/heredocs.js +4 -0
- data/vendor/coffee-script/documentation/js/intro.js +7 -0
- data/vendor/coffee-script/documentation/js/multiple_return_values.js +11 -0
- data/vendor/coffee-script/documentation/js/object_comprehensions.js +17 -0
- data/vendor/coffee-script/documentation/js/object_extraction.js +17 -0
- data/vendor/coffee-script/documentation/js/objects_and_arrays.js +10 -0
- data/vendor/coffee-script/documentation/js/overview.js +43 -0
- data/vendor/coffee-script/documentation/js/parallel_assignment.js +8 -0
- data/vendor/coffee-script/documentation/js/punctuation.js +8 -0
- data/vendor/coffee-script/documentation/js/range_comprehensions.js +21 -0
- data/vendor/coffee-script/documentation/js/scope.js +10 -0
- data/vendor/coffee-script/documentation/js/slices.js +6 -0
- data/vendor/coffee-script/documentation/js/soaks.js +4 -0
- data/vendor/coffee-script/documentation/js/splats.js +16 -0
- data/vendor/coffee-script/documentation/js/splices.js +5 -0
- data/vendor/coffee-script/documentation/js/strings.js +9 -0
- data/vendor/coffee-script/documentation/js/super.js +37 -0
- data/vendor/coffee-script/documentation/js/switch.js +18 -0
- data/vendor/coffee-script/documentation/js/try.js +10 -0
- data/vendor/coffee-script/documentation/js/while.js +22 -0
- data/vendor/coffee-script/documentation/underscore.html +627 -0
- data/vendor/coffee-script/examples/beautiful_code/binary_search.coffee +16 -0
- data/vendor/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +13 -0
- data/vendor/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +34 -0
- data/vendor/coffee-script/examples/blocks.coffee +57 -0
- data/vendor/coffee-script/examples/code.coffee +173 -0
- data/vendor/coffee-script/examples/computer_science/README +4 -0
- data/vendor/coffee-script/examples/computer_science/binary_search.coffee +25 -0
- data/vendor/coffee-script/examples/computer_science/bubble_sort.coffee +11 -0
- data/vendor/coffee-script/examples/computer_science/linked_list.coffee +106 -0
- data/vendor/coffee-script/examples/computer_science/luhn_algorithm.coffee +36 -0
- data/vendor/coffee-script/examples/computer_science/merge_sort.coffee +19 -0
- data/vendor/coffee-script/examples/computer_science/selection_sort.coffee +23 -0
- data/vendor/coffee-script/examples/poignant.coffee +186 -0
- data/vendor/coffee-script/examples/potion.coffee +205 -0
- data/vendor/coffee-script/examples/underscore.coffee +603 -0
- data/vendor/coffee-script/examples/web_server.coffee +12 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences +24 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +361 -0
- data/vendor/coffee-script/extras/CoffeeScript.tmbundle/info.plist +10 -0
- data/vendor/coffee-script/extras/EXTRAS +20 -0
- data/vendor/coffee-script/extras/coffee.vim +117 -0
- data/vendor/coffee-script/index.html +1847 -0
- data/vendor/coffee-script/lib/bin/cake +7 -0
- data/vendor/coffee-script/lib/bin/coffee +7 -0
- data/vendor/coffee-script/lib/cake.js +80 -0
- data/vendor/coffee-script/lib/coffee-script.js +61 -0
- data/vendor/coffee-script/lib/command_line.js +201 -0
- data/vendor/coffee-script/lib/grammar.js +564 -0
- data/vendor/coffee-script/lib/lexer.js +405 -0
- data/vendor/coffee-script/lib/narwhal.js +44 -0
- data/vendor/coffee-script/lib/nodes.js +1328 -0
- data/vendor/coffee-script/lib/optparse.js +117 -0
- data/vendor/coffee-script/lib/parser.js +536 -0
- data/vendor/coffee-script/lib/repl.js +32 -0
- data/vendor/coffee-script/lib/rewriter.js +383 -0
- data/vendor/coffee-script/lib/scope.js +114 -0
- data/vendor/coffee-script/package.json +7 -0
- data/vendor/coffee-script/src/cake.coffee +45 -0
- data/vendor/coffee-script/src/coffee-script.coffee +45 -0
- data/vendor/coffee-script/src/command_line.coffee +130 -0
- data/vendor/coffee-script/src/grammar.coffee +456 -0
- data/vendor/coffee-script/src/lexer.coffee +327 -0
- data/vendor/coffee-script/src/narwhal.coffee +42 -0
- data/vendor/coffee-script/src/nodes.coffee +1045 -0
- data/vendor/coffee-script/src/optparse.coffee +79 -0
- data/vendor/coffee-script/src/repl.coffee +23 -0
- data/vendor/coffee-script/src/rewriter.coffee +253 -0
- data/vendor/coffee-script/src/scope.coffee +75 -0
- data/vendor/coffee-script/test/test_arguments.coffee +34 -0
- data/vendor/coffee-script/test/test_array_comprehension.coffee +42 -0
- data/vendor/coffee-script/test/test_assignment.coffee +26 -0
- data/vendor/coffee-script/test/test_blocks.coffee +4 -0
- data/vendor/coffee-script/test/test_calling_super.coffee +42 -0
- data/vendor/coffee-script/test/test_chained_calls.coffee +25 -0
- data/vendor/coffee-script/test/test_destructuring_assignment.coffee +62 -0
- data/vendor/coffee-script/test/test_everything.coffee +29 -0
- data/vendor/coffee-script/test/test_exceptions.coffee +2 -0
- data/vendor/coffee-script/test/test_existence.coffee +81 -0
- data/vendor/coffee-script/test/test_expressions.coffee +30 -0
- data/vendor/coffee-script/test/test_fancy_if_statement.coffee +26 -0
- data/vendor/coffee-script/test/test_functions.coffee +80 -0
- data/vendor/coffee-script/test/test_funky_comments.coffee +25 -0
- data/vendor/coffee-script/test/test_heredocs.coffee +46 -0
- data/vendor/coffee-script/test/test_lexical_scope.coffee +10 -0
- data/vendor/coffee-script/test/test_literals.coffee +56 -0
- data/vendor/coffee-script/test/test_nested_comprehensions.coffee +11 -0
- data/vendor/coffee-script/test/test_newline_escaping.coffee +6 -0
- data/vendor/coffee-script/test/test_operations.coffee +18 -0
- data/vendor/coffee-script/test/test_range_comprehension.coffee +20 -0
- data/vendor/coffee-script/test/test_ranges_and_slices.coffee +16 -0
- data/vendor/coffee-script/test/test_splats.coffee +47 -0
- data/vendor/coffee-script/test/test_splices.coffee +5 -0
- data/vendor/coffee-script/test/test_switch.coffee +64 -0
- data/vendor/coffee-script/test/test_while.coffee +30 -0
- data/vendor/coffee-script/vendor/jison/Jakefile +31 -0
- data/vendor/coffee-script/vendor/jison/README.md +347 -0
- data/vendor/coffee-script/vendor/jison/bin/jison +3 -0
- data/vendor/coffee-script/vendor/jison/bin/json2jison +3 -0
- data/vendor/coffee-script/vendor/jison/examples/ansic.jison +415 -0
- data/vendor/coffee-script/vendor/jison/examples/basic.json +8 -0
- data/vendor/coffee-script/vendor/jison/examples/basic2.json +9 -0
- data/vendor/coffee-script/vendor/jison/examples/basic2_lex.json +16 -0
- data/vendor/coffee-script/vendor/jison/examples/basic_lex.json +15 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.jison +38 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.jisonlex +14 -0
- data/vendor/coffee-script/vendor/jison/examples/calculator.json +42 -0
- data/vendor/coffee-script/vendor/jison/examples/classy.json +105 -0
- data/vendor/coffee-script/vendor/jison/examples/classy_ast.json +126 -0
- data/vendor/coffee-script/vendor/jison/examples/dism.json +25 -0
- data/vendor/coffee-script/vendor/jison/examples/dism_lr0.json +26 -0
- data/vendor/coffee-script/vendor/jison/examples/json.js +80 -0
- data/vendor/coffee-script/vendor/jison/examples/json_ast.js +83 -0
- data/vendor/coffee-script/vendor/jison/examples/precedence.json +26 -0
- data/vendor/coffee-script/vendor/jison/examples/reduce_conflict.json +13 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/bnf.js +43 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/jisonlex.js +18 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/json2jison.js +146 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/lexer.js +224 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/bnf-parser.js +383 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/lex-parser.js +407 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/set.js +94 -0
- data/vendor/coffee-script/vendor/jison/lib/jison/util/typal.js +90 -0
- data/vendor/coffee-script/vendor/jison/lib/jison.js +1414 -0
- data/vendor/coffee-script/vendor/jison/package.json +14 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.jison +110 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.jisonlex +25 -0
- data/vendor/coffee-script/vendor/jison/src/bnf.lex.json +24 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.jison +129 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.jisonlex +31 -0
- data/vendor/coffee-script/vendor/jison/src/jisonlex.lex.json +30 -0
- data/vendor/coffee-script/vendor/jison/tests/all-tests.js +8 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/bnf.js +91 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/bnf_parse.js +65 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/grammar-tests.js +10 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/json2jison.js +24 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/ansic.jisonlex +115 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.jisonlex +25 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.lex.json +24 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.jisonlex +31 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.lex.json +30 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex.jison +119 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex.js +58 -0
- data/vendor/coffee-script/vendor/jison/tests/grammar/lex_parse.js +117 -0
- data/vendor/coffee-script/vendor/jison/tests/lexer/lexer-tests.js +6 -0
- data/vendor/coffee-script/vendor/jison/tests/lexer/regexplexer.js +417 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/actions.js +311 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/api.js +236 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/generator.js +196 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lalr.js +183 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lr0.js +72 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/lr1.js +119 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/parser-tests.js +14 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/precedence.js +237 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/slr.js +52 -0
- data/vendor/coffee-script/vendor/jison/tests/parser/tables.js +126 -0
- data/vendor/coffee-script/vendor/jison/tests/performance.js +110 -0
- data/vendor/coffee-script/vendor/jison/tests/setup.js +3 -0
- metadata +324 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
func: ->
|
2
|
+
a: 3
|
3
|
+
b: []
|
4
|
+
|
5
|
+
while a >= 0
|
6
|
+
b.push 'o'
|
7
|
+
a--
|
8
|
+
|
9
|
+
c: {
|
10
|
+
"text": b
|
11
|
+
other: null
|
12
|
+
something_else: (x) -> x + 5
|
13
|
+
}
|
14
|
+
|
15
|
+
c: 'error' unless 42 > 41
|
16
|
+
|
17
|
+
c.text: if false
|
18
|
+
'error'
|
19
|
+
else
|
20
|
+
c.text + '---'
|
21
|
+
d = {
|
22
|
+
text = c.text
|
23
|
+
}
|
24
|
+
|
25
|
+
c.list: l for l in d.text.split('') when l is '-'
|
26
|
+
|
27
|
+
c.single: c.list[1..1][0]
|
28
|
+
|
29
|
+
ok func() is '-'
|
@@ -0,0 +1,81 @@
|
|
1
|
+
ok(if my_special_variable? then false else true)
|
2
|
+
|
3
|
+
my_special_variable: false
|
4
|
+
|
5
|
+
ok(if my_special_variable? then true else false)
|
6
|
+
|
7
|
+
|
8
|
+
# Existential assignment.
|
9
|
+
|
10
|
+
a: 5
|
11
|
+
a: null
|
12
|
+
a ?= 10
|
13
|
+
b ?= 10
|
14
|
+
|
15
|
+
ok a is 10 and b is 10
|
16
|
+
|
17
|
+
|
18
|
+
# The existential operator.
|
19
|
+
|
20
|
+
z: null
|
21
|
+
x: z ? "EX"
|
22
|
+
|
23
|
+
ok z is null and x is "EX"
|
24
|
+
|
25
|
+
|
26
|
+
# Only evaluate once.
|
27
|
+
|
28
|
+
counter: 0
|
29
|
+
get_next_node: ->
|
30
|
+
throw "up" if counter
|
31
|
+
counter++
|
32
|
+
|
33
|
+
ok(if get_next_node()? then true else false)
|
34
|
+
|
35
|
+
|
36
|
+
# Existence chains, soaking up undefined properties:
|
37
|
+
|
38
|
+
obj: {
|
39
|
+
prop: "hello"
|
40
|
+
}
|
41
|
+
|
42
|
+
ok obj?.prop is "hello"
|
43
|
+
|
44
|
+
ok obj?['prop'] is "hello"
|
45
|
+
|
46
|
+
ok obj.prop?.length is 5
|
47
|
+
|
48
|
+
ok obj?['prop']?['length'] is 5
|
49
|
+
|
50
|
+
ok obj?.prop?.non?.existent?.property is undefined
|
51
|
+
|
52
|
+
ok obj?['non']?['existent'].property is undefined
|
53
|
+
|
54
|
+
|
55
|
+
# Soaks and caches method calls as well.
|
56
|
+
|
57
|
+
arr: ["--", "----"]
|
58
|
+
|
59
|
+
ok arr.pop()?.length is 4
|
60
|
+
ok arr.pop()?.length is 2
|
61
|
+
ok arr.pop()?.length is undefined
|
62
|
+
ok arr[0]?.length is undefined
|
63
|
+
ok arr.pop()?.length?.non?.existent()?.property is undefined
|
64
|
+
|
65
|
+
|
66
|
+
# Soaks method calls safely.
|
67
|
+
value: undefined
|
68
|
+
result: value?.toString().toLowerCase()
|
69
|
+
|
70
|
+
ok result is undefined
|
71
|
+
|
72
|
+
value: 10
|
73
|
+
result: value?.toString().toLowerCase()
|
74
|
+
|
75
|
+
ok result is '10'
|
76
|
+
|
77
|
+
|
78
|
+
# Safely existence test on soaks.
|
79
|
+
result: not value?.property?
|
80
|
+
ok result
|
81
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Ensure that we don't wrap Nodes that are "statement_only" in a closure.
|
2
|
+
|
3
|
+
items: [1, 2, 3, "bacon", 4, 5]
|
4
|
+
|
5
|
+
for item in items
|
6
|
+
break if item is "bacon"
|
7
|
+
|
8
|
+
findit: (items) ->
|
9
|
+
for item in items
|
10
|
+
return item if item is "bacon"
|
11
|
+
|
12
|
+
ok findit(items) is "bacon"
|
13
|
+
|
14
|
+
|
15
|
+
# When when a closure wrapper is generated for expression conversion, make sure
|
16
|
+
# that references to "this" within the wrapper are safely converted as well.
|
17
|
+
|
18
|
+
obj: {
|
19
|
+
num: 5
|
20
|
+
func: ->
|
21
|
+
this.result: if false
|
22
|
+
10
|
23
|
+
else
|
24
|
+
"a"
|
25
|
+
"b"
|
26
|
+
this.num
|
27
|
+
}
|
28
|
+
|
29
|
+
ok obj.num is obj.func()
|
30
|
+
ok obj.num is obj.result
|
@@ -0,0 +1,26 @@
|
|
1
|
+
a: b: d: true
|
2
|
+
c: false
|
3
|
+
|
4
|
+
result: if a
|
5
|
+
if b
|
6
|
+
if c then false else
|
7
|
+
if d
|
8
|
+
true
|
9
|
+
|
10
|
+
ok result
|
11
|
+
|
12
|
+
|
13
|
+
first: if false then false else second: if false then false else true
|
14
|
+
|
15
|
+
ok first
|
16
|
+
ok second
|
17
|
+
|
18
|
+
|
19
|
+
result: if false
|
20
|
+
false
|
21
|
+
else if NaN
|
22
|
+
false
|
23
|
+
else
|
24
|
+
true
|
25
|
+
|
26
|
+
ok result
|
@@ -0,0 +1,80 @@
|
|
1
|
+
x: 1
|
2
|
+
y: {}
|
3
|
+
y.x: -> 3
|
4
|
+
|
5
|
+
ok x is 1
|
6
|
+
ok typeof(y.x) is 'function'
|
7
|
+
ok y.x instanceof Function
|
8
|
+
ok y.x() is 3
|
9
|
+
ok y.x.name is 'x'
|
10
|
+
|
11
|
+
|
12
|
+
# The empty function should not cause a syntax error.
|
13
|
+
->
|
14
|
+
() ->
|
15
|
+
|
16
|
+
|
17
|
+
obj: {
|
18
|
+
name: "Fred"
|
19
|
+
|
20
|
+
bound: ->
|
21
|
+
(=> ok(this.name is "Fred"))()
|
22
|
+
|
23
|
+
unbound: ->
|
24
|
+
(-> ok(!this.name?))()
|
25
|
+
}
|
26
|
+
|
27
|
+
obj.unbound()
|
28
|
+
obj.bound()
|
29
|
+
|
30
|
+
|
31
|
+
# The named function should be cleared out before a call occurs:
|
32
|
+
|
33
|
+
# Python decorator style wrapper that memoizes any function
|
34
|
+
memoize: (fn) ->
|
35
|
+
cache: {}
|
36
|
+
self: this
|
37
|
+
(args...) ->
|
38
|
+
key: args.toString()
|
39
|
+
return cache[key] if cache[key]
|
40
|
+
cache[key] = fn.apply(self, args)
|
41
|
+
|
42
|
+
Math: {
|
43
|
+
Add: (a, b) -> a + b
|
44
|
+
AnonymousAdd: ((a, b) -> a + b)
|
45
|
+
FastAdd: memoize (a, b) -> a + b
|
46
|
+
}
|
47
|
+
|
48
|
+
ok Math.Add(5, 5) is 10
|
49
|
+
ok Math.AnonymousAdd(10, 10) is 20
|
50
|
+
ok Math.FastAdd(20, 20) is 40
|
51
|
+
|
52
|
+
|
53
|
+
# Parens are optional on simple function calls.
|
54
|
+
ok 100 > 1 if 1 > 0
|
55
|
+
ok true unless false
|
56
|
+
ok true for i in [1..3]
|
57
|
+
|
58
|
+
ok_func: (f) -> ok(f())
|
59
|
+
ok_func -> true
|
60
|
+
|
61
|
+
# Optional parens can be used in a nested fashion.
|
62
|
+
call: (func) -> func()
|
63
|
+
|
64
|
+
result: call ->
|
65
|
+
inner: call ->
|
66
|
+
Math.Add(5, 5)
|
67
|
+
|
68
|
+
ok result is 10
|
69
|
+
|
70
|
+
|
71
|
+
# And even with strange things like this:
|
72
|
+
|
73
|
+
funcs: [(x) -> x, (x) -> x * x]
|
74
|
+
result: funcs[1] 5
|
75
|
+
|
76
|
+
ok result is 25
|
77
|
+
|
78
|
+
result: ("hello".slice) 3
|
79
|
+
|
80
|
+
ok result is 'lo'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# comment
|
2
|
+
func: ->
|
3
|
+
# comment
|
4
|
+
false
|
5
|
+
false # comment
|
6
|
+
false
|
7
|
+
# comment
|
8
|
+
true
|
9
|
+
|
10
|
+
switch 'string'
|
11
|
+
# comment
|
12
|
+
when false then something()
|
13
|
+
# comment
|
14
|
+
when null
|
15
|
+
something_else()
|
16
|
+
|
17
|
+
->
|
18
|
+
code()
|
19
|
+
# comment
|
20
|
+
|
21
|
+
ok func()
|
22
|
+
|
23
|
+
func
|
24
|
+
func
|
25
|
+
# Line3
|
@@ -0,0 +1,46 @@
|
|
1
|
+
a: """
|
2
|
+
basic heredoc
|
3
|
+
on two lines
|
4
|
+
"""
|
5
|
+
|
6
|
+
ok a is "basic heredoc\non two lines"
|
7
|
+
|
8
|
+
|
9
|
+
a: '''
|
10
|
+
a
|
11
|
+
"b
|
12
|
+
c
|
13
|
+
'''
|
14
|
+
|
15
|
+
ok a is "a\n \"b\nc"
|
16
|
+
|
17
|
+
|
18
|
+
a: '''one-liner'''
|
19
|
+
|
20
|
+
ok a is 'one-liner'
|
21
|
+
|
22
|
+
|
23
|
+
a: """
|
24
|
+
out
|
25
|
+
here
|
26
|
+
"""
|
27
|
+
|
28
|
+
ok a is "out\nhere"
|
29
|
+
|
30
|
+
|
31
|
+
a: '''
|
32
|
+
a
|
33
|
+
b
|
34
|
+
c
|
35
|
+
'''
|
36
|
+
|
37
|
+
ok a is " a\n b\nc"
|
38
|
+
|
39
|
+
a: '''
|
40
|
+
a
|
41
|
+
|
42
|
+
|
43
|
+
b c
|
44
|
+
'''
|
45
|
+
|
46
|
+
ok a is "a\n\n\nb c"
|
@@ -0,0 +1,56 @@
|
|
1
|
+
a: [(x) -> x, (x) -> x * x]
|
2
|
+
|
3
|
+
ok a.length is 2
|
4
|
+
|
5
|
+
|
6
|
+
regex: /match/i
|
7
|
+
words: "I think there is a match in here."
|
8
|
+
|
9
|
+
ok !!words.match(regex)
|
10
|
+
|
11
|
+
|
12
|
+
neg: (3 -4)
|
13
|
+
|
14
|
+
ok neg is -1
|
15
|
+
|
16
|
+
|
17
|
+
func: ->
|
18
|
+
return if true
|
19
|
+
|
20
|
+
ok func() is null
|
21
|
+
|
22
|
+
|
23
|
+
str: "\\"
|
24
|
+
reg: /\\/
|
25
|
+
|
26
|
+
ok reg(str) and str is '\\'
|
27
|
+
|
28
|
+
|
29
|
+
money$: 'dollars'
|
30
|
+
|
31
|
+
ok money$ is 'dollars'
|
32
|
+
|
33
|
+
|
34
|
+
ok {a: (num) -> num is 10 }.a 10
|
35
|
+
|
36
|
+
|
37
|
+
bob: {
|
38
|
+
name: 'Bob'
|
39
|
+
greet: (salutation) ->
|
40
|
+
salutation + " " + @name
|
41
|
+
hello: ->
|
42
|
+
@['greet'] "Hello"
|
43
|
+
10: 'number'
|
44
|
+
}
|
45
|
+
|
46
|
+
ok bob.hello() is "Hello Bob"
|
47
|
+
ok bob[10] is 'number'
|
48
|
+
|
49
|
+
|
50
|
+
obj: {
|
51
|
+
'is': -> yes
|
52
|
+
'not': -> no
|
53
|
+
}
|
54
|
+
|
55
|
+
ok obj.is()
|
56
|
+
ok not obj.not()
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# CoffeeScript's operations should be chainable, like Python's.
|
2
|
+
|
3
|
+
ok 500 > 50 > 5 > -5
|
4
|
+
|
5
|
+
ok true is not false is true is not false
|
6
|
+
|
7
|
+
ok 10 < 20 > 10
|
8
|
+
|
9
|
+
ok 50 > 10 > 5 is parseInt('5', 10)
|
10
|
+
|
11
|
+
|
12
|
+
# Make sure that each argument is only evaluated once, even if used
|
13
|
+
# more than once.
|
14
|
+
|
15
|
+
i: 0
|
16
|
+
func: -> i++
|
17
|
+
|
18
|
+
ok 1 > func() < 1
|
@@ -0,0 +1,20 @@
|
|
1
|
+
nums: i * 3 for i in [1..3]
|
2
|
+
|
3
|
+
negs: x for x in [-20..-5*2]
|
4
|
+
negs: negs[0..2]
|
5
|
+
|
6
|
+
result: nums.concat(negs).join(', ')
|
7
|
+
|
8
|
+
ok result is '3, 6, 9, -20, -19, -18'
|
9
|
+
|
10
|
+
# Ensure that ranges are safe. This used to infinite loop:
|
11
|
+
j = 5
|
12
|
+
result: for j in [j..(j+3)]
|
13
|
+
j
|
14
|
+
|
15
|
+
ok result.join(' ') is '5 6 7 8'
|
16
|
+
|
17
|
+
# With range comprehensions, you can loop in steps.
|
18
|
+
results: x for x in [0..25] by 5
|
19
|
+
|
20
|
+
ok results.join(' ') is '0 5 10 15 20 25'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
2
|
+
|
3
|
+
a: array[7..9]
|
4
|
+
b: array[2...4]
|
5
|
+
|
6
|
+
result: a.concat(b).join(' ')
|
7
|
+
|
8
|
+
ok result is "7 8 9 2 3"
|
9
|
+
|
10
|
+
|
11
|
+
countdown: [10..1].join(' ')
|
12
|
+
ok countdown is "10 9 8 7 6 5 4 3 2 1"
|
13
|
+
|
14
|
+
|
15
|
+
array: [(1+5)..1+9]
|
16
|
+
ok array.join(' ') is "6 7 8 9 10"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
func: (first, second, rest...) ->
|
2
|
+
rest.join ' '
|
3
|
+
|
4
|
+
result: func 1, 2, 3, 4, 5
|
5
|
+
|
6
|
+
ok result is "3 4 5"
|
7
|
+
|
8
|
+
|
9
|
+
gold: silver: bronze: the_field: null
|
10
|
+
|
11
|
+
medalists: (first, second, third, rest...) ->
|
12
|
+
gold: first
|
13
|
+
silver: second
|
14
|
+
bronze: third
|
15
|
+
the_field: rest
|
16
|
+
|
17
|
+
contenders: [
|
18
|
+
"Michael Phelps"
|
19
|
+
"Liu Xiang"
|
20
|
+
"Yao Ming"
|
21
|
+
"Allyson Felix"
|
22
|
+
"Shawn Johnson"
|
23
|
+
"Roman Sebrle"
|
24
|
+
"Guo Jingjing"
|
25
|
+
"Tyson Gay"
|
26
|
+
"Asafa Powell"
|
27
|
+
"Usain Bolt"
|
28
|
+
]
|
29
|
+
|
30
|
+
medalists "Mighty Mouse", contenders...
|
31
|
+
|
32
|
+
ok gold is "Mighty Mouse"
|
33
|
+
ok silver is "Michael Phelps"
|
34
|
+
ok bronze is "Liu Xiang"
|
35
|
+
ok the_field.length is 8
|
36
|
+
|
37
|
+
|
38
|
+
obj: {
|
39
|
+
name: 'bob'
|
40
|
+
accessor: (args...) ->
|
41
|
+
[@name].concat(args).join(' ')
|
42
|
+
getNames: ->
|
43
|
+
args: ['jane', 'ted']
|
44
|
+
@accessor(args...)
|
45
|
+
}
|
46
|
+
|
47
|
+
ok obj.getNames() is 'bob jane ted'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
num: 10
|
2
|
+
|
3
|
+
result: switch num
|
4
|
+
when 5 then false
|
5
|
+
when 'a'
|
6
|
+
true
|
7
|
+
true
|
8
|
+
false
|
9
|
+
when 10 then true
|
10
|
+
|
11
|
+
|
12
|
+
# Mid-switch comment with whitespace
|
13
|
+
# and multi line
|
14
|
+
when 11 then false
|
15
|
+
else false
|
16
|
+
|
17
|
+
ok result
|
18
|
+
|
19
|
+
|
20
|
+
func: (num) ->
|
21
|
+
switch num
|
22
|
+
when 2, 4, 6
|
23
|
+
true
|
24
|
+
when 1, 3, 5
|
25
|
+
false
|
26
|
+
else false
|
27
|
+
|
28
|
+
ok func(2)
|
29
|
+
ok func(6)
|
30
|
+
ok !func(3)
|
31
|
+
ok !func(8)
|
32
|
+
|
33
|
+
|
34
|
+
# Should cache the switch value, if anything fancier than a literal.
|
35
|
+
num: 5
|
36
|
+
result: switch num += 5
|
37
|
+
when 5 then false
|
38
|
+
when 15 then false
|
39
|
+
when 10 then true
|
40
|
+
else false
|
41
|
+
|
42
|
+
ok result
|
43
|
+
|
44
|
+
|
45
|
+
# Ensure that trailing switch elses don't get rewritten.
|
46
|
+
result: false
|
47
|
+
switch "word"
|
48
|
+
when "one thing"
|
49
|
+
do_something()
|
50
|
+
else
|
51
|
+
result: true unless false
|
52
|
+
|
53
|
+
ok result
|
54
|
+
|
55
|
+
result: false
|
56
|
+
switch "word"
|
57
|
+
when "one thing"
|
58
|
+
do_something()
|
59
|
+
when "other thing"
|
60
|
+
do_something()
|
61
|
+
else
|
62
|
+
result: true unless false
|
63
|
+
|
64
|
+
ok result
|
@@ -0,0 +1,30 @@
|
|
1
|
+
i: 5
|
2
|
+
list: while i -= 1
|
3
|
+
i * 2
|
4
|
+
|
5
|
+
ok list.join(' ') is "8 6 4 2"
|
6
|
+
|
7
|
+
|
8
|
+
i: 5
|
9
|
+
list: (i * 3 while i -= 1)
|
10
|
+
|
11
|
+
ok list.join(' ') is "12 9 6 3"
|
12
|
+
|
13
|
+
|
14
|
+
i: 5
|
15
|
+
func: (num) -> i -= num
|
16
|
+
assert: -> ok i < 5 > 0
|
17
|
+
|
18
|
+
results: while func 1
|
19
|
+
assert()
|
20
|
+
i
|
21
|
+
|
22
|
+
ok results.join(' ') is '4 3 2 1'
|
23
|
+
|
24
|
+
|
25
|
+
i: 10
|
26
|
+
results: while i -= 1 when i % 2 is 0
|
27
|
+
i * 2
|
28
|
+
|
29
|
+
ok results.join(' ') is '16 12 8 4'
|
30
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env narwhal
|
2
|
+
|
3
|
+
var FILE = require("file"),
|
4
|
+
OS = require("os"),
|
5
|
+
jake = require("jake");
|
6
|
+
|
7
|
+
jake.task("build", ["build:bnf", "build:lex"]);
|
8
|
+
|
9
|
+
jake.task("build:bnf", function () {
|
10
|
+
OS.system(['./bin/jison', 'src/bnf.jison', 'src/bnf.jisonlex']);
|
11
|
+
OS.system(['mv', 'bnf.js', 'lib/jison/util/bnf-parser.js']);
|
12
|
+
});
|
13
|
+
|
14
|
+
jake.task("build:lex", function () {
|
15
|
+
OS.system(['./bin/jison', 'src/jisonlex.jison', 'src/jisonlex.jisonlex']);
|
16
|
+
OS.system(['mv', 'jisonlex.js', 'lib/jison/util/lex-parser.js']);
|
17
|
+
});
|
18
|
+
|
19
|
+
|
20
|
+
jake.task("test", function () {
|
21
|
+
OS.system(['narwhal', 'tests/all-tests.js']);
|
22
|
+
});
|
23
|
+
jake.task("test:parser", function () {
|
24
|
+
OS.system(['narwhal', 'tests/parser/parser-tests.js']);
|
25
|
+
});
|
26
|
+
jake.task("test:lexer", function () {
|
27
|
+
OS.system(['narwhal', 'tests/lexer/lexer-tests.js']);
|
28
|
+
});
|
29
|
+
jake.task("test:grammar", function () {
|
30
|
+
OS.system(['narwhal', 'tests/grammar/grammar-tests.js']);
|
31
|
+
});
|