@Override protected void exitSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } }
@Override protected void exitLexerSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } } }
@Override protected void exitLexerSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } } }
@Override protected void exitSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } }
/** * Generate a frequency set as the union of two input sets. If an * element is contained in both sets, the value for the output will be * the maximum of the two input values. * * @param a The first set. * @param b The second set. * @return The union of the two sets, with the maximum value chosen * whenever both sets contain the same key. */ protected static FrequencySet<String> combineMax(FrequencySet<String> a, FrequencySet<String> b) { FrequencySet<String> result = combineAndClip(a, b, 1); for (Map.Entry<String, MutableInt> entry : a.entrySet()) { result.get(entry.getKey()).v = entry.getValue().v; } for (Map.Entry<String, MutableInt> entry : b.entrySet()) { MutableInt slot = result.get(entry.getKey()); slot.v = Math.max(slot.v, entry.getValue().v); } return result; }
@Override protected void exitBlockSet(GrammarAST tree) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { // This visitor counts a block set as a sequence of elements, not a // sequence of alternatives of elements. Reset the count back to 1 // for all items when leaving the set to ensure duplicate entries in // the set are treated as a maximum of one item. entry.getValue().v = 1; } if (minFrequencies.peek().size() > 1) { // Everything is optional minFrequencies.peek().clear(); } frequencies.push(combineAndClip(frequencies.pop(), frequencies.pop(), 2)); minFrequencies.push(combineAndClip(minFrequencies.pop(), minFrequencies.pop(), 2)); }
/** * Generate a frequency set as the union of two input sets. If an * element is contained in both sets, the value for the output will be * the maximum of the two input values. * * @param a The first set. * @param b The second set. * @return The union of the two sets, with the maximum value chosen * whenever both sets contain the same key. */ protected static FrequencySet<String> combineMax(FrequencySet<String> a, FrequencySet<String> b) { FrequencySet<String> result = combineAndClip(a, b, 1); for (Map.Entry<String, MutableInt> entry : a.entrySet()) { result.get(entry.getKey()).v = entry.getValue().v; } for (Map.Entry<String, MutableInt> entry : b.entrySet()) { MutableInt slot = result.get(entry.getKey()); slot.v = Math.max(slot.v, entry.getValue().v); } return result; }
@Override protected void exitBlockSet(GrammarAST tree) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { // This visitor counts a block set as a sequence of elements, not a // sequence of alternatives of elements. Reset the count back to 1 // for all items when leaving the set to ensure duplicate entries in // the set are treated as a maximum of one item. entry.getValue().v = 1; } if (minFrequencies.peek().size() > 1) { // Everything is optional minFrequencies.peek().clear(); } frequencies.push(combineAndClip(frequencies.pop(), frequencies.pop(), 2)); minFrequencies.push(combineAndClip(minFrequencies.pop(), minFrequencies.pop(), 2)); }
/** * Generate a frequency set as the union of two input sets. If an * element is contained in both sets, the value for the output will be * the maximum of the two input values. * * @param a The first set. * @param b The second set. * @return The union of the two sets, with the maximum value chosen * whenever both sets contain the same key. */ protected static FrequencySet<String> combineMax(FrequencySet<String> a, FrequencySet<String> b) { FrequencySet<String> result = combineAndClip(a, b, 1); for (Map.Entry<String, MutableInt> entry : a.entrySet()) { result.get(entry.getKey()).v = entry.getValue().v; } for (Map.Entry<String, MutableInt> entry : b.entrySet()) { MutableInt slot = result.get(entry.getKey()); slot.v = Math.max(slot.v, entry.getValue().v); } return result; }
/** * Generate a frequency set as the union of two input sets. If an * element is contained in both sets, the value for the output will be * the maximum of the two input values. * * @param a The first set. * @param b The second set. * @return The union of the two sets, with the maximum value chosen * whenever both sets contain the same key. */ protected static FrequencySet<String> combineMax(FrequencySet<String> a, FrequencySet<String> b) { FrequencySet<String> result = combineAndClip(a, b, 1); for (Map.Entry<String, MutableInt> entry : a.entrySet()) { result.get(entry.getKey()).v = entry.getValue().v; } for (Map.Entry<String, MutableInt> entry : b.entrySet()) { MutableInt slot = result.get(entry.getKey()); slot.v = Math.max(slot.v, entry.getValue().v); } return result; }
/** * Generate a frequency set as the union of two input sets. If an * element is contained in both sets, the value for the output will be * the maximum of the two input values. * * @param a The first set. * @param b The second set. * @return The union of the two sets, with the maximum value chosen * whenever both sets contain the same key. */ protected static FrequencySet<String> combineMax(FrequencySet<String> a, FrequencySet<String> b) { FrequencySet<String> result = combineAndClip(a, b, 1); for (Map.Entry<String, MutableInt> entry : a.entrySet()) { result.get(entry.getKey()).v = entry.getValue().v; } for (Map.Entry<String, MutableInt> entry : b.entrySet()) { MutableInt slot = result.get(entry.getKey()); slot.v = Math.max(slot.v, entry.getValue().v); } return result; }
@Override protected void exitBlockSet(GrammarAST tree) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { // This visitor counts a block set as a sequence of elements, not a // sequence of alternatives of elements. Reset the count back to 1 // for all items when leaving the set to ensure duplicate entries in // the set are treated as a maximum of one item. entry.getValue().v = 1; } if (minFrequencies.peek().size() > 1) { // Everything is optional minFrequencies.peek().clear(); } frequencies.push(combineAndClip(frequencies.pop(), frequencies.pop(), 2)); minFrequencies.push(combineAndClip(minFrequencies.pop(), minFrequencies.pop(), 2)); }
@Override protected void exitLexerSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } if (tree.getType() == CLOSURE) { // Everything inside a closure is optional, so the minimum // number of occurrences for all elements is 0. minFrequencies.peek().clear(); } } }
/** * Generate a frequency set as the union of two input sets. If an * element is contained in both sets, the value for the output will be * the minimum of the two input values. * * @param a The first set. * @param b The second set. If this set is {@link #SENTINEL}, it is treated * as though no second set were provided. * @return The union of the two sets, with the minimum value chosen * whenever both sets contain the same key. */ protected static FrequencySet<String> combineMin(FrequencySet<String> a, FrequencySet<String> b) { if (b == SENTINEL) { return a; } assert a != SENTINEL; FrequencySet<String> result = combineAndClip(a, b, Integer.MAX_VALUE); for (Map.Entry<String, MutableInt> entry : result.entrySet()) { entry.getValue().v = Math.min(a.count(entry.getKey()), b.count(entry.getKey())); } return result; }
@Override protected void exitLexerSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } if (tree.getType() == CLOSURE) { // Everything inside a closure is optional, so the minimum // number of occurrences for all elements is 0. minFrequencies.peek().clear(); } } }
/** * Generate a frequency set as the union of two input sets. If an * element is contained in both sets, the value for the output will be * the minimum of the two input values. * * @param a The first set. * @param b The second set. If this set is {@link #SENTINEL}, it is treated * as though no second set were provided. * @return The union of the two sets, with the minimum value chosen * whenever both sets contain the same key. */ protected static FrequencySet<String> combineMin(FrequencySet<String> a, FrequencySet<String> b) { if (b == SENTINEL) { return a; } assert a != SENTINEL; FrequencySet<String> result = combineAndClip(a, b, Integer.MAX_VALUE); for (Map.Entry<String, MutableInt> entry : result.entrySet()) { entry.getValue().v = Math.min(a.count(entry.getKey()), b.count(entry.getKey())); } return result; }
@Override protected void exitSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } if (tree.getType() == CLOSURE || tree.getType() == OPTIONAL) { // Everything inside a closure is optional, so the minimum // number of occurrences for all elements is 0. minFrequencies.peek().clear(); } }
@Override protected void exitLexerSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } if (tree.getType() == CLOSURE) { // Everything inside a closure is optional, so the minimum // number of occurrences for all elements is 0. minFrequencies.peek().clear(); } } }
@Override protected void exitSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } if (tree.getType() == CLOSURE || tree.getType() == OPTIONAL) { // Everything inside a closure is optional, so the minimum // number of occurrences for all elements is 0. minFrequencies.peek().clear(); } }
@Override protected void exitSubrule(GrammarAST tree) { if (tree.getType() == CLOSURE || tree.getType() == POSITIVE_CLOSURE) { for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { entry.getValue().v = 2; } } if (tree.getType() == CLOSURE || tree.getType() == OPTIONAL) { // Everything inside a closure is optional, so the minimum // number of occurrences for all elements is 0. minFrequencies.peek().clear(); } }