red 3.4.2 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/lib/red/assignment_nodes.rb +16 -5
- data/lib/red/call_nodes.rb +6 -6
- data/lib/red/conjunction_nodes.rb +2 -2
- data/lib/red/definition_nodes.rb +14 -3
- data/lib/red/literal_nodes.rb +2 -2
- data/lib/red/version.rb +2 -2
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 3.5.0 2008-08-13
|
2
|
+
|
3
|
+
* 2 major enhancements:
|
4
|
+
* Added support for child classes.
|
5
|
+
* Updated method for "call to returned function"; now use "_".
|
6
|
+
|
7
|
+
* 3 bug fixes:
|
8
|
+
* Fixed Prototype library's handling of class_variables; now separated out into an Object.extend declaration.
|
9
|
+
* String quoting is now properly handled in foo["eval#{string}"]-type calls.
|
10
|
+
* Added parentheses wrapping to sugared operators ('+', '*', '||', '&&', etc) in order to solve chained method problems.
|
11
|
+
|
1
12
|
== 3.4.2 2008-08-12
|
2
13
|
|
3
14
|
* 1 major enhancement:
|
data/lib/red/assignment_nodes.rb
CHANGED
@@ -64,14 +64,20 @@ module Red
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def compile_internals(options = {})
|
67
|
-
variable_name, slot = [@variable_name, @slot].compile_nodes(:quotes => '')
|
68
67
|
expression = @expression.compile_node(:as_argument => true)
|
69
|
-
receiver = self.compile_receiver
|
68
|
+
receiver = self.compile_receiver
|
70
69
|
return [receiver, expression]
|
71
70
|
end
|
72
71
|
|
73
|
-
def compile_receiver
|
74
|
-
|
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]
|
75
81
|
end
|
76
82
|
end
|
77
83
|
|
@@ -107,7 +113,12 @@ module Red
|
|
107
113
|
end
|
108
114
|
|
109
115
|
def compile_receiver(receiver, slot)
|
110
|
-
|
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]
|
111
122
|
end
|
112
123
|
end
|
113
124
|
|
data/lib/red/call_nodes.rb
CHANGED
@@ -39,13 +39,13 @@ module Red
|
|
39
39
|
|
40
40
|
class MethodNode # :nodoc:
|
41
41
|
def compile_node(options = {})
|
42
|
-
|
43
|
-
|
42
|
+
receiver = @receiver.compile_node
|
43
|
+
function = @function.compile_node(:quotes => '')
|
44
44
|
arguments = @arguments.compile_nodes(:as_argument => true, :quotes => "'")
|
45
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
46
|
case function.to_sym
|
47
|
-
when :-, :+, :<, :>, :>=, :<=, :%, :*, :/, :^, :==, :===, :instanceof
|
48
|
-
"%s %s %s" % [receiver, function, arguments.first]
|
47
|
+
when :-, :+, :<, :>, :>=, :<=, :%, :*, :/, :^, :==, :===, :instanceof, :in
|
48
|
+
"(%s %s %s)" % [receiver, function, arguments.first]
|
49
49
|
when :raise
|
50
50
|
"throw(%s)" % [arguments.first]
|
51
51
|
when :new
|
@@ -59,8 +59,8 @@ module Red
|
|
59
59
|
else
|
60
60
|
"%s[%s]"
|
61
61
|
end % [receiver, arguments.first]
|
62
|
-
when
|
63
|
-
"
|
62
|
+
when :_
|
63
|
+
"%s(%s)" % [receiver, arguments]
|
64
64
|
else
|
65
65
|
receiver += '.' unless receiver.empty?
|
66
66
|
"%s%s(%s)" % [receiver, function, arguments.join(', ')]
|
@@ -10,13 +10,13 @@ module Red
|
|
10
10
|
|
11
11
|
class AndNode < ConjunctionNode # :nodoc:
|
12
12
|
def compile_node(options = {})
|
13
|
-
return "%s && %s" % self.compile_internals
|
13
|
+
return "(%s && %s)" % self.compile_internals
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
class OrNode < ConjunctionNode # :nodoc:
|
18
18
|
def compile_node(options = {})
|
19
|
-
return "%s || %s" % self.compile_internals
|
19
|
+
return "(%s || %s)" % self.compile_internals
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/red/definition_nodes.rb
CHANGED
@@ -10,6 +10,7 @@ module Red
|
|
10
10
|
case @@red_library
|
11
11
|
when :Prototype
|
12
12
|
@initializer = block_node.rassoc(:initialize)
|
13
|
+
@classes = block_node.select {|node| (node.first == :class) rescue false }.build_nodes
|
13
14
|
@properties = block_node.select {|node| (node.first == :cvdecl) rescue false }.build_nodes
|
14
15
|
@functions = block_node.select {|node| ![:block, :scope].include?(node) && ((node.first != :cvdecl) rescue false) }.build_nodes
|
15
16
|
else
|
@@ -18,6 +19,7 @@ module Red
|
|
18
19
|
@arguments = (args_node[1..-1] || []).build_nodes
|
19
20
|
@initializer = initializer_node.assoc(:scope).assoc(:block).reject {|node| node == args_node}.build_node
|
20
21
|
end
|
22
|
+
@classes = block_node.select {|node| (node.first == :class) rescue false }.build_nodes
|
21
23
|
@properties = block_node.select {|node| (node.first == :cvdecl) rescue false }.build_nodes
|
22
24
|
@functions = block_node.select {|node| (node != initializer_node) && ![:block, :scope].include?(node) && ((node.first != :cvdecl) rescue false) }.build_nodes
|
23
25
|
end
|
@@ -27,7 +29,9 @@ module Red
|
|
27
29
|
def compile_node(options = {})
|
28
30
|
old_class = @@red_class
|
29
31
|
@@red_class = @class
|
30
|
-
if
|
32
|
+
if options[:as_prototype]
|
33
|
+
output = self.compile_as_child_class
|
34
|
+
elsif @initializer
|
31
35
|
case @@red_library
|
32
36
|
when :Prototype
|
33
37
|
output = self.compile_as_prototype_class
|
@@ -41,10 +45,17 @@ module Red
|
|
41
45
|
return output
|
42
46
|
end
|
43
47
|
|
48
|
+
def compile_as_child_class
|
49
|
+
class_name = @class_name.compile_node
|
50
|
+
slots = (@classes | @properties | @functions).compile_nodes(:as_prototype => true).compact.join(', ')
|
51
|
+
return "%s: { %s }" % [class_name, slots]
|
52
|
+
end
|
53
|
+
|
44
54
|
def compile_as_prototype_class
|
45
55
|
class_name = @class_name.compile_node
|
46
|
-
|
47
|
-
|
56
|
+
functions = @functions.compile_nodes(:as_prototype => true).compact.join(', ')
|
57
|
+
properties = @properties.compile_nodes(:as_prototype => true).compact.join(', ')
|
58
|
+
return "%s%s = Class.create({ %s });Object.extend(%s, { %s })" % [self.var?, class_name, functions, class_name, properties]
|
48
59
|
end
|
49
60
|
|
50
61
|
def compile_as_standard_class(options = {})
|
data/lib/red/literal_nodes.rb
CHANGED
@@ -15,7 +15,7 @@ module Red
|
|
15
15
|
case @initial
|
16
16
|
when DataNode::NilNode : :nil
|
17
17
|
when DataNode::RangeNode : :range
|
18
|
-
when DataNode::StringNode : :string
|
18
|
+
when DataNode::StringNode : (@subsequent.empty? ? :string : :eval)
|
19
19
|
when DataNode::SymbolNode : :symbol
|
20
20
|
else @initial.value.is_a?(Numeric) ? :numeric : :regexp
|
21
21
|
end
|
@@ -23,7 +23,7 @@ module Red
|
|
23
23
|
|
24
24
|
class ArrayNode < LiteralNode # :nodoc:
|
25
25
|
def compile_node(options = {})
|
26
|
-
elements = @subsequent.unshift(@initial).compile_nodes.join(', ')
|
26
|
+
elements = @subsequent.unshift(@initial).compile_nodes.reject {|element| element.empty? }.join(', ')
|
27
27
|
return "[%s]" % [elements]
|
28
28
|
end
|
29
29
|
end
|
data/lib/red/version.rb
CHANGED
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: 3.
|
4
|
+
version: 3.5.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-08-
|
12
|
+
date: 2008-08-13 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|