Line by lines is not support at compile time. One more option:
readLines("input",3) reads first 3 lines of file, works at compile time. Useful
if you need to parse a header in the beginning of the file.
Huh, interesting. That works! I was more looking for something that wouldn't
read everything into memory at once (kind of like memfiles), but this works for
now. Thank you!
Like this:
import strutils
macro r: untyped =
for l in "input".slurp.splitLines:
# process a line
echo l
r()
Run
Is there a way to read a file line by line at compile time?
My use case is that I want to process an input file and produce Nim code via
macros, but have no trace of the input file in the resulting binary. Basically,
I just want to iterate over the lines and throw them away after the VM has read