coffee-script 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,45 @@
1
+ module CoffeeScript
2
+
3
+ # Scope objects form a tree corresponding to the shape of the function
4
+ # definitions present in the script. They provide lexical scope, to determine
5
+ # whether a variable has been seen before or if it needs to be declared.
6
+ class Scope
7
+
8
+ attr_reader :parent, :temp_variable
9
+
10
+ # Initialize a scope with its parent, for lookups up the chain.
11
+ def initialize(parent=nil)
12
+ @parent = parent
13
+ @variables = {}
14
+ @temp_variable = @parent ? @parent.temp_variable : 'a'
15
+ end
16
+
17
+ # Look up a variable in lexical scope, or declare it if not found.
18
+ def find(name, remote=false)
19
+ found = check(name, remote)
20
+ return found if found || remote
21
+ @variables[name.to_sym] = true
22
+ found
23
+ end
24
+
25
+ # Just check to see if a variable has already been declared.
26
+ def check(name, remote=false)
27
+ return true if @variables[name.to_sym]
28
+ @parent && @parent.find(name, true)
29
+ end
30
+
31
+ # You can reset a found variable on the immediate scope.
32
+ def reset(name)
33
+ @variables[name.to_sym] = false
34
+ end
35
+
36
+ # Find an available, short, name for a compiler-generated variable.
37
+ def free_variable
38
+ @temp_variable.succ! while check(@temp_variable)
39
+ @variables[@temp_variable.to_sym] = true
40
+ @temp_variable.dup
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,42 @@
1
+ module CoffeeScript
2
+
3
+ # Instead of producing raw Ruby objects, the Lexer produces values of this
4
+ # class, wrapping native objects tagged with line number information.
5
+ class Value
6
+ attr_reader :value, :line
7
+
8
+ def initialize(value, line)
9
+ @value, @line = value, line
10
+ end
11
+
12
+ def to_str
13
+ @value.to_s
14
+ end
15
+ alias_method :to_s, :to_str
16
+
17
+ def to_sym
18
+ to_str.to_sym
19
+ end
20
+
21
+ def inspect
22
+ @value.inspect
23
+ end
24
+
25
+ def ==(other)
26
+ @value == other
27
+ end
28
+
29
+ def [](index)
30
+ @value[index]
31
+ end
32
+
33
+ def eql?(other)
34
+ @value.eql?(other)
35
+ end
36
+
37
+ def hash
38
+ @value.hash
39
+ end
40
+ end
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coffee-script
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Ashkenas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-24 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: " CoffeeScript is a little language that compiles into JavaScript.\n"
17
+ email: jashkenas@gmail.com
18
+ executables:
19
+ - coffee-script
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - bin/coffee-script
26
+ - examples/code.cs
27
+ - examples/documents.cs
28
+ - examples/poignant.cs
29
+ - examples/syntax_errors.cs
30
+ - examples/underscore.cs
31
+ - lib/coffee-script.rb
32
+ - lib/coffee_script/CoffeeScript.tmbundle/info.plist
33
+ - lib/coffee_script/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences
34
+ - lib/coffee_script/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
35
+ - lib/coffee_script/command_line.rb
36
+ - lib/coffee_script/grammar.y
37
+ - lib/coffee_script/lexer.rb
38
+ - lib/coffee_script/nodes.rb
39
+ - lib/coffee_script/parse_error.rb
40
+ - lib/coffee_script/parser.rb
41
+ - lib/coffee_script/scope.rb
42
+ - lib/coffee_script/value.rb
43
+ - coffee-script.gemspec
44
+ - LICENSE
45
+ - README
46
+ has_rdoc: false
47
+ homepage: http://jashkenas.github.com/coffee-script/
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project: coffee-script
70
+ rubygems_version: 1.3.5
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: The CoffeeScript Compiler
74
+ test_files: []
75
+