mirror of
				https://github.com/DanilaFe/abacus
				synced 2025-11-04 02:43:41 -08:00 
			
		
		
		
	Fix a few bug in the pattern compilation code.
This commit is contained in:
		
							parent
							
								
									ac3087fc3f
								
							
						
					
					
						commit
						43c3d5f754
					
				@ -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;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user