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

Fix a few bug in the pattern compilation code.

This commit is contained in:
Danila Fedorin 2017-07-24 20:47:13 -07:00
parent ac3087fc3f
commit 43c3d5f754

View File

@ -68,6 +68,7 @@ public class Pattern<T> {
private PatternChain<T> parseOr(){ private PatternChain<T> parseOr(){
Stack<PatternChain<T>> orStack = new Stack<>(); Stack<PatternChain<T>> orStack = new Stack<>();
index++;
while(index < source.length() && source.charAt(index) != ']'){ while(index < source.length() && source.charAt(index) != ']'){
if(source.charAt(index) == '-'){ if(source.charAt(index) == '-'){
index++; index++;
@ -82,10 +83,9 @@ public class Pattern<T> {
if(newChain == null) return null; if(newChain == null) return null;
orStack.push(newChain); orStack.push(newChain);
} }
index++;
} }
if(index >= source.length()) return null; if(index++ >= source.length()) return null;
return combineChains(orStack); return (orStack.size() == 1) ? orStack.pop() : combineChains(orStack);
} }
private PatternChain<T> parseSegment(boolean isSubsegment){ private PatternChain<T> parseSegment(boolean isSubsegment){
@ -124,6 +124,12 @@ public class Pattern<T> {
} }
currentChain = parseOr(); currentChain = parseOr();
if(currentChain == null) return null; if(currentChain == null) return null;
} else if(currentChar == '.'){
if(currentChain != null){
fullChain.append(currentChain);
}
currentChain = new PatternChain<>(new AnyNode<>());
index++;
} else { } else {
if(currentChain != null){ if(currentChain != null){
fullChain.append(currentChain); fullChain.append(currentChain);
@ -159,4 +165,7 @@ public class Pattern<T> {
} }
} }
public PatternNode<T> getHead() {
return head;
}
} }