melbourne 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +3 -0
- data/LICENSE +27 -0
- data/README.rdoc +38 -0
- data/Rakefile +38 -0
- data/VERSION.yml +4 -0
- data/ext/melbourne/bstring-license.txt +29 -0
- data/ext/melbourne/bstrlib.c +2918 -0
- data/ext/melbourne/bstrlib.h +302 -0
- data/ext/melbourne/extconf.rb +76 -0
- data/ext/melbourne/grammar.cpp +11885 -0
- data/ext/melbourne/grammar.hpp +14 -0
- data/ext/melbourne/grammar.y +6013 -0
- data/ext/melbourne/internal.hpp +137 -0
- data/ext/melbourne/lex.c.tab +136 -0
- data/ext/melbourne/local_state.hpp +41 -0
- data/ext/melbourne/melbourne.cpp +37 -0
- data/ext/melbourne/node.hpp +262 -0
- data/ext/melbourne/node_types.cpp +245 -0
- data/ext/melbourne/node_types.hpp +135 -0
- data/ext/melbourne/node_types.rb +190 -0
- data/ext/melbourne/quark.cpp +52 -0
- data/ext/melbourne/quark.hpp +14 -0
- data/ext/melbourne/symbols.cpp +219 -0
- data/ext/melbourne/symbols.hpp +116 -0
- data/ext/melbourne/var_table.cpp +113 -0
- data/ext/melbourne/var_table.hpp +33 -0
- data/ext/melbourne/visitor.cpp +1052 -0
- data/ext/melbourne/visitor.hpp +20 -0
- data/lib/melbourne/ast/constants.rb +128 -0
- data/lib/melbourne/ast/control_flow.rb +382 -0
- data/lib/melbourne/ast/data.rb +19 -0
- data/lib/melbourne/ast/definitions.rb +561 -0
- data/lib/melbourne/ast/exceptions.rb +182 -0
- data/lib/melbourne/ast/file.rb +15 -0
- data/lib/melbourne/ast/grapher.rb +75 -0
- data/lib/melbourne/ast/literals.rb +268 -0
- data/lib/melbourne/ast/node.rb +21 -0
- data/lib/melbourne/ast/operators.rb +117 -0
- data/lib/melbourne/ast/self.rb +17 -0
- data/lib/melbourne/ast/sends.rb +451 -0
- data/lib/melbourne/ast/values.rb +74 -0
- data/lib/melbourne/ast/variables.rb +251 -0
- data/lib/melbourne/ast.rb +22 -0
- data/lib/melbourne/parser.rb +38 -0
- data/lib/melbourne/processor.rb +460 -0
- data/lib/melbourne.rb +46 -0
- data/spec/helpers/ast/node.rb +15 -0
- data/spec/helpers/ast/reduced_graph.rb +64 -0
- data/spec/lib/parser/alias_spec.rb +97 -0
- data/spec/lib/parser/and_spec.rb +63 -0
- data/spec/lib/parser/array_spec.rb +157 -0
- data/spec/lib/parser/attrasgn_spec.rb +401 -0
- data/spec/lib/parser/back_ref_spec.rb +20 -0
- data/spec/lib/parser/call_spec.rb +958 -0
- data/spec/lib/parser/case_spec.rb +577 -0
- data/spec/lib/parser/cdecl_spec.rb +108 -0
- data/spec/lib/parser/class_spec.rb +221 -0
- data/spec/lib/parser/colon2_spec.rb +13 -0
- data/spec/lib/parser/colon3_spec.rb +12 -0
- data/spec/lib/parser/const_spec.rb +12 -0
- data/spec/lib/parser/cvar_spec.rb +55 -0
- data/spec/lib/parser/cvasgn_spec.rb +71 -0
- data/spec/lib/parser/cvdecl_spec.rb +31 -0
- data/spec/lib/parser/defined_spec.rb +353 -0
- data/spec/lib/parser/defn_spec.rb +1409 -0
- data/spec/lib/parser/defs_spec.rb +247 -0
- data/spec/lib/parser/dot2_spec.rb +29 -0
- data/spec/lib/parser/dot3_spec.rb +29 -0
- data/spec/lib/parser/dregx_spec.rb +127 -0
- data/spec/lib/parser/dstr_spec.rb +453 -0
- data/spec/lib/parser/dsym_spec.rb +31 -0
- data/spec/lib/parser/dxstr_spec.rb +31 -0
- data/spec/lib/parser/ensure_spec.rb +279 -0
- data/spec/lib/parser/false_spec.rb +12 -0
- data/spec/lib/parser/flip2_spec.rb +138 -0
- data/spec/lib/parser/flip3_spec.rb +100 -0
- data/spec/lib/parser/for_spec.rb +279 -0
- data/spec/lib/parser/gasgn_spec.rb +34 -0
- data/spec/lib/parser/gvar_spec.rb +33 -0
- data/spec/lib/parser/hash_spec.rb +77 -0
- data/spec/lib/parser/iasgn_spec.rb +54 -0
- data/spec/lib/parser/if_spec.rb +439 -0
- data/spec/lib/parser/iter_spec.rb +2582 -0
- data/spec/lib/parser/lasgn_spec.rb +1066 -0
- data/spec/lib/parser/lit_spec.rb +75 -0
- data/spec/lib/parser/masgn_spec.rb +1970 -0
- data/spec/lib/parser/match2_spec.rb +47 -0
- data/spec/lib/parser/match3_spec.rb +54 -0
- data/spec/lib/parser/match_spec.rb +19 -0
- data/spec/lib/parser/module_spec.rb +102 -0
- data/spec/lib/parser/nil_spec.rb +13 -0
- data/spec/lib/parser/not_spec.rb +39 -0
- data/spec/lib/parser/nth_ref_spec.rb +12 -0
- data/spec/lib/parser/op_asgn_spec.rb +619 -0
- data/spec/lib/parser/or_spec.rb +155 -0
- data/spec/lib/parser/postexe_spec.rb +31 -0
- data/spec/lib/parser/regex_spec.rb +52 -0
- data/spec/lib/parser/rescue_spec.rb +1028 -0
- data/spec/lib/parser/return_spec.rb +151 -0
- data/spec/lib/parser/sclass_spec.rb +172 -0
- data/spec/lib/parser/str_spec.rb +162 -0
- data/spec/lib/parser/super_spec.rb +276 -0
- data/spec/lib/parser/true_spec.rb +12 -0
- data/spec/lib/parser/undef_spec.rb +222 -0
- data/spec/lib/parser/until_spec.rb +286 -0
- data/spec/lib/parser/valias_spec.rb +12 -0
- data/spec/lib/parser/while_spec.rb +458 -0
- data/spec/lib/parser/xstr_spec.rb +12 -0
- data/spec/lib/parser/yield_spec.rb +202 -0
- data/spec/lib/parser/zsuper_spec.rb +101 -0
- data/spec/matchers/parse_as.rb +27 -0
- data/spec/spec_helper.rb +10 -0
- metadata +168 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module Melbourne
|
|
2
|
+
module AST
|
|
3
|
+
class AsciiGrapher
|
|
4
|
+
def initialize(ast)
|
|
5
|
+
@ast = ast
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def print
|
|
9
|
+
graph_node @ast
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def indented_print(level, value)
|
|
13
|
+
puts "#{" " * level}#{value}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def print_node(node, level)
|
|
17
|
+
name = node.class.to_s.split("::").last
|
|
18
|
+
indented_print level, name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def graph_node(node, level=0)
|
|
22
|
+
print_node node, level
|
|
23
|
+
level += 2
|
|
24
|
+
|
|
25
|
+
nodes = []
|
|
26
|
+
node.instance_variables.each do |v|
|
|
27
|
+
next if v == "@compiler"
|
|
28
|
+
|
|
29
|
+
value = node.instance_variable_get v
|
|
30
|
+
|
|
31
|
+
# lame, yes. remove when Node doesn't have @body by default
|
|
32
|
+
next if v == "@body" and value.nil? and not v.respond_to? :body=
|
|
33
|
+
|
|
34
|
+
if value.kind_of? Node
|
|
35
|
+
nodes << [v, value]
|
|
36
|
+
else
|
|
37
|
+
graph_value v, value, level
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
nodes.each do |name, node|
|
|
42
|
+
puts "#{" " * level}#{name}: \\"
|
|
43
|
+
graph_node node, level
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def graph_simple(name, value, level)
|
|
48
|
+
puts "#{" " * level}#{name}: #{value}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def graph_value(name, value, level)
|
|
52
|
+
case value
|
|
53
|
+
when NilClass, String
|
|
54
|
+
graph_simple name, value.inspect, level
|
|
55
|
+
when TrueClass, FalseClass, Symbol, Fixnum
|
|
56
|
+
graph_simple name, value, level
|
|
57
|
+
when Array
|
|
58
|
+
puts "#{" " * level}#{name}: \\"
|
|
59
|
+
nodes = []
|
|
60
|
+
value.each do |v|
|
|
61
|
+
if v.kind_of? Node
|
|
62
|
+
nodes << v
|
|
63
|
+
else
|
|
64
|
+
graph_value "-", v, level + 2
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
nodes.each { |n| graph_node n, level + 2 }
|
|
69
|
+
else
|
|
70
|
+
graph_simple name, value.class, level
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
module Melbourne
|
|
2
|
+
|
|
3
|
+
module AST
|
|
4
|
+
|
|
5
|
+
# An array literal as in:
|
|
6
|
+
#
|
|
7
|
+
# [1, 2]
|
|
8
|
+
#
|
|
9
|
+
class ArrayLiteral < Node
|
|
10
|
+
|
|
11
|
+
# The body os the array literal (the actual values contained in the array)
|
|
12
|
+
#
|
|
13
|
+
attr_accessor :body
|
|
14
|
+
|
|
15
|
+
def initialize(line, array) #:nodoc:
|
|
16
|
+
@line = line
|
|
17
|
+
@body = array
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# An empty array literal as in:
|
|
23
|
+
#
|
|
24
|
+
# []
|
|
25
|
+
#
|
|
26
|
+
class EmptyArray < Node
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# False as in:
|
|
31
|
+
#
|
|
32
|
+
# false
|
|
33
|
+
#
|
|
34
|
+
class False < Node
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# True as in:
|
|
39
|
+
#
|
|
40
|
+
# true
|
|
41
|
+
#
|
|
42
|
+
class True < Node
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# A float literal as in:
|
|
47
|
+
#
|
|
48
|
+
# 1.2
|
|
49
|
+
#
|
|
50
|
+
class Float < Node
|
|
51
|
+
|
|
52
|
+
# The actual value of the float literal
|
|
53
|
+
#
|
|
54
|
+
attr_accessor :value
|
|
55
|
+
|
|
56
|
+
def initialize(line, str) #:nodoc:
|
|
57
|
+
@line = line
|
|
58
|
+
@value = str.to_f
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# An hash literal as in:
|
|
64
|
+
#
|
|
65
|
+
# { :a => :b }
|
|
66
|
+
#
|
|
67
|
+
class HashLiteral < Node
|
|
68
|
+
|
|
69
|
+
# The actual values in the hash literal
|
|
70
|
+
#
|
|
71
|
+
attr_accessor :array
|
|
72
|
+
|
|
73
|
+
def initialize(line, array) #:nodoc:
|
|
74
|
+
@line = line
|
|
75
|
+
@array = array
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# A symbol literal as in:
|
|
81
|
+
#
|
|
82
|
+
# :x
|
|
83
|
+
#
|
|
84
|
+
class SymbolLiteral < Node
|
|
85
|
+
|
|
86
|
+
# The value of the symbol literal
|
|
87
|
+
#
|
|
88
|
+
attr_accessor :value
|
|
89
|
+
|
|
90
|
+
def initialize(line, sym) #:nodoc:
|
|
91
|
+
@line = line
|
|
92
|
+
@value = sym
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Nil as in:
|
|
98
|
+
#
|
|
99
|
+
# nil
|
|
100
|
+
#
|
|
101
|
+
class Nil < Node
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
class NumberLiteral < Node #:nodoc:
|
|
106
|
+
|
|
107
|
+
attr_accessor :value
|
|
108
|
+
|
|
109
|
+
def initialize(line, value)
|
|
110
|
+
@line = line
|
|
111
|
+
@value = value
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# A FixNum literal as in:
|
|
117
|
+
#
|
|
118
|
+
# 1
|
|
119
|
+
#
|
|
120
|
+
class FixnumLiteral < NumberLiteral
|
|
121
|
+
|
|
122
|
+
def initialize(line, value) #:nodoc:
|
|
123
|
+
@line = line
|
|
124
|
+
@value = value
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# A range literal as in:
|
|
130
|
+
#
|
|
131
|
+
# 1..3
|
|
132
|
+
#
|
|
133
|
+
class Range < Node
|
|
134
|
+
|
|
135
|
+
# The start of the range
|
|
136
|
+
#
|
|
137
|
+
attr_accessor :start
|
|
138
|
+
|
|
139
|
+
# The finish of the range
|
|
140
|
+
#
|
|
141
|
+
attr_accessor :finish
|
|
142
|
+
|
|
143
|
+
def initialize(line, start, finish) #:nodoc:
|
|
144
|
+
@line = line
|
|
145
|
+
@start = start
|
|
146
|
+
@finish = finish
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# A range literal that excludes the end as in:
|
|
152
|
+
#
|
|
153
|
+
# 1...3
|
|
154
|
+
#
|
|
155
|
+
class RangeExclude < Range
|
|
156
|
+
|
|
157
|
+
def initialize(line, start, finish) #:nodoc:
|
|
158
|
+
@line = line
|
|
159
|
+
@start = start
|
|
160
|
+
@finish = finish
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# A regular expression literal as in:
|
|
166
|
+
#
|
|
167
|
+
# /.*/
|
|
168
|
+
#
|
|
169
|
+
class RegexLiteral < Node
|
|
170
|
+
|
|
171
|
+
# The source of the regular expression literal
|
|
172
|
+
#
|
|
173
|
+
attr_accessor :source
|
|
174
|
+
|
|
175
|
+
# Options defined for the regular expression literal (e.g. +n+ or +o+)
|
|
176
|
+
#
|
|
177
|
+
attr_accessor :options
|
|
178
|
+
|
|
179
|
+
def initialize(line, str, flags) #:nodoc:
|
|
180
|
+
@line = line
|
|
181
|
+
@source = str
|
|
182
|
+
@options = flags
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# A string literal as in:
|
|
188
|
+
#
|
|
189
|
+
# 'some'
|
|
190
|
+
#
|
|
191
|
+
class StringLiteral < Node
|
|
192
|
+
|
|
193
|
+
# The actual string of the string literal
|
|
194
|
+
#
|
|
195
|
+
attr_accessor :string
|
|
196
|
+
|
|
197
|
+
def initialize(line, str) #:nodoc:
|
|
198
|
+
@line = line
|
|
199
|
+
@string = str
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# A dynamic string literal as in:
|
|
205
|
+
#
|
|
206
|
+
# "some #{a}"
|
|
207
|
+
#
|
|
208
|
+
class DynamicString < StringLiteral
|
|
209
|
+
|
|
210
|
+
# The parts of the dynamic string literal
|
|
211
|
+
#
|
|
212
|
+
attr_accessor :array
|
|
213
|
+
|
|
214
|
+
attr_accessor :options #:nodoc:
|
|
215
|
+
|
|
216
|
+
def initialize(line, str, array) #:nodoc:
|
|
217
|
+
@line = line
|
|
218
|
+
@string = str
|
|
219
|
+
@array = array
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# A dynamic symbol literal as in:
|
|
225
|
+
#
|
|
226
|
+
# :"some#{a}"
|
|
227
|
+
#
|
|
228
|
+
class DynamicSymbol < DynamicString
|
|
229
|
+
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# A dynamic execute string literal as in:
|
|
233
|
+
#
|
|
234
|
+
# `touch #{path}`
|
|
235
|
+
#
|
|
236
|
+
class DynamicExecuteString < DynamicString
|
|
237
|
+
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# A dynamic regular expression literal as in:
|
|
241
|
+
#
|
|
242
|
+
# /.*#{a}/
|
|
243
|
+
#
|
|
244
|
+
class DynamicRegex < DynamicString
|
|
245
|
+
|
|
246
|
+
def initialize(line, str, array, flags) #:nodoc:
|
|
247
|
+
super line, str, array
|
|
248
|
+
@options = flags || 0
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# TODO: document!
|
|
254
|
+
class DynamicOnceRegex < DynamicRegex #:nodoc:
|
|
255
|
+
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# An execute string literal as in:
|
|
259
|
+
#
|
|
260
|
+
# `touch tmp/restart.txt`
|
|
261
|
+
#
|
|
262
|
+
class ExecuteString < StringLiteral
|
|
263
|
+
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
module Melbourne
|
|
2
|
+
|
|
3
|
+
module AST
|
|
4
|
+
|
|
5
|
+
# The +and+ operator as in:
|
|
6
|
+
#
|
|
7
|
+
# a and b
|
|
8
|
+
#
|
|
9
|
+
class And < Node
|
|
10
|
+
|
|
11
|
+
# The left-side expression of the +and+ operator
|
|
12
|
+
#
|
|
13
|
+
attr_accessor :left
|
|
14
|
+
|
|
15
|
+
# The right-side expression of the +and+ operator
|
|
16
|
+
#
|
|
17
|
+
attr_accessor :right
|
|
18
|
+
|
|
19
|
+
def initialize(line, left, right) #:nodoc:
|
|
20
|
+
@line = line
|
|
21
|
+
@left = left
|
|
22
|
+
@right = right
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# The +or+ operator as in:
|
|
28
|
+
#
|
|
29
|
+
# a or b
|
|
30
|
+
#
|
|
31
|
+
class Or < And
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# The +not+ operator as in:
|
|
36
|
+
#
|
|
37
|
+
# (not true)
|
|
38
|
+
#
|
|
39
|
+
class Not < Node
|
|
40
|
+
|
|
41
|
+
# The value that is negated
|
|
42
|
+
#
|
|
43
|
+
attr_accessor :value
|
|
44
|
+
|
|
45
|
+
def initialize(line, value) #:nodoc:
|
|
46
|
+
@line = line
|
|
47
|
+
@value = value
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# TODO: document!
|
|
53
|
+
class OpAssign1 < Node #:nodoc:
|
|
54
|
+
|
|
55
|
+
attr_accessor :receiver
|
|
56
|
+
|
|
57
|
+
attr_accessor :op
|
|
58
|
+
|
|
59
|
+
attr_accessor :index
|
|
60
|
+
|
|
61
|
+
attr_accessor :value
|
|
62
|
+
|
|
63
|
+
def initialize(line, receiver, index, op, value)
|
|
64
|
+
@line = line
|
|
65
|
+
@receiver = receiver
|
|
66
|
+
@op = op
|
|
67
|
+
@index = index.body
|
|
68
|
+
@value = value
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# TODO: document!
|
|
74
|
+
class OpAssign2 < Node #:nodoc:
|
|
75
|
+
|
|
76
|
+
attr_accessor :receiver
|
|
77
|
+
|
|
78
|
+
attr_accessor :op
|
|
79
|
+
|
|
80
|
+
attr_accessor :name
|
|
81
|
+
|
|
82
|
+
attr_accessor :assign
|
|
83
|
+
|
|
84
|
+
attr_accessor :value
|
|
85
|
+
|
|
86
|
+
def initialize(line, receiver, name, op, value)
|
|
87
|
+
@line = line
|
|
88
|
+
@receiver = receiver
|
|
89
|
+
@name = name
|
|
90
|
+
@op = op
|
|
91
|
+
@value = value
|
|
92
|
+
@assign = name.to_s[-1] == ?= ? name : :"#{name}="
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# TODO: document!
|
|
98
|
+
class OpAssignAnd < Node #:nodoc:
|
|
99
|
+
|
|
100
|
+
attr_accessor :left, :right
|
|
101
|
+
|
|
102
|
+
def initialize(line, left, right)
|
|
103
|
+
@line = line
|
|
104
|
+
@left = left
|
|
105
|
+
@right = right
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# TODO: document!
|
|
111
|
+
class OpAssignOr < OpAssignAnd #:nodoc:
|
|
112
|
+
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|