coffee-script 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/coffee-script.gemspec +2 -2
- data/examples/documents.coffee +3 -3
- data/lib/coffee-script.rb +1 -1
- data/lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +2 -2
- data/lib/coffee_script/grammar.y +20 -8
- data/lib/coffee_script/lexer.rb +19 -16
- data/lib/coffee_script/nodes.rb +94 -42
- data/lib/coffee_script/parse_error.rb +7 -1
- data/lib/coffee_script/parser.rb +1115 -1045
- data/lib/coffee_script/rewriter.rb +8 -1
- data/lib/coffee_script/scope.rb +25 -0
- data/lib/coffee_script/value.rb +4 -0
- data/package.json +1 -1
- metadata +2 -2
@@ -26,7 +26,7 @@ module CoffeeScript
|
|
26
26
|
|
27
27
|
# Single-line flavors of block expressions that have unclosed endings.
|
28
28
|
# The grammar can't disambiguate them, so we insert the implicit indentation.
|
29
|
-
SINGLE_LINERS = [:ELSE, "=>", :TRY, :FINALLY, :THEN]
|
29
|
+
SINGLE_LINERS = [:ELSE, "=>", "==>", :TRY, :FINALLY, :THEN]
|
30
30
|
SINGLE_CLOSERS = ["\n", :CATCH, :FINALLY, :ELSE, :OUTDENT, :LEADING_WHEN]
|
31
31
|
|
32
32
|
# Rewrite the token stream in multiple passes, one logical filter at
|
@@ -35,6 +35,7 @@ module CoffeeScript
|
|
35
35
|
def rewrite(tokens)
|
36
36
|
@tokens = tokens
|
37
37
|
adjust_comments
|
38
|
+
remove_leading_newlines
|
38
39
|
remove_mid_expression_newlines
|
39
40
|
move_commas_outside_outdents
|
40
41
|
add_implicit_indentation
|
@@ -82,6 +83,12 @@ module CoffeeScript
|
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
86
|
+
# Leading newlines would introduce an ambiguity in the grammar, so we
|
87
|
+
# dispatch them here.
|
88
|
+
def remove_leading_newlines
|
89
|
+
@tokens.shift if @tokens[0][0] == "\n"
|
90
|
+
end
|
91
|
+
|
85
92
|
# Some blocks occur in the middle of expressions -- when we're expecting
|
86
93
|
# this, remove their trailing newlines.
|
87
94
|
def remove_mid_expression_newlines
|
data/lib/coffee_script/scope.rb
CHANGED
@@ -47,15 +47,40 @@ module CoffeeScript
|
|
47
47
|
@temp_variable.dup
|
48
48
|
end
|
49
49
|
|
50
|
+
# Ensure that an assignment is made at the top of scope (or top-level
|
51
|
+
# scope, if requested).
|
52
|
+
def assign(name, value, top=false)
|
53
|
+
return @parent.assign(name, value, top) if top && @parent
|
54
|
+
@variables[name.to_sym] = Value.new(value)
|
55
|
+
end
|
56
|
+
|
50
57
|
def declarations?(body)
|
51
58
|
!declared_variables.empty? && body == @expressions
|
52
59
|
end
|
53
60
|
|
61
|
+
def assignments?(body)
|
62
|
+
!assigned_variables.empty? && body == @expressions
|
63
|
+
end
|
64
|
+
|
54
65
|
# Return the list of variables first declared in current scope.
|
55
66
|
def declared_variables
|
56
67
|
@variables.select {|k, v| v == :var }.map {|pair| pair[0].to_s }.sort
|
57
68
|
end
|
58
69
|
|
70
|
+
# Return the list of variables that are supposed to be assigned at the top
|
71
|
+
# of scope.
|
72
|
+
def assigned_variables
|
73
|
+
@variables.select {|k, v| v.is_a?(Value) }.sort_by {|pair| pair[0].to_s }
|
74
|
+
end
|
75
|
+
|
76
|
+
def compiled_declarations
|
77
|
+
declared_variables.join(', ')
|
78
|
+
end
|
79
|
+
|
80
|
+
def compiled_assignments
|
81
|
+
assigned_variables.map {|name, val| "#{name} = #{val}"}.join(', ')
|
82
|
+
end
|
83
|
+
|
59
84
|
def inspect
|
60
85
|
"<Scope:#{__id__} #{@variables.inspect}>"
|
61
86
|
end
|
data/lib/coffee_script/value.rb
CHANGED
data/package.json
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee-script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Ashkenas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-13 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|