Created
June 5, 2010 09:54
-
-
Save tstone/426501 to your computer and use it in GitHub Desktop.
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
import scala.io.Source | |
if (args.length > 0) { | |
def formatSourcePrefix(line: Int, suffix: String, max: Int = 5): String = { | |
var prefix: String = "" | |
for (i <- 1 to (max - line.toString.length)) | |
prefix += " " | |
prefix + line.toString + suffix | |
} | |
def formatSourceLine(lines: List[String], line: Int = 1, output: String = ""): String = { | |
val out = output + formatSourcePrefix(line, " | ") + lines.head + "\n" | |
if (lines.length > 1) | |
formatSourceLine(lines.tail, line + 1, out) | |
else | |
out | |
} | |
// Read file from disk | |
val lines = Source.fromPath(args(0)).getLines().toList | |
// Print results to screen | |
println | |
print(formatSourceLine(lines)) | |
} | |
else { | |
// Print out proper syntax | |
Console.err.println | |
Console.err.println("scala file.scala [filename]") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment