bitwalker/combine

Newline doesn't actually increment the line count

LeviSchuck opened this issue · 1 comments

It's a sad day when all error messages say line 1.

  defparser correct_newline(%ParserState{} = state) do
   do_newline(state)
  end
  defp do_newline(%ParserState{status: :ok, line: line, input: <<?\n::utf8,rest::binary>>, results: results} = state) do
   %{state | :column => 0, :line => line + 1, :input => rest, :results => ["\n"|results]}
  end
  defp do_newline(%ParserState{status: :ok, line: line, input: <<?\r::utf8,?\n::utf8,rest::binary>>, results: results} = state) do
    %{state | :column => 0, :line => line + 1, :input => rest, :results => ["\n"|results]}
  end
  defp do_newline(%ParserState{status: :ok, line: line, column: col, input: <<?\r::utf8,c::utf8,_::binary>>} = state) do
    %{state | :status => :error, :error => "Expected CRLF sequence, but found `\\r#{<<c::utf8>>}` at line #{line}, column #{col + 1}."}
  end
  defp do_newline(%ParserState{status: :ok, input: <<?\r::utf8>>} = state) do
    %{state | :status => :error, :error => "Expected CRLF sequence, but hit end of input."}
  end
  defp do_newline(%ParserState{status: :ok, line: line, column: col, input: <<c::utf8,_::binary>>} = state) do
    %{state | :status => :error, :error => "Expected newline but found `#{<<c::utf8>>}` at line #{line}, column #{col + 1}."}
  end
  defp do_newline(%ParserState{status: :ok, input: <<>>} = state) do
    %{state | :status => :error, :error => "Expected newline, but hit end of input."}
  end

Here's what I had to do in my project.

I've pushed a fix to master, could you confirm it works for you? If so I'll publish 0.9.7.