From 1178ee3ee669eb4eb05307160b86932803a1ca2a Mon Sep 17 00:00:00 2001 From: James Harton Date: Wed, 27 Jan 2021 10:19:21 +1300 Subject: [PATCH] fix: Don't compare the consumed string's length for every iteration. Closes #3. --- lib/lex_luthor/runner.ex | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/lex_luthor/runner.ex b/lib/lex_luthor/runner.ex index 2a9f897..ef58dca 100644 --- a/lib/lex_luthor/runner.ex +++ b/lib/lex_luthor/runner.ex @@ -60,12 +60,9 @@ defmodule LexLuthor.Runner do line: line, column: column}) - # Are we at the end of the string? - if String.length(string) == len do - { :ok, Enum.reverse lexer.tokens } - else - { _ , new_string } = String.split_at string, len - do_lex module, rules, new_string, lexer + case String.split_at(string, len) do + {_, ""} -> {:ok, Enum.reverse(lexer.tokens)} + {_, new_string} -> do_lex(module, rules, new_string, lexer) end end end