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,251 @@
|
|
|
1
|
+
module Melbourne
|
|
2
|
+
|
|
3
|
+
module AST
|
|
4
|
+
|
|
5
|
+
# A back reference as in:
|
|
6
|
+
#
|
|
7
|
+
# $&
|
|
8
|
+
#
|
|
9
|
+
# or
|
|
10
|
+
#
|
|
11
|
+
# $'
|
|
12
|
+
#
|
|
13
|
+
class BackRef < Node
|
|
14
|
+
|
|
15
|
+
# The kind of back reference
|
|
16
|
+
#
|
|
17
|
+
attr_accessor :kind
|
|
18
|
+
|
|
19
|
+
def initialize(line, ref) #:nodoc:
|
|
20
|
+
@line = line
|
|
21
|
+
@kind = ref
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# A reference to the nth match in a regular expression match result as in:
|
|
27
|
+
#
|
|
28
|
+
# $1
|
|
29
|
+
#
|
|
30
|
+
class NthRef < Node
|
|
31
|
+
|
|
32
|
+
# The number of the match that is referenced
|
|
33
|
+
#
|
|
34
|
+
attr_accessor :which
|
|
35
|
+
|
|
36
|
+
def initialize(line, ref) #:nodoc:
|
|
37
|
+
@line = line
|
|
38
|
+
@which = ref
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class VariableAccess < Node #:nodoc:
|
|
44
|
+
|
|
45
|
+
attr_accessor :name
|
|
46
|
+
|
|
47
|
+
def initialize(line, name)
|
|
48
|
+
@line = line
|
|
49
|
+
@name = name
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class VariableAssignment < Node #:nodoc:
|
|
55
|
+
|
|
56
|
+
attr_accessor :name, :value
|
|
57
|
+
|
|
58
|
+
def initialize(line, name, value)
|
|
59
|
+
@line = line
|
|
60
|
+
@name = name
|
|
61
|
+
@value = value
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Access of a class variable as in:
|
|
67
|
+
#
|
|
68
|
+
# puts @@var
|
|
69
|
+
#
|
|
70
|
+
class ClassVariableAccess < VariableAccess
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# An assignment to a class variable as in:
|
|
75
|
+
#
|
|
76
|
+
# @@var = 1
|
|
77
|
+
#
|
|
78
|
+
class ClassVariableAssignment < VariableAssignment
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class CVarDeclare < ClassVariableAssignment #:nodoc:
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Access of a global variable as in:
|
|
87
|
+
#
|
|
88
|
+
# $stderr
|
|
89
|
+
#
|
|
90
|
+
class GlobalVariableAccess < VariableAccess
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Assignment to a global variable as in:
|
|
95
|
+
#
|
|
96
|
+
# $x = 1
|
|
97
|
+
#
|
|
98
|
+
class GlobalVariableAssignment < VariableAssignment
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Assignment to a splat (<tt>*some</tt>) as in:
|
|
103
|
+
#
|
|
104
|
+
# *c = *[1, 2]
|
|
105
|
+
#
|
|
106
|
+
class SplatAssignment < Node
|
|
107
|
+
|
|
108
|
+
# The value being assigned to the splat
|
|
109
|
+
#
|
|
110
|
+
attr_accessor :value
|
|
111
|
+
|
|
112
|
+
def initialize(line, value) #:nodoc:
|
|
113
|
+
@line = line
|
|
114
|
+
@value = value
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
class SplatArray < SplatAssignment #:nodoc:
|
|
120
|
+
|
|
121
|
+
def initialize(line, value, size)
|
|
122
|
+
@line = line
|
|
123
|
+
@value = value
|
|
124
|
+
@size = size
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
class SplatWrapped < SplatAssignment #:nodoc:
|
|
130
|
+
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# An empty splat as in:
|
|
134
|
+
#
|
|
135
|
+
# * = 1, 2
|
|
136
|
+
#
|
|
137
|
+
class EmptySplat < Node
|
|
138
|
+
|
|
139
|
+
def initialize(line, size) #:nodoc:
|
|
140
|
+
@line = line
|
|
141
|
+
@size = size
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Access of an instance variable as in:
|
|
147
|
+
#
|
|
148
|
+
# puts @var
|
|
149
|
+
#
|
|
150
|
+
class InstanceVariableAccess < VariableAccess
|
|
151
|
+
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# An assignment to an instance variable as in:
|
|
155
|
+
#
|
|
156
|
+
# @var = 1
|
|
157
|
+
#
|
|
158
|
+
class InstanceVariableAssignment < VariableAssignment
|
|
159
|
+
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Access of a local variable as in:
|
|
163
|
+
#
|
|
164
|
+
# puts var
|
|
165
|
+
#
|
|
166
|
+
class LocalVariableAccess < VariableAccess
|
|
167
|
+
|
|
168
|
+
include LocalVariable
|
|
169
|
+
|
|
170
|
+
def initialize(line, name) #:nodoc:
|
|
171
|
+
@line = line
|
|
172
|
+
@name = name
|
|
173
|
+
@variable = nil
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# An assignment to an instance variable as in:
|
|
179
|
+
#
|
|
180
|
+
# var = 1
|
|
181
|
+
#
|
|
182
|
+
class LocalVariableAssignment < VariableAssignment
|
|
183
|
+
|
|
184
|
+
include LocalVariable
|
|
185
|
+
|
|
186
|
+
def initialize(line, name, value) #:nodoc:
|
|
187
|
+
@line = line
|
|
188
|
+
@name = name
|
|
189
|
+
@value = value
|
|
190
|
+
@variable = nil
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# An assignment of multiple values as in:
|
|
196
|
+
#
|
|
197
|
+
# a, b = 1, 2
|
|
198
|
+
#
|
|
199
|
+
class MAsgn < Node
|
|
200
|
+
|
|
201
|
+
# The left side of the assignment
|
|
202
|
+
#
|
|
203
|
+
attr_accessor :left
|
|
204
|
+
|
|
205
|
+
# The right side of the assignment
|
|
206
|
+
#
|
|
207
|
+
attr_accessor :right
|
|
208
|
+
|
|
209
|
+
# TODO: document!
|
|
210
|
+
attr_accessor :splat #:nodoc:
|
|
211
|
+
|
|
212
|
+
# TODO: document!
|
|
213
|
+
attr_accessor :block #:nodoc:
|
|
214
|
+
|
|
215
|
+
def initialize(line, left, right, splat) #:nodoc:
|
|
216
|
+
@line = line
|
|
217
|
+
@left = left
|
|
218
|
+
@right = right
|
|
219
|
+
@splat = nil
|
|
220
|
+
@block = nil # support for |&b|
|
|
221
|
+
|
|
222
|
+
@fixed = right.kind_of?(ArrayLiteral) ? true : false
|
|
223
|
+
|
|
224
|
+
if splat.kind_of? Node
|
|
225
|
+
if @left
|
|
226
|
+
if right
|
|
227
|
+
@splat = SplatAssignment.new line, splat
|
|
228
|
+
else
|
|
229
|
+
@splat = SplatWrapped.new line, splat
|
|
230
|
+
end
|
|
231
|
+
elsif @fixed
|
|
232
|
+
@splat = SplatArray.new line, splat, right.body.size
|
|
233
|
+
elsif right.kind_of? SplatValue
|
|
234
|
+
@splat = splat
|
|
235
|
+
else
|
|
236
|
+
@splat = SplatWrapped.new line, splat
|
|
237
|
+
end
|
|
238
|
+
elsif splat and @fixed
|
|
239
|
+
@splat = EmptySplat.new line, right.body.size
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def iter_arguments
|
|
244
|
+
@iter_arguments = true
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
base = File.dirname(__FILE__)
|
|
2
|
+
|
|
3
|
+
module Melbourne
|
|
4
|
+
|
|
5
|
+
module AST #:nodoc:
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require File.join(base, 'ast/node')
|
|
11
|
+
require File.join(base, 'ast/self')
|
|
12
|
+
require File.join(base, 'ast/constants')
|
|
13
|
+
require File.join(base, 'ast/control_flow')
|
|
14
|
+
require File.join(base, 'ast/definitions')
|
|
15
|
+
require File.join(base, 'ast/exceptions')
|
|
16
|
+
require File.join(base, 'ast/file')
|
|
17
|
+
require File.join(base, 'ast/grapher')
|
|
18
|
+
require File.join(base, 'ast/literals')
|
|
19
|
+
require File.join(base, 'ast/operators')
|
|
20
|
+
require File.join(base, 'ast/sends')
|
|
21
|
+
require File.join(base, 'ast/values')
|
|
22
|
+
require File.join(base, 'ast/variables')
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Melbourne
|
|
2
|
+
|
|
3
|
+
class Parser #:nodoc:
|
|
4
|
+
|
|
5
|
+
def self.parse_string(string, name = '(eval)', line = 1)
|
|
6
|
+
new(name, line).parse_string(string)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.parse_file(name, line=1)
|
|
10
|
+
new(name, line).parse_file
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize(name, line, transforms=[])
|
|
14
|
+
@name = name
|
|
15
|
+
@line = line > 0 ? line : 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def syntax_error
|
|
19
|
+
raise @exc if @exc
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def parse_string(string)
|
|
23
|
+
syntax_error unless ast = string_to_ast(string, @name, @line)
|
|
24
|
+
ast
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def parse_file
|
|
28
|
+
unless @name and File.exists?(@name)
|
|
29
|
+
raise Errno::ENOENT, @name.inspect
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
syntax_error unless ast = file_to_ast(@name, @line)
|
|
33
|
+
ast
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
end
|