1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 15:30:09 -08:00

Fix bug causing the last character not to be matched.

This commit is contained in:
Danila Fedorin 2017-07-24 21:00:35 -07:00
parent c86e192d2e
commit 42db6b3c2f

View File

@ -6,7 +6,6 @@ import org.nwapw.abacus.lexing.pattern.Pattern;
import org.nwapw.abacus.lexing.pattern.PatternNode; import org.nwapw.abacus.lexing.pattern.PatternNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
@ -31,10 +30,9 @@ public class Lexer<T> {
for(Pattern<T> pattern : patterns){ for(Pattern<T> pattern : patterns){
pattern.getHead().addInto(currentSet); pattern.getHead().addInto(currentSet);
} }
while(!currentSet.isEmpty() && index < from.length()){ while(!currentSet.isEmpty()){
char currentChar = from.charAt(index);
for(PatternNode<T> node : currentSet){ for(PatternNode<T> node : currentSet){
if(node.matches(currentChar)) { if(index < from.length() && node.matches(from.charAt(index))) {
node.addOutputsInto(futureSet); node.addOutputsInto(futureSet);
} else if(node instanceof EndNode){ } else if(node instanceof EndNode){
matches.add(new Match<>(startAt, index, ((EndNode<T>) node).getPatternId())); matches.add(new Match<>(startAt, index, ((EndNode<T>) node).getPatternId()));