From 93e892f92e49f2cd671e7d4453d1acb0df8c310b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 26 Jul 2017 13:24:46 -0700 Subject: [PATCH] Correctly handle un-matched tokens and end-of-string situations. --- src/org/nwapw/abacus/lexing/Lexer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/org/nwapw/abacus/lexing/Lexer.java b/src/org/nwapw/abacus/lexing/Lexer.java index 2813061..1a3cab8 100644 --- a/src/org/nwapw/abacus/lexing/Lexer.java +++ b/src/org/nwapw/abacus/lexing/Lexer.java @@ -87,11 +87,12 @@ public class Lexer { int index = startAt; ArrayList> matches = new ArrayList<>(); Match lastMatch = null; - while((lastMatch = lexOne(from, index, compare)) != null && index < from.length()){ + while(index < from.length() && (lastMatch = lexOne(from, index, compare)) != null){ if(lastMatch.getTo() == lastMatch.getFrom()) return null; matches.add(lastMatch); index += lastMatch.getTo() - lastMatch.getFrom(); } + if(lastMatch == null) return null; return matches; }