From 43c3d5f7548f5075b1e0d24ab3e1a1eac116efd9 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 24 Jul 2017 20:47:13 -0700 Subject: [PATCH] Fix a few bug in the pattern compilation code. --- src/org/nwapw/abacus/lexing/pattern/Pattern.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/org/nwapw/abacus/lexing/pattern/Pattern.java b/src/org/nwapw/abacus/lexing/pattern/Pattern.java index 364152b..860e036 100644 --- a/src/org/nwapw/abacus/lexing/pattern/Pattern.java +++ b/src/org/nwapw/abacus/lexing/pattern/Pattern.java @@ -68,6 +68,7 @@ public class Pattern { private PatternChain parseOr(){ Stack> orStack = new Stack<>(); + index++; while(index < source.length() && source.charAt(index) != ']'){ if(source.charAt(index) == '-'){ index++; @@ -82,10 +83,9 @@ public class Pattern { if(newChain == null) return null; orStack.push(newChain); } - index++; } - if(index >= source.length()) return null; - return combineChains(orStack); + if(index++ >= source.length()) return null; + return (orStack.size() == 1) ? orStack.pop() : combineChains(orStack); } private PatternChain parseSegment(boolean isSubsegment){ @@ -124,6 +124,12 @@ public class Pattern { } currentChain = parseOr(); if(currentChain == null) return null; + } else if(currentChar == '.'){ + if(currentChain != null){ + fullChain.append(currentChain); + } + currentChain = new PatternChain<>(new AnyNode<>()); + index++; } else { if(currentChain != null){ fullChain.append(currentChain); @@ -159,4 +165,7 @@ public class Pattern { } } + public PatternNode getHead() { + return head; + } }