Skip to content

String interpolation ? #1063

Answered by HerringtonDarkholme
fcbry asked this question in Q&A
Apr 19, 2024 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

This can be done via transform operation.
The trick here is $NEW_MOD can be freely changed via regex replacement.

rule:
  any:
    - pattern: |
        defmodule $M do 
          IO.puts($A)
        end
transform:
  NEW_MOD:
    replace:
      by: ConcreteFactoryImpl
      replace: $
      source: $M
fix: |
  defmodule $NEW_MOD do 
    def msg($A) do 
      IO.puts(:stdout,$A)
    end 
  end

https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImVsaXhpciIsInF1ZXJ5IjoiY29uc29sZS5sb2coJE1BVENIKSIsInJld3JpdGUiOiJsb2dnZXIubG9nKCRNQVRDSCkiLCJjb25maWciOiJydWxlOlxuICBhbnk6XG4gICAgLSBwYXR0ZXJuOiB8XG4gICAgICAgIGRlZm1vZHVsZSAkTSBkbyBcbiAgICAgICAgICBJTy5wdXRzKCRBKVxuICAgICAgICB…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

@HerringtonDarkholme
Comment options

@fcbry
Comment options

Answer selected by fcbry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants