red 3.5.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +10 -15
- data/README.txt +7 -50
- data/bin/red +12 -19
- data/config/hoe.rb +7 -6
- data/lib/red/errors.rb +2 -64
- data/lib/red/executable.rb +35 -34
- data/lib/red/nodes/assignment_nodes.rb +133 -0
- data/lib/red/nodes/call_nodes.rb +126 -0
- data/lib/red/nodes/control_nodes.rb +126 -0
- data/lib/red/nodes/data_nodes.rb +75 -0
- data/lib/red/nodes/definition_nodes.rb +191 -0
- data/lib/red/nodes/illegal_nodes.rb +33 -0
- data/lib/red/nodes/literal_nodes.rb +148 -0
- data/lib/red/nodes/logic_nodes.rb +89 -0
- data/lib/red/nodes/variable_nodes.rb +76 -0
- data/lib/red/plugin.rb +6 -7
- data/lib/red/version.rb +2 -2
- data/lib/red.rb +209 -131
- data/lib/source/ruby.rb +6744 -0
- metadata +14 -19
- data/lib/javascripts/_dom_ready.js +0 -249
- data/lib/javascripts/prototype_dom_ready.js +0 -1
- data/lib/javascripts/red/unobtrusive.red +0 -6
- data/lib/red/assignment_nodes.rb +0 -164
- data/lib/red/call_nodes.rb +0 -90
- data/lib/red/conditional_nodes.rb +0 -63
- data/lib/red/conjunction_nodes.rb +0 -23
- data/lib/red/constant_nodes.rb +0 -47
- data/lib/red/control_nodes.rb +0 -129
- data/lib/red/data_nodes.rb +0 -93
- data/lib/red/definition_nodes.rb +0 -177
- data/lib/red/illegal_nodes.rb +0 -63
- data/lib/red/literal_nodes.rb +0 -119
- data/lib/red/variable_nodes.rb +0 -37
- data/lib/red/wrap_nodes.rb +0 -51
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Sielaff
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-12 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 1.7.0
|
44
44
|
version:
|
45
|
-
description: Red
|
45
|
+
description: Red writes like Ruby and runs like JavaScript.
|
46
46
|
email:
|
47
47
|
- jesse.sielaff@gmail.com
|
48
48
|
executables:
|
@@ -65,26 +65,21 @@ files:
|
|
65
65
|
- bin/red
|
66
66
|
- config/hoe.rb
|
67
67
|
- config/requirements.rb
|
68
|
-
- lib/javascripts/_dom_ready.js
|
69
|
-
- lib/javascripts/prototype_dom_ready.js
|
70
|
-
- lib/javascripts/red/unobtrusive.red
|
71
68
|
- lib/red.rb
|
72
|
-
- lib/red/assignment_nodes.rb
|
73
|
-
- lib/red/call_nodes.rb
|
74
|
-
- lib/red/conditional_nodes.rb
|
75
|
-
- lib/red/conjunction_nodes.rb
|
76
|
-
- lib/red/constant_nodes.rb
|
77
|
-
- lib/red/control_nodes.rb
|
78
|
-
- lib/red/data_nodes.rb
|
79
|
-
- lib/red/definition_nodes.rb
|
80
69
|
- lib/red/errors.rb
|
81
70
|
- lib/red/executable.rb
|
82
|
-
- lib/red/illegal_nodes.rb
|
83
|
-
- lib/red/literal_nodes.rb
|
84
71
|
- lib/red/plugin.rb
|
85
|
-
- lib/red/variable_nodes.rb
|
86
72
|
- lib/red/version.rb
|
87
|
-
- lib/red/
|
73
|
+
- lib/red/nodes/assignment_nodes.rb
|
74
|
+
- lib/red/nodes/call_nodes.rb
|
75
|
+
- lib/red/nodes/control_nodes.rb
|
76
|
+
- lib/red/nodes/data_nodes.rb
|
77
|
+
- lib/red/nodes/definition_nodes.rb
|
78
|
+
- lib/red/nodes/illegal_nodes.rb
|
79
|
+
- lib/red/nodes/literal_nodes.rb
|
80
|
+
- lib/red/nodes/logic_nodes.rb
|
81
|
+
- lib/red/nodes/variable_nodes.rb
|
82
|
+
- lib/source/ruby.rb
|
88
83
|
- script/console
|
89
84
|
- script/destroy
|
90
85
|
- script/generate
|
@@ -125,6 +120,6 @@ rubyforge_project: red-js
|
|
125
120
|
rubygems_version: 1.2.0
|
126
121
|
signing_key:
|
127
122
|
specification_version: 2
|
128
|
-
summary: Red
|
123
|
+
summary: Red writes like Ruby and runs like JavaScript.
|
129
124
|
test_files: []
|
130
125
|
|
@@ -1,249 +0,0 @@
|
|
1
|
-
// http://tanny.ica.com/ICA/TKO/test.nsf/js/addevent.js
|
2
|
-
// Accessed 8/08/08 for Red
|
3
|
-
|
4
|
-
// written by Dean Edwards, 2005
|
5
|
-
// with input from Tino Zijdel, Matthias Miller, Diego Perini
|
6
|
-
// http://dean.edwards.name/weblog/2005/10/add-event/
|
7
|
-
// 2007-07-10 TKO - Removed check for body in schedule because of problems with Firefox 2.0
|
8
|
-
|
9
|
-
/*global domReady */
|
10
|
-
|
11
|
-
function addEvent(element, type, handler) {
|
12
|
-
// Modification by Tanny O'Haley, http://tanny.ica.com to add the
|
13
|
-
// DOMContentLoaded for all browsers.
|
14
|
-
if ((type === "DOMContentLoaded" || type === "domload")) {
|
15
|
-
if(typeof domReady === "function") {
|
16
|
-
domReady(handler);
|
17
|
-
return;
|
18
|
-
} else {
|
19
|
-
type = "load";
|
20
|
-
}
|
21
|
-
}
|
22
|
-
|
23
|
-
if (element.addEventListener) {
|
24
|
-
element.addEventListener(type, handler, false);
|
25
|
-
} else {
|
26
|
-
// assign each event handler a unique ID
|
27
|
-
if (!handler.$$guid) {
|
28
|
-
handler.$$guid = addEvent.guid++;
|
29
|
-
}
|
30
|
-
// create a hash table of event types for the element
|
31
|
-
if (!element.events) {
|
32
|
-
element.events = {};
|
33
|
-
}
|
34
|
-
// create a hash table of event handlers for each element/event pair
|
35
|
-
var handlers = element.events[type];
|
36
|
-
if (!handlers) {
|
37
|
-
handlers = element.events[type] = {};
|
38
|
-
// store the existing event handler (if there is one)
|
39
|
-
if (element["on" + type]) {
|
40
|
-
handlers[0] = element["on" + type];
|
41
|
-
}
|
42
|
-
}
|
43
|
-
// store the event handler in the hash table
|
44
|
-
handlers[handler.$$guid] = handler;
|
45
|
-
// assign a global event handler to do all the work
|
46
|
-
element["on" + type] = handleEvent;
|
47
|
-
}
|
48
|
-
}
|
49
|
-
// a counter used to create unique IDs
|
50
|
-
addEvent.guid = 1;
|
51
|
-
|
52
|
-
function removeEvent(element, type, handler) {
|
53
|
-
if (element.removeEventListener) {
|
54
|
-
element.removeEventListener(type, handler, false);
|
55
|
-
} else {
|
56
|
-
// delete the event handler from the hash table
|
57
|
-
if (element.events && element.events[type]) {
|
58
|
-
delete element.events[type][handler.$$guid];
|
59
|
-
}
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
function handleEvent(event) {
|
64
|
-
var returnValue = true;
|
65
|
-
// grab the event object (IE uses a global event object)
|
66
|
-
event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
|
67
|
-
// get a reference to the hash table of event handlers
|
68
|
-
var handlers = this.events[event.type];
|
69
|
-
// execute each event handler
|
70
|
-
for (var i in handlers) {
|
71
|
-
this.$$handleEvent = handlers[i];
|
72
|
-
if (this.$$handleEvent(event) === false) {
|
73
|
-
returnValue = false;
|
74
|
-
}
|
75
|
-
}
|
76
|
-
return returnValue;
|
77
|
-
}
|
78
|
-
|
79
|
-
function fixEvent(event) {
|
80
|
-
// add W3C standard event methods
|
81
|
-
event.preventDefault = fixEvent.preventDefault;
|
82
|
-
event.stopPropagation = fixEvent.stopPropagation;
|
83
|
-
return event;
|
84
|
-
}
|
85
|
-
fixEvent.preventDefault = function() {
|
86
|
-
this.returnValue = false;
|
87
|
-
};
|
88
|
-
fixEvent.stopPropagation = function() {
|
89
|
-
this.cancelBubble = true;
|
90
|
-
};
|
91
|
-
|
92
|
-
// End Dean Edwards addEvent.
|
93
|
-
|
94
|
-
// Tino Zijdel - crisp@xs4all.nl This little snippet fixes the problem that the onload attribute on
|
95
|
-
// the body-element will overwrite previous attached events on the window object for the onload event.
|
96
|
-
if (!window.addEventListener) {
|
97
|
-
document.onreadystatechange = function(){
|
98
|
-
if (window.onload && window.onload !== handleEvent) {
|
99
|
-
addEvent(window, 'load', window.onload);
|
100
|
-
window.onload = handleEvent;
|
101
|
-
}
|
102
|
-
};
|
103
|
-
}
|
104
|
-
|
105
|
-
// -----------------------------------------------------
|
106
|
-
// -----------------------------------------------------
|
107
|
-
|
108
|
-
// http://tanny.ica.com/ICA/TKO/test.nsf/js/domready.js
|
109
|
-
// Accessed 8/08/08 for Red
|
110
|
-
|
111
|
-
// DOMContentLoaded event handler. Works for browsers that don't support the DOMContentLoaded event.
|
112
|
-
//
|
113
|
-
// Modification Log:
|
114
|
-
// Date Initial Description
|
115
|
-
// 26 May 2008 TKO Created by Tanny O'Haley
|
116
|
-
|
117
|
-
/*global addEvent, escape, unescape */
|
118
|
-
|
119
|
-
var domReadyEvent = {
|
120
|
-
name: "domReadyEvent",
|
121
|
-
// Array of DOMContentLoaded event handlers.
|
122
|
-
events: {},
|
123
|
-
domReadyID: 1,
|
124
|
-
bDone: false,
|
125
|
-
DOMContentLoadedCustom: null,
|
126
|
-
|
127
|
-
// Function that adds DOMContentLoaded listeners to the array.
|
128
|
-
add: function(handler) {
|
129
|
-
// Assign each event handler a unique ID. If the handler has an ID, it
|
130
|
-
// has already been added to the events object or been run.
|
131
|
-
if (!handler.$$domReadyID) {
|
132
|
-
handler.$$domReadyID = this.domReadyID++;
|
133
|
-
|
134
|
-
// If the DOMContentLoaded event has happened, run the function.
|
135
|
-
if(this.bDone){
|
136
|
-
handler();
|
137
|
-
}
|
138
|
-
|
139
|
-
// store the event handler in the hash table
|
140
|
-
this.events[handler.$$domReadyID] = handler;
|
141
|
-
}
|
142
|
-
},
|
143
|
-
|
144
|
-
remove: function(handler) {
|
145
|
-
// Delete the event handler from the hash table
|
146
|
-
if (handler.$$domReadyID) {
|
147
|
-
delete this.events[handler.$$domReadyID];
|
148
|
-
}
|
149
|
-
},
|
150
|
-
|
151
|
-
// Function to process the DOMContentLoaded events array.
|
152
|
-
run: function() {
|
153
|
-
// quit if this function has already been called
|
154
|
-
if (this.bDone) {
|
155
|
-
return;
|
156
|
-
}
|
157
|
-
|
158
|
-
// Flag this function so we don't do the same thing twice
|
159
|
-
this.bDone = true;
|
160
|
-
|
161
|
-
// iterates through array of registered functions
|
162
|
-
for (var i in this.events) {
|
163
|
-
this.events[i]();
|
164
|
-
}
|
165
|
-
},
|
166
|
-
|
167
|
-
schedule: function() {
|
168
|
-
// Quit if the init function has already been called
|
169
|
-
if (this.bDone) {
|
170
|
-
return;
|
171
|
-
}
|
172
|
-
|
173
|
-
// First, check for Safari or KHTML.
|
174
|
-
if(/KHTML|WebKit/i.test(navigator.userAgent)) {
|
175
|
-
if(/loaded|complete/.test(document.readyState)) {
|
176
|
-
this.run();
|
177
|
-
} else {
|
178
|
-
// Not ready yet, wait a little more.
|
179
|
-
setTimeout(this.name + ".schedule()", 100);
|
180
|
-
}
|
181
|
-
} else if(document.getElementById("__ie_onload")) {
|
182
|
-
// Second, check for IE.
|
183
|
-
return true;
|
184
|
-
}
|
185
|
-
|
186
|
-
// Check for custom developer provided function.
|
187
|
-
if(typeof this.DOMContentLoadedCustom === "function") {
|
188
|
-
//if DOM methods are supported, and the body element exists
|
189
|
-
//(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1]
|
190
|
-
//in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
|
191
|
-
if(typeof document.getElementsByTagName !== 'undefined' && (document.getElementsByTagName('body')[0] !== null || document.body !== null)) {
|
192
|
-
// Call custom function.
|
193
|
-
if(this.DOMContentLoadedCustom()) {
|
194
|
-
this.run();
|
195
|
-
} else {
|
196
|
-
// Not ready yet, wait a little more.
|
197
|
-
setTimeout(this.name + ".schedule()", 250);
|
198
|
-
}
|
199
|
-
}
|
200
|
-
}
|
201
|
-
|
202
|
-
return true;
|
203
|
-
},
|
204
|
-
|
205
|
-
init: function() {
|
206
|
-
// If addEventListener supports the DOMContentLoaded event.
|
207
|
-
if(document.addEventListener) {
|
208
|
-
document.addEventListener("DOMContentLoaded", function() { domReadyEvent.run(); }, false);
|
209
|
-
}
|
210
|
-
|
211
|
-
// Schedule to run the init function.
|
212
|
-
setTimeout("domReadyEvent.schedule()", 100);
|
213
|
-
|
214
|
-
function run() {
|
215
|
-
domReadyEvent.run();
|
216
|
-
}
|
217
|
-
|
218
|
-
// Just in case window.onload happens first, add it to onload using an available method.
|
219
|
-
if(typeof addEvent !== "undefined") {
|
220
|
-
addEvent(window, "load", run);
|
221
|
-
} else if(document.addEventListener) {
|
222
|
-
document.addEventListener("load", run, false);
|
223
|
-
} else if(typeof window.onload === "function") {
|
224
|
-
var oldonload = window.onload;
|
225
|
-
window.onload = function() {
|
226
|
-
domReadyEvent.run();
|
227
|
-
oldonload();
|
228
|
-
};
|
229
|
-
} else {
|
230
|
-
window.onload = run;
|
231
|
-
}
|
232
|
-
|
233
|
-
/* for Internet Explorer */
|
234
|
-
/*@cc_on
|
235
|
-
@if (@_win32 || @_win64)
|
236
|
-
document.write("<script id=__ie_onload defer src=\"//:\"><\/script>");
|
237
|
-
var script = document.getElementById("__ie_onload");
|
238
|
-
script.onreadystatechange = function() {
|
239
|
-
if (this.readyState == "complete") {
|
240
|
-
domReadyEvent.run(); // call the onload handler
|
241
|
-
}
|
242
|
-
};
|
243
|
-
@end
|
244
|
-
@*/
|
245
|
-
}
|
246
|
-
};
|
247
|
-
|
248
|
-
var domReady = function(handler) { domReadyEvent.add(handler); };
|
249
|
-
domReadyEvent.init();
|
@@ -1 +0,0 @@
|
|
1
|
-
var domReady = function(handler) { document.observe('dom:loaded', handler); };
|
@@ -1,6 +0,0 @@
|
|
1
|
-
# To enable DOM-ready functionality, be sure the <head> of your layout contains:
|
2
|
-
# <script type="text/javascript" src="/javascripts/dom_ready.js"></script>
|
3
|
-
# <script type="text/javascript" src="/javascripts/unobtrusive.js"></script>
|
4
|
-
dom_ready do
|
5
|
-
# The contents of this block will be executed when the DOM is finished loading.
|
6
|
-
end
|
data/lib/red/assignment_nodes.rb
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
module Red
|
2
|
-
class AssignmentNode # :nodoc:
|
3
|
-
def initialize(variable_name, expression)
|
4
|
-
raise(BuildError::NoMultilineAssignment, "Multiline assignment (e.g. foo = begin; line1; line2; end) is not supported") if expression.first == :block
|
5
|
-
@variable_name, @expression = [variable_name, expression].build_nodes
|
6
|
-
end
|
7
|
-
|
8
|
-
def compile_internals(options = {})
|
9
|
-
return [@variable_name, @expression].compile_nodes(:as_argument => true)
|
10
|
-
end
|
11
|
-
|
12
|
-
def compile_increment(options = {})
|
13
|
-
return "%s%s" % [options[:receiver] || @variable_name.compile_node, @expression.increment_operator * 2]
|
14
|
-
end
|
15
|
-
|
16
|
-
def call_to_increment?
|
17
|
-
return @expression.increment_operator rescue false
|
18
|
-
end
|
19
|
-
|
20
|
-
class ClassVariableNode < AssignmentNode # :nodoc:
|
21
|
-
def compile_node(options = {})
|
22
|
-
expression = @expression.compile_node(:as_argument => true)
|
23
|
-
if options[:as_prototype]
|
24
|
-
receiver = @variable_name.compile_node
|
25
|
-
"%s: %s"
|
26
|
-
else
|
27
|
-
receiver = "%s.%s" % [@@red_class, @variable_name.compile_node]
|
28
|
-
return self.compile_increment(:receiver => receiver) if self.call_to_increment?
|
29
|
-
"%s = %s"
|
30
|
-
end % [receiver, expression]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class GlobalVariableNode < AssignmentNode # :nodoc:
|
35
|
-
def compile_node(options = {})
|
36
|
-
return self.compile_increment if self.call_to_increment?
|
37
|
-
return "%s = %s" % self.compile_internals
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class InstanceVariableNode < AssignmentNode # :nodoc:
|
42
|
-
def compile_node(options = {})
|
43
|
-
receiver = "this.%s" % @variable_name.compile_node
|
44
|
-
return self.compile_increment(:receiver => receiver) if self.call_to_increment?
|
45
|
-
return "%s = %s" % [receiver, @expression.compile_node(:as_argument => true)]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class LocalVariableNode < AssignmentNode # :nodoc:
|
50
|
-
def compile_node(options = {})
|
51
|
-
return self.compile_increment if self.call_to_increment?
|
52
|
-
return (@variable_name.is_a?(LiteralNode::NamespaceNode) || options[:skip_var] ? "%s = %s" : "var %s = %s") % self.compile_internals
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class AttributeNode # :nodoc:
|
57
|
-
def initialize(variable_name, slot_equals, arguments)
|
58
|
-
@variable_name, @expression = [variable_name, arguments.last].build_nodes
|
59
|
-
@slot = (slot_equals == :[]= ? arguments[1] : slot_equals.to_s.gsub(/=/,'').to_sym).build_node
|
60
|
-
end
|
61
|
-
|
62
|
-
def compile_node(options = {})
|
63
|
-
return "%s = %s" % compile_internals
|
64
|
-
end
|
65
|
-
|
66
|
-
def compile_internals(options = {})
|
67
|
-
expression = @expression.compile_node(:as_argument => true)
|
68
|
-
receiver = self.compile_receiver
|
69
|
-
return [receiver, expression]
|
70
|
-
end
|
71
|
-
|
72
|
-
def compile_receiver
|
73
|
-
variable_name = @variable_name.compile_node
|
74
|
-
if [:symbol, :string].include?((@slot.data_type rescue :node))
|
75
|
-
slot = @slot.compile_node(:quotes => '')
|
76
|
-
"%s.%s"
|
77
|
-
else
|
78
|
-
slot = @slot.compile_node
|
79
|
-
"%s[%s]"
|
80
|
-
end % [variable_name, slot]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class OperatorNode # :nodoc:
|
85
|
-
def compile_node(options = {})
|
86
|
-
return self.compile_increment if self.call_to_increment?
|
87
|
-
return "%s%s = %s %s %s" % self.compile_internals
|
88
|
-
end
|
89
|
-
|
90
|
-
def compile_increment(options = {})
|
91
|
-
receiver, operation = [@receiver, @operation].compile_nodes
|
92
|
-
slot = @slot.compile_node(:quotes => '')
|
93
|
-
original = self.compile_receiver(receiver, slot)
|
94
|
-
return "%s%s" % [original, operation * 2]
|
95
|
-
end
|
96
|
-
|
97
|
-
def compile_internals(options = {})
|
98
|
-
receiver, operation = [@receiver, @operation].compile_nodes
|
99
|
-
expression = @expression.compile_node(:as_argument => true)
|
100
|
-
slot = @slot.compile_node(:quotes => '')
|
101
|
-
original = self.compile_receiver(receiver, slot)
|
102
|
-
var = (self.var? rescue nil)
|
103
|
-
return [var, original, original, operation, expression]
|
104
|
-
end
|
105
|
-
|
106
|
-
def call_to_increment?
|
107
|
-
return ['+', '-'].include?(@operation.compile_node) && @expression.compile_node == '1'
|
108
|
-
end
|
109
|
-
|
110
|
-
class BracketNode < OperatorNode # :nodoc:
|
111
|
-
def initialize(receiver, bracket_contents, operation, expression)
|
112
|
-
@receiver, @slot, @operation, @expression = [receiver, bracket_contents.last, operation, expression].build_nodes
|
113
|
-
end
|
114
|
-
|
115
|
-
def compile_receiver(receiver, slot)
|
116
|
-
if [:symbol, :string].include?((@slot.data_type rescue :node))
|
117
|
-
"%s.%s"
|
118
|
-
else
|
119
|
-
slot = @slot.compile_node(:quotes => "'")
|
120
|
-
"%s[%s]"
|
121
|
-
end % [receiver, slot]
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
class DotNode < OperatorNode # :nodoc:
|
126
|
-
def initialize(receiver, slot_equals, operation, expression)
|
127
|
-
@receiver, @slot, @operation, @expression = [receiver, slot_equals.to_s.gsub(/=/,''), operation, expression].build_nodes
|
128
|
-
end
|
129
|
-
|
130
|
-
def compile_receiver(receiver, slot)
|
131
|
-
return "%s.%s" % [receiver, slot]
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
class OrNode < OperatorNode # :nodoc:
|
136
|
-
def initialize(receiver, assignment_node_array)
|
137
|
-
@receiver, @slot, @operation, @expression = [receiver, nil, %s(||), assignment_node_array.last].build_nodes
|
138
|
-
end
|
139
|
-
|
140
|
-
def compile_receiver(receiver, slot)
|
141
|
-
return "%s" % [receiver]
|
142
|
-
end
|
143
|
-
|
144
|
-
def var?
|
145
|
-
return "var " unless [VariableNode::GlobalVariableNode, VariableNode::InstanceVariableNode, VariableNode::ClassVariableNode].include?(@receiver.class)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
class AndNode < OperatorNode # :nodoc:
|
150
|
-
def initialize(receiver, assignment_node_array)
|
151
|
-
@receiver, @slot, @operation, @expression = [receiver, nil, %s(&&), assignment_node_array.last].build_nodes
|
152
|
-
end
|
153
|
-
|
154
|
-
def compile_receiver(receiver, slot)
|
155
|
-
return "%s" % [receiver]
|
156
|
-
end
|
157
|
-
|
158
|
-
def var?
|
159
|
-
return "var " unless [VariableNode::GlobalVariableNode, VariableNode::InstanceVariableNode, VariableNode::ClassVariableNode].include?(@receiver.class)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
data/lib/red/call_nodes.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
module Red
|
2
|
-
class CallNode # :nodoc:
|
3
|
-
class BlockNode # :nodoc:
|
4
|
-
def initialize(receiver, arguments_array, expression = nil)
|
5
|
-
@receiver, @expression = [receiver, expression].build_nodes
|
6
|
-
@arguments = (((arguments_array ||= []).first == :masgn) ? arguments_array.assoc(:array)[1..-1].map {|node| node.last} : [arguments_array.last]).build_nodes
|
7
|
-
end
|
8
|
-
|
9
|
-
def compile_node(options = {})
|
10
|
-
receiver = @receiver.compile_node.gsub(/\(\)$/,'')
|
11
|
-
arguments = @arguments.compile_nodes.join(', ')
|
12
|
-
expression = @expression.compile_node
|
13
|
-
case receiver.to_sym
|
14
|
-
when :lambda, :function, :proc
|
15
|
-
"function(%s) { %s }" % [arguments, expression]
|
16
|
-
else
|
17
|
-
"%s(function(%s) { %s })" % [receiver, arguments, expression]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class MatchNode # :nodoc:
|
23
|
-
def initialize(regex, expression)
|
24
|
-
@regex, @expression = [regex, expression].build_nodes
|
25
|
-
end
|
26
|
-
|
27
|
-
def compile_node(options = {}) # :nodoc:
|
28
|
-
regex = @regex.compile_node
|
29
|
-
expression = @expression.compile_node(:as_argument => true)
|
30
|
-
"%s.match(%s)" % [regex, expression]
|
31
|
-
end
|
32
|
-
|
33
|
-
class ReverseNode < MatchNode # :nodoc:
|
34
|
-
def initialize(expression, regex)
|
35
|
-
@regex, @expression = [regex, expression].build_nodes
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class MethodNode # :nodoc:
|
41
|
-
def compile_node(options = {})
|
42
|
-
receiver = @receiver.compile_node
|
43
|
-
function = @function.compile_node(:quotes => '')
|
44
|
-
arguments = @arguments.compile_nodes(:as_argument => true, :quotes => "'")
|
45
|
-
return ("$%s(%s)" % [receiver = ((receiver == '$-') || (receiver == 'id' && @@red_library == :Prototype) ? nil : receiver), arguments.first]).gsub('$$','$').gsub('$class','$$') if @receiver.is_a?(VariableNode::GlobalVariableNode) && function == '-'
|
46
|
-
case function.to_sym
|
47
|
-
when :-, :+, :<, :>, :>=, :<=, :%, :*, :/, :^, :==, :===, :instanceof, :in
|
48
|
-
"(%s %s %s)" % [receiver, function, arguments.first]
|
49
|
-
when :raise
|
50
|
-
"throw(%s)" % [arguments.first]
|
51
|
-
when :new
|
52
|
-
"new %s(%s)" % [receiver, arguments.join(', ')]
|
53
|
-
when :var
|
54
|
-
"var %s" % [arguments.join(', ')]
|
55
|
-
when :[]
|
56
|
-
if ([:symbol, :string].include?(@arguments.first.data_type) rescue false)
|
57
|
-
arguments = @arguments.compile_nodes(:quotes => "", :as_argument => true)
|
58
|
-
"%s.%s"
|
59
|
-
else
|
60
|
-
"%s[%s]"
|
61
|
-
end % [receiver, arguments.first]
|
62
|
-
when :_
|
63
|
-
"%s(%s)" % [receiver, arguments]
|
64
|
-
else
|
65
|
-
receiver += '.' unless receiver.empty?
|
66
|
-
"%s%s(%s)" % [receiver, function, arguments.join(', ')]
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def increment_operator
|
71
|
-
return @function.compile_node if ['+', '-'].include?(@function.compile_node) && @arguments.first.compile_node == '1'
|
72
|
-
end
|
73
|
-
|
74
|
-
class ExplicitNode < MethodNode # :nodoc:
|
75
|
-
def initialize(receiver, function, arguments = [nil])
|
76
|
-
@receiver, @function = [receiver, function].build_nodes
|
77
|
-
@arguments = arguments[1..-1].build_nodes
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class ImplicitNode < MethodNode # :nodoc:
|
82
|
-
def initialize(function, arguments = [nil])
|
83
|
-
@function = function.build_node
|
84
|
-
@receiver = (:self if @function.compile_node == '[]').build_node
|
85
|
-
@arguments = arguments[1..-1].build_nodes
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Red
|
2
|
-
class ConditionalNode # :nodoc:
|
3
|
-
class IfNode # :nodoc:
|
4
|
-
def initialize(condition, true_case, else_case)
|
5
|
-
@condition, @true_case, @else_case = [condition, true_case, else_case].build_nodes
|
6
|
-
end
|
7
|
-
|
8
|
-
def compile_node(options = {})
|
9
|
-
unless options[:as_argument]
|
10
|
-
"if (%s) %s%s%s"
|
11
|
-
else
|
12
|
-
"(%s ? %s : %s)"
|
13
|
-
end % self.compile_internals(options)
|
14
|
-
end
|
15
|
-
|
16
|
-
def compile_internals(options = {})
|
17
|
-
true_case, else_case, condition = [@true_case, @else_case, @condition].compile_nodes
|
18
|
-
return [condition, (true_case.empty? ? 'null' : @true_case.compile_node(:as_argument => true)), (else_case.empty? ? 'null' : @else_case.compile_node(:as_argument => true))] if options[:as_argument]
|
19
|
-
condition = (true_case.empty? ? "!(%s)" : "%s") % [condition]
|
20
|
-
true_case = "{ %s; }" % [true_case] unless true_case.empty?
|
21
|
-
join = " else " unless true_case.empty? || else_case.empty?
|
22
|
-
else_case = "{ %s; }" % [else_case] unless else_case.empty?
|
23
|
-
return [condition, true_case, join, else_case]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class CaseNode # :nodoc:
|
28
|
-
def initialize(switch, *cases)
|
29
|
-
@switch, @else_case = [switch, cases.pop].build_nodes
|
30
|
-
@when_cases = cases.build_nodes
|
31
|
-
end
|
32
|
-
|
33
|
-
def compile_node(options = {})
|
34
|
-
return "switch (%s) { %s%s }" % self.compile_internals
|
35
|
-
end
|
36
|
-
|
37
|
-
def compile_internals(options = {})
|
38
|
-
switch, else_case = [@switch, @else_case].compile_nodes
|
39
|
-
when_cases = @when_cases.compile_nodes.join
|
40
|
-
default = "default:%s;" % [else_case] unless else_case.empty?
|
41
|
-
return [switch, when_cases, default]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class WhenNode # :nodoc:
|
46
|
-
def initialize(conditions, expression)
|
47
|
-
@conditions = conditions[1..-1].build_nodes
|
48
|
-
@expression = expression.build_node
|
49
|
-
end
|
50
|
-
|
51
|
-
def compile_node(options = {})
|
52
|
-
return "case %s:%s;%s" % self.compile_internals
|
53
|
-
end
|
54
|
-
|
55
|
-
def compile_internals(options = {})
|
56
|
-
condition = @conditions.first.compile_node(:quotes => "'")
|
57
|
-
expression = @expression.compile_node
|
58
|
-
final = "break;"
|
59
|
-
return [condition, expression, final]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Red
|
2
|
-
class ConjunctionNode # :nodoc:
|
3
|
-
def initialize(a, b)
|
4
|
-
@a, @b = [a, b].build_nodes
|
5
|
-
end
|
6
|
-
|
7
|
-
def compile_internals(options = {})
|
8
|
-
[@a, @b].compile_nodes(:as_argument => true)
|
9
|
-
end
|
10
|
-
|
11
|
-
class AndNode < ConjunctionNode # :nodoc:
|
12
|
-
def compile_node(options = {})
|
13
|
-
return "(%s && %s)" % self.compile_internals
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class OrNode < ConjunctionNode # :nodoc:
|
18
|
-
def compile_node(options = {})
|
19
|
-
return "(%s || %s)" % self.compile_internals
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|