mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 18:30:42 +00:00
Merge branch 'master' of https://git.scc.kit.edu/pse-typinferenz/typicalc
This commit is contained in:
commit
f82d316bbf
18
frontend/src/mathjax-unification.ts
Normal file
18
frontend/src/mathjax-unification.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import {MathjaxAdapter} from "./mathjax-adapter";
|
||||||
|
import {TemplateResult} from "lit-html";
|
||||||
|
|
||||||
|
class MathjaxUnification extends MathjaxAdapter {
|
||||||
|
|
||||||
|
render(): TemplateResult {
|
||||||
|
return super.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected showStep(_n: number): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected calculateSteps(): void {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define('tc-unification', MathjaxUnification);
|
@ -1,20 +1,15 @@
|
|||||||
package edu.kit.typicalc.view;
|
package edu.kit.typicalc.view;
|
||||||
|
|
||||||
import com.vaadin.flow.component.littemplate.LitTemplate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an HTML element that uses MathJax and custom JavaScript classes to render its contents.
|
* Represents an HTML element that uses MathJax and custom JavaScript classes to render its contents.
|
||||||
* Provides an interface between Java code and said JavaScript classes. Allows to reveal parts of the
|
* Provides an interface between Java code and said JavaScript classes. Allows to reveal parts of the
|
||||||
* rendered LaTeX step-by-step. Allows for scaling of the rendered LaTeX.
|
* rendered LaTeX step-by-step. Allows for scaling of the rendered LaTeX.
|
||||||
*/
|
*/
|
||||||
public abstract class MathjaxAdapter extends LitTemplate {
|
public interface MathjaxAdapter {
|
||||||
|
|
||||||
/**
|
int getStepCount();
|
||||||
* Creates a new HTML element that renders the LaTeX string passed as parameter using MathJax. Because
|
|
||||||
* MathJax is used to render the String, all LaTeX commands used must be MathJax compatible.
|
|
||||||
* @param latex the LaTex string to render with MathJax
|
|
||||||
*/
|
|
||||||
protected MathjaxAdapter(String latex) {
|
|
||||||
|
|
||||||
}
|
void showStep(int n);
|
||||||
|
|
||||||
|
void scale(double newScaling);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import com.vaadin.flow.router.PageTitle;
|
|||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import com.vaadin.flow.router.RouteAlias;
|
import com.vaadin.flow.router.RouteAlias;
|
||||||
import edu.kit.typicalc.view.content.typeinferencecontent.MathjaxProofTree;
|
import edu.kit.typicalc.view.content.typeinferencecontent.MathjaxProofTree;
|
||||||
|
import edu.kit.typicalc.view.content.typeinferencecontent.MathjaxUnification;
|
||||||
import edu.kit.typicalc.view.main.MainViewImpl;
|
import edu.kit.typicalc.view.main.MainViewImpl;
|
||||||
import edu.kit.typicalc.view.main.MathjaxDisplay;
|
import edu.kit.typicalc.view.main.MathjaxDisplay;
|
||||||
|
|
||||||
@ -21,8 +22,9 @@ public class StartPageView extends VerticalLayout {
|
|||||||
public StartPageView() {
|
public StartPageView() {
|
||||||
// todo implement correctly
|
// todo implement correctly
|
||||||
setId("start-page");
|
setId("start-page");
|
||||||
add(new MathjaxDisplay());
|
add(new MathjaxDisplay(getTranslation("abs-rule")));
|
||||||
add(new MathjaxProofTree());
|
add(new MathjaxUnification("\\(constraint test \\vdash \\)"));
|
||||||
|
add(new MathjaxProofTree(getTranslation("demo-tree")));
|
||||||
sayHello = new Button("Say hello");
|
sayHello = new Button("Say hello");
|
||||||
add(sayHello);
|
add(sayHello);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ import edu.kit.typicalc.model.type.TypeVisitor;
|
|||||||
*/
|
*/
|
||||||
public class LatexCreator implements StepVisitor, TermVisitor, TypeVisitor {
|
public class LatexCreator implements StepVisitor, TermVisitor, TypeVisitor {
|
||||||
|
|
||||||
|
private static final String EQUAL_SIGN = "=";
|
||||||
|
|
||||||
private static final String LABEL_ABS = "\\LeftLabel{ABS}";
|
private static final String LABEL_ABS = "\\LeftLabel{ABS}";
|
||||||
private static final String LABEL_APP = "\\LeftLabel{APP}";
|
private static final String LABEL_APP = "\\LeftLabel{APP}";
|
||||||
private static final String LABEL_CONST = "\\LeftLabel{CONST}";
|
private static final String LABEL_CONST = "\\LeftLabel{CONST}";
|
||||||
@ -43,6 +45,11 @@ public class LatexCreator implements StepVisitor, TermVisitor, TypeVisitor {
|
|||||||
private final StringBuilder tree;
|
private final StringBuilder tree;
|
||||||
private final boolean stepLabels;
|
private final boolean stepLabels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needed for typeVisitor methods
|
||||||
|
*/
|
||||||
|
private String typeBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the pieces of LaTeX-code from the type inferer.
|
* Generate the pieces of LaTeX-code from the type inferer.
|
||||||
*
|
*
|
||||||
@ -64,28 +71,28 @@ public class LatexCreator implements StepVisitor, TermVisitor, TypeVisitor {
|
|||||||
*/
|
*/
|
||||||
protected String getTree() {
|
protected String getTree() {
|
||||||
return null;
|
return null;
|
||||||
}
|
} // todo implement
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the LaTeX-code for constraints nad unification
|
* @return the LaTeX-code for constraints nad unification
|
||||||
*/
|
*/
|
||||||
protected String getUnification() {
|
protected String getUnification() {
|
||||||
return null;
|
return null;
|
||||||
}
|
} // todo implement
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the packages needed for the LaTeX-code from getTree() and getUnification()to work
|
* @return the packages needed for the LaTeX-code from getTree() and getUnification()to work
|
||||||
*/
|
*/
|
||||||
protected String getLatexPackages() {
|
protected String getLatexPackages() {
|
||||||
return null;
|
return null;
|
||||||
}
|
} // todo implement
|
||||||
|
|
||||||
private String conclusionToLatex(Conclusion conclusion) {
|
private String conclusionToLatex(Conclusion conclusion) {
|
||||||
// todo implement
|
// todo implement
|
||||||
return "";
|
return "{some text}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateConclusion(InferenceStep step, String label, String command) {
|
private StringBuilder generateConclusion(InferenceStep step, String label, String command) {
|
||||||
StringBuilder conclusion = new StringBuilder();
|
StringBuilder conclusion = new StringBuilder();
|
||||||
if (stepLabels) {
|
if (stepLabels) {
|
||||||
conclusion.append(label);
|
conclusion.append(label);
|
||||||
@ -94,52 +101,79 @@ public class LatexCreator implements StepVisitor, TermVisitor, TypeVisitor {
|
|||||||
conclusion.append(command);
|
conclusion.append(command);
|
||||||
conclusion.append(conclusionToLatex(step.getConclusion()));
|
conclusion.append(conclusionToLatex(step.getConclusion()));
|
||||||
conclusion.append(System.lineSeparator());
|
conclusion.append(System.lineSeparator());
|
||||||
tree.insert(0, conclusion);
|
return conclusion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StringBuilder generateConstraint(InferenceStep step) {
|
||||||
|
// todo implement maybe rename to addConstraint
|
||||||
|
StringBuilder constraint = new StringBuilder();
|
||||||
|
step.getConstraint().getFirstType().accept(this);
|
||||||
|
String firstType = typeBuffer;
|
||||||
|
step.getConstraint().getSecondType().accept(this);
|
||||||
|
String secondType = typeBuffer;
|
||||||
|
constraint.append(firstType)
|
||||||
|
.append(EQUAL_SIGN)
|
||||||
|
.append(secondType)
|
||||||
|
.append(System.lineSeparator());
|
||||||
|
return constraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo use generateConstraint
|
||||||
@Override
|
@Override
|
||||||
public void visit(AbsStepDefault absD) {
|
public void visit(AbsStepDefault absD) {
|
||||||
generateConclusion(absD, LABEL_ABS, UIC);
|
tree.insert(0, generateConclusion(absD, LABEL_ABS, UIC));
|
||||||
|
absD.getPremise().accept(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(AbsStepWithLet absL) {
|
public void visit(AbsStepWithLet absL) {
|
||||||
generateConclusion(absL, LABEL_ABS, UIC);
|
tree.insert(0, generateConclusion(absL, LABEL_ABS, UIC));
|
||||||
|
absL.getPremise().accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(AppStepDefault appD) {
|
public void visit(AppStepDefault appD) {
|
||||||
generateConclusion(appD, LABEL_APP, UIC);
|
tree.insert(0, generateConclusion(appD, LABEL_APP, BIC));
|
||||||
|
appD.getPremise2().accept(this);
|
||||||
|
appD.getPremise1().accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ConstStepDefault constD) {
|
public void visit(ConstStepDefault constD) {
|
||||||
generateConclusion(constD, LABEL_CONST, UIC);
|
tree.insert(0, generateConclusion(constD, LABEL_CONST, UIC));
|
||||||
|
// todo implement
|
||||||
|
StringBuilder temp = new StringBuilder();
|
||||||
|
temp.append(AXC).append("{const default}");
|
||||||
|
tree.insert(0, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(VarStepDefault varD) {
|
public void visit(VarStepDefault varD) {
|
||||||
generateConclusion(varD, LABEL_VAR, UIC);
|
tree.insert(0, generateConclusion(varD, LABEL_VAR, UIC));
|
||||||
|
// todo implement
|
||||||
|
StringBuilder temp = new StringBuilder();
|
||||||
|
temp.append(AXC).append("{var default}");
|
||||||
|
tree.insert(0, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(VarStepWithLet varL) {
|
public void visit(VarStepWithLet varL) {
|
||||||
generateConclusion(varL, LABEL_VAR, UIC);
|
tree.insert(0, generateConclusion(varL, LABEL_VAR, UIC));
|
||||||
|
// todo implement
|
||||||
|
StringBuilder temp = new StringBuilder();
|
||||||
|
temp.append(AXC).append("{var with let}");
|
||||||
|
tree.insert(0, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LetStepDefault letD) {
|
public void visit(LetStepDefault letD) {
|
||||||
generateConclusion(letD, LABEL_LET, UIC);
|
tree.insert(0, generateConclusion(letD, LABEL_LET, BIC));
|
||||||
|
letD.getPremise().accept(this);
|
||||||
|
// todo implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(AppTerm appTerm) {
|
public void visit(AppTerm appTerm) {
|
||||||
|
|
||||||
@ -165,6 +199,8 @@ public class LatexCreator implements StepVisitor, TermVisitor, TypeVisitor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(NamedType named) {
|
public void visit(NamedType named) {
|
||||||
|
|
||||||
|
@ -5,18 +5,43 @@ import com.vaadin.flow.component.dependency.JsModule;
|
|||||||
import com.vaadin.flow.component.html.Div;
|
import com.vaadin.flow.component.html.Div;
|
||||||
import com.vaadin.flow.component.littemplate.LitTemplate;
|
import com.vaadin.flow.component.littemplate.LitTemplate;
|
||||||
import com.vaadin.flow.component.template.Id;
|
import com.vaadin.flow.component.template.Id;
|
||||||
|
import edu.kit.typicalc.view.MathjaxAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a tree from LaTeX using MathJax and allows for step-by-step-revealing for
|
||||||
|
* proof trees that use the bussproofs package. Relies on MathjaxProofTreeJS to interact
|
||||||
|
* with MathJax.
|
||||||
|
*/
|
||||||
@Tag("tc-proof-tree")
|
@Tag("tc-proof-tree")
|
||||||
@JsModule("./src/mathjax-proof-tree.ts")
|
@JsModule("./src/mathjax-proof-tree.ts")
|
||||||
public class MathjaxProofTree extends LitTemplate {
|
public class MathjaxProofTree extends LitTemplate implements MathjaxAdapter {
|
||||||
|
|
||||||
@Id("tc-content")
|
@Id("tc-content")
|
||||||
private Div content;
|
private Div content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* todo Creates the hello world template.
|
* Creates a new HTML element that renders the proof tree and cuts it into steps.
|
||||||
|
* The latex String must consist of exactly one proof tree environment in order for
|
||||||
|
* this element to work. In other cases the expected behaviour is undefined.
|
||||||
|
* @param latex the LaTeX-String to render with MathJax
|
||||||
*/
|
*/
|
||||||
public MathjaxProofTree() {
|
public MathjaxProofTree(String latex) {
|
||||||
content.add(getTranslation("demo-tree"));
|
content.add(latex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStepCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showStep(int n) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scale(double newScaling) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package edu.kit.typicalc.view.content.typeinferencecontent;
|
||||||
|
|
||||||
|
import com.vaadin.flow.component.Tag;
|
||||||
|
import com.vaadin.flow.component.dependency.JsModule;
|
||||||
|
import com.vaadin.flow.component.html.Div;
|
||||||
|
import com.vaadin.flow.component.littemplate.LitTemplate;
|
||||||
|
import com.vaadin.flow.component.template.Id;
|
||||||
|
import edu.kit.typicalc.view.MathjaxAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the constraints and unification from LaTeX using MathJax and allows step-by-
|
||||||
|
* step-revealing capabilities. Relies on MathjaxUnificationJS to interact with MathJax.
|
||||||
|
*/
|
||||||
|
@Tag("tc-unification")
|
||||||
|
@JsModule("./src/mathjax-unification.ts")
|
||||||
|
public class MathjaxUnification extends LitTemplate implements MathjaxAdapter {
|
||||||
|
|
||||||
|
@Id("tc-content")
|
||||||
|
private Div content;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new HTML element that renders the constraints and unification and
|
||||||
|
* calculates the steps.
|
||||||
|
* @param latex the LaTeX-String to render with MathJax
|
||||||
|
*/
|
||||||
|
public MathjaxUnification(String latex) {
|
||||||
|
content.add(latex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStepCount() {
|
||||||
|
// todo implement
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showStep(int n) {
|
||||||
|
// todo implement
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scale(double newScaling) {
|
||||||
|
// todo implement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import com.vaadin.flow.component.applayout.DrawerToggle;
|
|||||||
import com.vaadin.flow.component.avatar.Avatar;
|
import com.vaadin.flow.component.avatar.Avatar;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.dependency.CssImport;
|
import com.vaadin.flow.component.dependency.CssImport;
|
||||||
|
import com.vaadin.flow.component.dependency.JavaScript;
|
||||||
import com.vaadin.flow.component.dependency.JsModule;
|
import com.vaadin.flow.component.dependency.JsModule;
|
||||||
import com.vaadin.flow.component.html.H1;
|
import com.vaadin.flow.component.html.H1;
|
||||||
import com.vaadin.flow.component.html.Image;
|
import com.vaadin.flow.component.html.Image;
|
||||||
@ -20,14 +21,15 @@ import com.vaadin.flow.component.tabs.Tabs;
|
|||||||
import edu.kit.typicalc.model.ModelImpl;
|
import edu.kit.typicalc.model.ModelImpl;
|
||||||
import edu.kit.typicalc.model.TypeInfererInterface;
|
import edu.kit.typicalc.model.TypeInfererInterface;
|
||||||
import edu.kit.typicalc.model.parser.ParseError;
|
import edu.kit.typicalc.model.parser.ParseError;
|
||||||
import edu.kit.typicalc.view.content.typeinferencecontent.TypeInferenceView;
|
|
||||||
import edu.kit.typicalc.presenter.Presenter;
|
import edu.kit.typicalc.presenter.Presenter;
|
||||||
|
import edu.kit.typicalc.view.content.typeinferencecontent.TypeInferenceView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main view is a top-level placeholder for other views.
|
* The main view is a top-level placeholder for other views.
|
||||||
*/
|
*/
|
||||||
@CssImport("./styles/view/main/main-view.css")
|
@CssImport("./styles/view/main/main-view.css")
|
||||||
@JsModule("./styles/shared-styles.js")
|
@JsModule("./styles/shared-styles.js")
|
||||||
|
@JavaScript("./src/tex-svg-full.js")
|
||||||
public class MainViewImpl extends AppLayout implements MainView {
|
public class MainViewImpl extends AppLayout implements MainView {
|
||||||
|
|
||||||
private H1 viewTitle;
|
private H1 viewTitle;
|
||||||
|
@ -1,24 +1,44 @@
|
|||||||
package edu.kit.typicalc.view.main;
|
package edu.kit.typicalc.view.main;
|
||||||
|
|
||||||
import com.vaadin.flow.component.Tag;
|
import com.vaadin.flow.component.Tag;
|
||||||
import com.vaadin.flow.component.dependency.JavaScript;
|
|
||||||
import com.vaadin.flow.component.dependency.JsModule;
|
import com.vaadin.flow.component.dependency.JsModule;
|
||||||
import com.vaadin.flow.component.html.Div;
|
import com.vaadin.flow.component.html.Div;
|
||||||
import com.vaadin.flow.component.littemplate.LitTemplate;
|
import com.vaadin.flow.component.littemplate.LitTemplate;
|
||||||
import com.vaadin.flow.component.template.Id;
|
import com.vaadin.flow.component.template.Id;
|
||||||
|
import edu.kit.typicalc.view.MathjaxAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders static LaTeX content using MathJax. Relies on MathjaxDisplayJS to interact
|
||||||
|
* with MathJax.
|
||||||
|
*/
|
||||||
@Tag("tc-display")
|
@Tag("tc-display")
|
||||||
@JsModule("./src/mathjax-display.ts")
|
@JsModule("./src/mathjax-display.ts")
|
||||||
@JavaScript("./src/tex-svg-full.js")
|
public class MathjaxDisplay extends LitTemplate implements MathjaxAdapter {
|
||||||
public class MathjaxDisplay extends LitTemplate {
|
|
||||||
|
|
||||||
@Id("tc-content")
|
@Id("tc-content")
|
||||||
private Div content;
|
private Div content;
|
||||||
/**
|
/**
|
||||||
* todo Creates the hello world template.
|
* Creates a new HTML element that renders the LaTeX code.
|
||||||
|
*
|
||||||
|
* @param latex the LaTeX string to render with MathJax
|
||||||
*/
|
*/
|
||||||
public MathjaxDisplay() {
|
public MathjaxDisplay(String latex) {
|
||||||
content.add(getTranslation("abs-rule"));
|
content.add(latex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStepCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showStep(int n) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scale(double newScaling) {
|
||||||
|
// todo implement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user