Skip to content

Commit 842b7bb

Browse files
committed
Keep all special characters in boolean abstraction
Replacing special characters in variable names is mostly necessary to adhere to the grammar supported by the FeatureIDE parser for `Node`s. However, we already do our own parsing using Antlr4 so we can skip this step by building the `Node` tree our selves. This also removes one more source of bugs because overall there is less code involved. Beware that this introduces a semantic change: The new JPP parser abstracts `!defined(property)` to a negative literal `defined(property)` instead of a positive literal with a prefix denoting the negation.
1 parent e2da89e commit 842b7bb

15 files changed

Lines changed: 384 additions & 1104 deletions
Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package org.variantsync.diffdetective.feature;
22

3-
import org.prop4j.Literal;
43
import org.prop4j.Node;
5-
import org.prop4j.NodeReader;
64
import org.tinylog.Logger;
75
import org.variantsync.diffdetective.error.UncheckedUnParseableFormulaException;
86
import org.variantsync.diffdetective.error.UnparseableFormulaException;
9-
import org.variantsync.diffdetective.util.fide.FixTrueFalse;
107

11-
import java.util.function.Supplier;
128
import java.util.regex.Matcher;
139
import java.util.regex.Pattern;
1410

@@ -47,8 +43,6 @@ public AbstractingFormulaExtractor(Pattern annotationPattern) {
4743
@Override
4844
public Node extractFormula(final String text) throws UnparseableFormulaException {
4945
final Matcher matcher = annotationPattern.matcher(text);
50-
final Supplier<UnparseableFormulaException> couldNotExtractFormula = () ->
51-
new UnparseableFormulaException("Could not extract formula from line \"" + text + "\".");
5246

5347
// Retrieve the formula from the macro line
5448
String fm;
@@ -59,50 +53,18 @@ public Node extractFormula(final String text) throws UnparseableFormulaException
5953
fm = matcher.group(4);
6054
}
6155
} else {
62-
throw couldNotExtractFormula.get();
56+
throw new UnparseableFormulaException("Could not extract formula from line \"" + text + "\".");
6357
}
6458

6559
// abstract complex formulas (e.g., if they contain arithmetics or macro calls)
6660
try {
67-
fm = abstractFormula(fm);
61+
return abstractFormula(fm);
6862
} catch (UncheckedUnParseableFormulaException e) {
6963
throw e.inner();
7064
} catch (Exception e) {
7165
Logger.warn(e);
7266
throw new UnparseableFormulaException(e);
7367
}
74-
75-
if (fm.isEmpty()) {
76-
throw couldNotExtractFormula.get();
77-
}
78-
79-
return parseFormula(fm);
80-
}
81-
82-
/**
83-
* Parser that uses the {@link NodeReader} from FeatureIDE and uses its
84-
* {@link NodeReader#activateJavaSymbols() java symbols} to match operators.
85-
*/
86-
protected Node parseFormula(String text) {
87-
final NodeReader nodeReader = new NodeReader();
88-
nodeReader.activateJavaSymbols();
89-
90-
Node node = nodeReader.stringToNode(text);
91-
92-
// if parsing succeeded
93-
if (node != null) {
94-
// TODO: Is this our desired behaviour?
95-
// If so, should we document it by not using get here
96-
// and instead keeping the witness that this call happened?
97-
node = FixTrueFalse.EliminateTrueAndFalseInplace(node).get();
98-
}
99-
100-
if (node == null) {
101-
// Logger.warn("Could not parse expression '{}' to feature mapping. Usin>
102-
node = new Literal(text);
103-
}
104-
105-
return node;
10668
}
10769

10870
/**
@@ -113,5 +75,5 @@ protected Node parseFormula(String text) {
11375
* @param formula that is to be abstracted
11476
* @return the abstracted formula
11577
*/
116-
protected abstract String abstractFormula(String formula);
78+
protected abstract Node abstractFormula(String formula);
11779
}

0 commit comments

Comments
 (0)