Last active
May 16, 2016 06:58
-
-
Save aeden/47e8e8201694c03174c752a64ae3f157 to your computer and use it in GitHub Desktop.
Ruby script to convert erlang define to functions, for access from Elixir
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Converts all Erlang macro defines to Erlang functions. | |
# This is useful if you want to access those values from Elixir. | |
# | |
# If the defines are in an .hrl file, you should copy all of the | |
# defines into a .erl file first and then run the script on that | |
# .erl file. The script will copy the .erl file to .erl.old and | |
# then will overwrite the existing .erl file. | |
require 'fileutils' | |
ARGV.each do |name| | |
buffer = [] | |
FileUtils.cp(name, name + ".old") | |
open(name) do |f| | |
f.readlines.each do |line| | |
if line =~ /-define\((.*),/ | |
buffer << "#{$1.downcase}() -> ?#{$1}.\n" | |
else | |
buffer << line | |
end | |
end | |
end | |
open(name, 'w') do |f| | |
f << buffer.join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment