Fix line number incrementing. Add test.
This commit is contained in:
parent
8d7b741173
commit
dce82668ce
|
@ -80,7 +80,7 @@ defmodule LexLuthor do
|
|||
lexer
|
||||
_ ->
|
||||
# Increment lexer position
|
||||
line = (String.slice(string, 0, len) |> String.split(~r{(\r|\n|\r\n)}) |> Enum.count) + lexer.line
|
||||
line = (String.slice(string, 0, len) |> String.split(~r{(\r|\n|\r\n)}) |> Enum.count) - 1 + lexer.line
|
||||
lexer = %State{ pos: lexer.pos + len, line: line, states: lexer.states, tokens: lexer.tokens }
|
||||
|
||||
# Are we at the end of the string?
|
||||
|
|
|
@ -34,4 +34,12 @@ defmodule AcceptanceTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "String #{inspect "foo\nbar"} has correct line numbers" do
|
||||
{ok, tokens} = ExampleLexer.lex "'foo'\n'bar'"
|
||||
assert ok == :ok
|
||||
|
||||
token = List.last tokens
|
||||
assert token.line == 2
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue