Created
March 27, 2010 22:53
-
-
Save cflewis/346406 to your computer and use it in GitHub Desktop.
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
begin | |
$stdin.each_line do |prism_line| | |
# cflewis | 2010-03-27 | Regular expressions to use | |
# cflewis | 2010-03-27 | eg. x[3] : [0..2] init blank | |
array_declaration = /(\s*)(\w+)\[(\d+)\]\s+:\s+(\[.*\]\s+init\s+(\w+)\;)/ | |
# cflewis | 2010-03-27 | eg. x[1] | |
array_usage = /(\w+)\[(\d+)\]/ | |
separator = "__" | |
# cflewis | 2010-03-27 | For each line, check for array declarations | |
# and substitute with individual variables | |
if (prism_line =~ array_declaration) | |
leading_whitespace = $1 | |
array_name = $2 | |
array_length = $3 | |
tailing_data = $4 | |
array_substitution = "" | |
for i in (0..Integer(array_length) - 1) | |
array_substitution = array_substitution + | |
"#{leading_whitespace}#{array_name}#{separator}#{i} " + | |
": #{tailing_data} //Substitution by Spectrum\n" | |
end | |
prism_line.gsub!(array_declaration, array_substitution) | |
end | |
# cflewis | 2010-03-27 | Replace all array usages with their | |
# corresponding expanded variables | |
prism_line.gsub!(array_usage, '\1' + separator + '\2') | |
puts prism_line | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment