This commit is contained in:
Johanna Stuber 2021-02-15 16:42:56 +01:00
commit bbf24cae78
2 changed files with 9 additions and 11 deletions

View File

@ -11,7 +11,6 @@ import static edu.kit.typicalc.view.content.typeinferencecontent.latexcreator.La
* @see LambdaTerm
*/
public class LatexCreatorTerm implements TermVisitor {
// TODO: document
private final StringBuilder latex = new StringBuilder();
private boolean needsParentheses = false;
@ -29,14 +28,13 @@ public class LatexCreatorTerm implements TermVisitor {
* @return the generated LaTeX code
*/
public String getLatex() {
// todo remove most outer parentheses if they exist, untested
// long count = latex.chars().filter(ch -> ch == PAREN_LEFT).count();
// if (latex.indexOf(String.valueOf(PAREN_LEFT)) == 0
// && latex.indexOf(String.valueOf(PAREN_RIGHT)) == latex.length() - 1
// && count == 1) {
// latex.deleteCharAt(latex.length() - 1);
// latex.deleteCharAt(0);
// }
long count = latex.chars().filter(ch -> ch == PAREN_LEFT).count();
if (latex.indexOf(String.valueOf(PAREN_LEFT)) == 0
&& latex.indexOf(String.valueOf(PAREN_RIGHT)) == latex.length() - 1
&& count == 1) {
latex.deleteCharAt(latex.length() - 1);
latex.deleteCharAt(0);
}
return latex.toString();
}

View File

@ -18,8 +18,8 @@ class LatexCreatorTermTest {
@Test
void absTest() {
typeInferer = model.getTypeInferer("λx.y", new HashMap<>()).unwrap();
assertEquals(PAREN_LEFT + LAMBDA + SPACE + MONO_TEXT + "{x}" + DOT_SIGN
+ LATEX_SPACE + MONO_TEXT + "{y}" + PAREN_RIGHT,
assertEquals(LAMBDA + SPACE + MONO_TEXT + "{x}" + DOT_SIGN
+ LATEX_SPACE + MONO_TEXT + "{y}",
new LatexCreatorTerm(typeInferer.getFirstInferenceStep().getConclusion().getLambdaTerm()).getLatex());
}