Created
January 22, 2019 14:40
-
-
Save hanneskaeufler/a90add4d07624173db93a142a5312c1a to your computer and use it in GitHub Desktop.
Replace `true` with `false`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "compiler/crystal/syntax/*" | |
code = <<-CODE | |
def hello | |
true | |
end | |
CODE | |
ast = Crystal::Parser.parse(code) | |
class BooleanTransformer < Crystal::Transformer | |
def transform(node : Crystal::BoolLiteral) | |
Crystal::BoolLiteral.new(false) | |
end | |
end | |
puts ast.transform(BooleanTransformer.new) | |
# => will print: | |
# def hello | |
# false | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment