Skip to content

Commit

Permalink
Implement backrefs
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
Sam Phippen committed Mar 13, 2019
1 parent eab3bfa commit 03dc382
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fixtures/backref_actual.rb
@@ -0,0 +1,2 @@
'foo' =~ /(.)oo/
puts $1
2 changes: 2 additions & 0 deletions fixtures/backref_expected.rb
@@ -0,0 +1,2 @@
"foo" =~ /(.)oo/
puts($1)
10 changes: 10 additions & 0 deletions src/rubyfmt.rb
Expand Up @@ -2048,6 +2048,15 @@ def format_rescue_mod(ps, expression)
ps.emit_newline if ps.start_of_line.last
end

def format_backref(ps, expression)
ps.emit_indent if ps.start_of_line.last

ps.emit_ident(expression[0])
ps.on_line(expression[1][0])

ps.emit_newline if ps.start_of_line.last
end

def format_expression(ps, expression)
type, rest = expression[0],expression[1...expression.length]

Expand Down Expand Up @@ -2139,6 +2148,7 @@ def format_expression(ps, expression)
:lambda => lambda { |ps, rest| format_lambda(ps, rest) },
:rescue_mod => lambda { |ps, rest| format_rescue_mod(ps, rest) },
:xstring_literal => lambda { |ps, rest| format_xstring_literal(ps, rest) },
:@backref => lambda { |ps, rest| format_backref(ps, rest) },
}.fetch(type).call(ps, rest)
end

Expand Down

0 comments on commit 03dc382

Please sign in to comment.