mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Correctly handle un-matched tokens and end-of-string situations.
This commit is contained in:
parent
798ee6f7c3
commit
e816b86a3e
|
@ -87,11 +87,12 @@ public class Lexer<T> {
|
|||
int index = startAt;
|
||||
ArrayList<Match<T>> matches = new ArrayList<>();
|
||||
Match<T> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user