Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4963ad5

Browse files
authored
Merge pull request #304 from ruby-syntax-tree/reflection
Reflection API
2 parents 69c6719 + 42572ac commit 4963ad5

File tree

13 files changed

+787
-192
lines changed

13 files changed

+787
-192
lines changed

Rakefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ task default: :test
1616

1717
configure = ->(task) do
1818
task.source_files =
19-
FileList[%w[Gemfile Rakefile syntax_tree.gemspec lib/**/*.rb test/*.rb]]
19+
FileList[
20+
%w[
21+
Gemfile
22+
Rakefile
23+
syntax_tree.gemspec
24+
lib/**/*.rb
25+
tasks/*.rake
26+
test/*.rb
27+
]
28+
]
2029

2130
# Since Syntax Tree supports back to Ruby 2.7.0, we need to make sure that we
2231
# format our code such that it's compatible with that version. This actually

bin/console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
require "bundler/setup"
55
require "syntax_tree"
6+
require "syntax_tree/reflection"
67

78
require "irb"
89
IRB.start(__FILE__)

lib/syntax_tree/dsl.rb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,17 @@ def RAssign(value, operator, pattern)
210210
end
211211

212212
# Create a new ClassDeclaration node.
213-
def ClassDeclaration(constant, superclass, bodystmt)
213+
def ClassDeclaration(
214+
constant,
215+
superclass,
216+
bodystmt,
217+
location = Location.default
218+
)
214219
ClassDeclaration.new(
215220
constant: constant,
216221
superclass: superclass,
217222
bodystmt: bodystmt,
218-
location: Location.default
223+
location: location
219224
)
220225
end
221226

@@ -225,12 +230,12 @@ def Comma(value)
225230
end
226231

227232
# Create a new Command node.
228-
def Command(message, arguments, block)
233+
def Command(message, arguments, block, location = Location.default)
229234
Command.new(
230235
message: message,
231236
arguments: arguments,
232237
block: block,
233-
location: Location.default
238+
location: location
234239
)
235240
end
236241

@@ -247,8 +252,8 @@ def CommandCall(receiver, operator, message, arguments, block)
247252
end
248253

249254
# Create a new Comment node.
250-
def Comment(value, inline)
251-
Comment.new(value: value, inline: inline, location: Location.default)
255+
def Comment(value, inline, location = Location.default)
256+
Comment.new(value: value, inline: inline, location: location)
252257
end
253258

254259
# Create a new Const node.
@@ -285,14 +290,21 @@ def CVar(value)
285290
end
286291

287292
# Create a new DefNode node.
288-
def DefNode(target, operator, name, params, bodystmt)
293+
def DefNode(
294+
target,
295+
operator,
296+
name,
297+
params,
298+
bodystmt,
299+
location = Location.default
300+
)
289301
DefNode.new(
290302
target: target,
291303
operator: operator,
292304
name: name,
293305
params: params,
294306
bodystmt: bodystmt,
295-
location: Location.default
307+
location: location
296308
)
297309
end
298310

@@ -565,8 +577,8 @@ def MAssign(target, value)
565577
end
566578

567579
# Create a new MethodAddBlock node.
568-
def MethodAddBlock(call, block)
569-
MethodAddBlock.new(call: call, block: block, location: Location.default)
580+
def MethodAddBlock(call, block, location = Location.default)
581+
MethodAddBlock.new(call: call, block: block, location: location)
570582
end
571583

572584
# Create a new MLHS node.

0 commit comments

Comments
 (0)