String interpolation ? #1063
-
Hi, $V=" hello "
echo "I say${V},you say goodbye."
I say hello, you say goodbye. Now, I want to do a fix, this works fine (Elixir):
But say, I want to rename the Elixir module (suffix it with "ConcreteFactoryImpl")(lets pretend we're Java devs: Now Ideally, unless I'm being silly, variables could be expressed in a
Is there a better way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I seem to have gotten around this by splicing in
Woops, wrong, it's still eating the letter 'C' |
Beta Was this translation helpful? Give feedback.
-
This can be done via transform operation. 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 |
Beta Was this translation helpful? Give feedback.
This can be done via transform operation.
The trick here is
$NEW_MOD
can be freely changed via regex replacement.https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImVsaXhpciIsInF1ZXJ5IjoiY29uc29sZS5sb2coJE1BVENIKSIsInJld3JpdGUiOiJsb2dnZXIubG9nKCRNQVRDSCkiLCJjb25maWciOiJydWxlOlxuICBhbnk6XG4gICAgLSBwYXR0ZXJuOiB8XG4gICAgICAgIGRlZm1vZHVsZSAkTSBkbyBcbiAgICAgICAgICBJTy5wdXRzKCRBKVxuICAgICAgICB…