diff --git a/src/org/nwapw/abacus/lexing/Lexer.java b/src/org/nwapw/abacus/lexing/Lexer.java index 1a3cab8..7c84f16 100644 --- a/src/org/nwapw/abacus/lexing/Lexer.java +++ b/src/org/nwapw/abacus/lexing/Lexer.java @@ -7,6 +7,7 @@ import org.nwapw.abacus.lexing.pattern.PatternNode; import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; /** @@ -19,13 +20,13 @@ public class Lexer { /** * The registered patterns. */ - private ArrayList> patterns; + private HashMap> patterns; /** * Creates a new lexer with no registered patterns. */ public Lexer(){ - patterns = new ArrayList<>(); + patterns = new HashMap<>(); } /** @@ -35,7 +36,7 @@ public class Lexer { */ public void register(String pattern, T id){ Pattern compiledPattern = new Pattern<>(pattern, id); - if(compiledPattern.getHead() != null) patterns.add(compiledPattern); + if(compiledPattern.getHead() != null) patterns.put(pattern, compiledPattern); } /** @@ -50,7 +51,7 @@ public class Lexer { HashSet> currentSet = new HashSet<>(); HashSet> futureSet = new HashSet<>(); int index = startAt; - for(Pattern pattern : patterns){ + for(Pattern pattern : patterns.values()){ pattern.getHead().addInto(currentSet); } while(!currentSet.isEmpty()){