Skip to content

Commit

Permalink
#36. Generate Not Matching String
Browse files Browse the repository at this point in the history
All fixed.
  • Loading branch information
curious-odd-man committed Aug 25, 2020
1 parent ee560dc commit b447732
Showing 1 changed file with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ public void visit(SymbolSet node) {

@Override
public void visit(Choice node) {
for (Node n : node.getNodes()) {
// Just sum up all the choices
n.visit(this);
for (Node vnode : node.getNodes()) {
BigInteger count = countSeparately(node, vnode);
applyOrSkip(v -> {
if (count == null) {
return null;
}

return v.add(count);
});
}
}

Expand All @@ -77,37 +83,43 @@ public void visit(Repeat node) {
@Override
public void visit(Sequence node) {
for (Node vnode : node.getNodes()) {
UniqueValuesCountingVisitor countingVisitor = new UniqueValuesCountingVisitor(node);
vnode.visit(countingVisitor);
BigInteger count = countSeparately(node, vnode);
applyOrSkip(v -> {
if (countingVisitor.aCount == null) {
if (count == null) {
return null;
}

if (v.equals(BigInteger.ZERO)) {
return countingVisitor.aCount;
return count;
}

return countingVisitor.aCount.equals(BigInteger.ZERO) ? v : v.multiply(countingVisitor.aCount);
return count.equals(BigInteger.ZERO) ? v : v.multiply(count);
});
}
}

private BigInteger countSeparately(Node parentNode, Node vnode) {
UniqueValuesCountingVisitor countingVisitor = new UniqueValuesCountingVisitor(parentNode);
vnode.visit(countingVisitor);
return countingVisitor.aCount;
}

@Override
public void visit(NotSymbol notSymbol) {
public void visit(NotSymbol node) {
aCount = null;
}

@Override
public void visit(GroupRef groupRef) {
if (aParentNode == null
|| !(aParentNode instanceof Repeat)) {
// Do nothing. It does not add new unique values.
} else {
if (aParentNode != null
&& (aParentNode instanceof Repeat || aParentNode instanceof Choice)
) {
// When repeated multiple times - it adds as much unique values as it is repeated. So we should add 1 (it will be used in Repeat for calculation).
// E.g. (a|b)\1{2,3} - captured value of group is repeated either 2 or 3 times - it gives 2 unique values.
aCount = aCount.add(BigInteger.ONE);
}
//else
// Do nothing. It does not add new unique values apart from above mentioned cases
}

@Override
Expand Down

0 comments on commit b447732

Please sign in to comment.