Skip to content

Commit 4934ac3

Browse files
committed
Refactor - moving hooked variables from regexp.rb to match_data.rb
1 parent c02ced6 commit 4934ac3

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

src/main/ruby/truffleruby/core/match_data.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,36 @@ def to_s
154154
self[0]
155155
end
156156
end
157+
158+
Truffle::KernelOperations.define_hooked_variable(
159+
:$~,
160+
-> s { Primitive.regexp_last_match_get(s) },
161+
Truffle::RegexpOperations::LAST_MATCH_SET)
162+
163+
Truffle::KernelOperations.define_hooked_variable(
164+
:'$`',
165+
-> s { match = Primitive.regexp_last_match_get(s)
166+
match.pre_match if match },
167+
-> { raise SyntaxError, "Can't set variable $`" },
168+
-> s { 'global-variable' if Primitive.regexp_last_match_get(s) })
169+
170+
Truffle::KernelOperations.define_hooked_variable(
171+
:"$'",
172+
-> s { match = Primitive.regexp_last_match_get(s)
173+
match.post_match if match },
174+
-> { raise SyntaxError, "Can't set variable $'" },
175+
-> s { 'global-variable' if Primitive.regexp_last_match_get(s) })
176+
177+
Truffle::KernelOperations.define_hooked_variable(
178+
:'$&',
179+
-> s { match = Primitive.regexp_last_match_get(s)
180+
match[0] if match },
181+
-> { raise SyntaxError, "Can't set variable $&" },
182+
-> s { 'global-variable' if Primitive.regexp_last_match_get(s) })
183+
184+
Truffle::KernelOperations.define_hooked_variable(
185+
:'$+',
186+
-> s { match = Primitive.regexp_last_match_get(s)
187+
match.captures.reverse.find { |m| !Primitive.nil?(m) } if match },
188+
-> { raise SyntaxError, "Can't set variable $+" },
189+
-> s { 'global-variable' if Primitive.regexp_last_match_get(s) })

src/main/ruby/truffleruby/core/regexp.rb

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -287,36 +287,3 @@ def names
287287
end
288288

289289
end
290-
291-
Truffle::KernelOperations.define_hooked_variable(
292-
:$~,
293-
-> s { Primitive.regexp_last_match_get(s) },
294-
Truffle::RegexpOperations::LAST_MATCH_SET)
295-
296-
Truffle::KernelOperations.define_hooked_variable(
297-
:'$`',
298-
-> s { match = Primitive.regexp_last_match_get(s)
299-
match.pre_match if match },
300-
-> { raise SyntaxError, "Can't set variable $`" },
301-
-> s { 'global-variable' if Primitive.regexp_last_match_get(s) })
302-
303-
Truffle::KernelOperations.define_hooked_variable(
304-
:"$'",
305-
-> s { match = Primitive.regexp_last_match_get(s)
306-
match.post_match if match },
307-
-> { raise SyntaxError, "Can't set variable $'" },
308-
-> s { 'global-variable' if Primitive.regexp_last_match_get(s) })
309-
310-
Truffle::KernelOperations.define_hooked_variable(
311-
:'$&',
312-
-> s { match = Primitive.regexp_last_match_get(s)
313-
match[0] if match },
314-
-> { raise SyntaxError, "Can't set variable $&" },
315-
-> s { 'global-variable' if Primitive.regexp_last_match_get(s) })
316-
317-
Truffle::KernelOperations.define_hooked_variable(
318-
:'$+',
319-
-> s { match = Primitive.regexp_last_match_get(s)
320-
match.captures.reverse.find { |m| !Primitive.nil?(m) } if match },
321-
-> { raise SyntaxError, "Can't set variable $+" },
322-
-> s { 'global-variable' if Primitive.regexp_last_match_get(s) })

0 commit comments

Comments
 (0)