S
S. Robert James
I need to parse a file line by line, and output the results line by
line (too big to fit into memory). So far, simple enough:
file.each_line.
However, the parser needs the ability to peek ahead to the next line,
in order to parse this line. What's the right way to do this? Again,
I really don't want to try to slurp the whole file into memory and
split on newlines.
Here's an example:
Line1: Hi
Line2: How
Line3: Are
Line4: you?
I'd like to:
parse('Hi', 'How')
parse('How', 'Are')
parse('Are', 'you?')
parse('you?', false)
# hey, this is practically a unit test!
Any ideas?
line (too big to fit into memory). So far, simple enough:
file.each_line.
However, the parser needs the ability to peek ahead to the next line,
in order to parse this line. What's the right way to do this? Again,
I really don't want to try to slurp the whole file into memory and
split on newlines.
Here's an example:
Line1: Hi
Line2: How
Line3: Are
Line4: you?
I'd like to:
parse('Hi', 'How')
parse('How', 'Are')
parse('Are', 'you?')
parse('you?', false)
# hey, this is practically a unit test!
Any ideas?