Modify rendering rules to handle precedence
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
fa5536f504
commit
85b81ffc98
|
@ -1,7 +1,28 @@
|
||||||
<div id="{{ .Get "id" }}"></div>
|
<div id="{{ .Get "id" }}"></div>
|
||||||
<script>
|
<script>
|
||||||
const renderRules =
|
const renderRules =
|
||||||
`LatexListNil @ latexlist(nil, nil) <-;
|
`
|
||||||
|
PrecApp @ prec(app(?l, ?r), 100, left) <-;
|
||||||
|
PrecPlus @ prec(plus(?l, ?r), 80, either) <-;
|
||||||
|
PrecAbs @ prec(abs(?x, ?t, ?e), 0, right) <-;
|
||||||
|
PrecArr @ prec(tarr(?l, ?r), 0, right) <-;
|
||||||
|
|
||||||
|
SelectHead @ select(cons([?t, ?v], ?rest), ?default, ?v) <- ?t;
|
||||||
|
SelectTail @ select(cons([?t, ?v], ?rest), ?default, ?found) <- not(?t), select(?rest, ?default, ?found);
|
||||||
|
SelectEmpty @ select(nil, ?default, ?default) <-;
|
||||||
|
|
||||||
|
ParenthAssocLeft @ parenthassoc(?a_i, left, right) <-;
|
||||||
|
ParenthAssocRight @ parenthassoc(?a_i, right, left) <-;
|
||||||
|
ParenthAssocNone @ parenthassoc(?a_i, none, ?pos) <-;
|
||||||
|
ParenthAssocNeq @ parenthassoc(?a_i, ?a_o, ?pos) <- not(symeq(?a_i, ?a_o));
|
||||||
|
|
||||||
|
Parenth @ parenth(?inner, ?outer, ?pos, ?strin, ?strout) <-
|
||||||
|
prec(?inner, ?p_i, ?a_i), prec(?outer, ?p_o, ?a_o),
|
||||||
|
join(["(", ?strin, ")"], ?strinparen),
|
||||||
|
select([ [less(?p_i, ?p_o), strinparen], [less(?p_o, ?p_i), ?strin], [ parenthassoc(?a_i, ?a_o, ?pos), ?strinparen ] ], ?strin, ?strout);
|
||||||
|
ParenthFallback @ parenth(?inner, ?outer, ?pos, ?strin, ?strin) <-;
|
||||||
|
|
||||||
|
LatexListNil @ latexlist(nil, nil) <-;
|
||||||
LatexListCons @ latexlist(cons(?x, ?xs), cons(?l_x, ?l_s)) <- latex(?x, ?l_x), latexlist(?xs, ?l_s);
|
LatexListCons @ latexlist(cons(?x, ?xs), cons(?l_x, ?l_s)) <- latex(?x, ?l_x), latexlist(?xs, ?l_s);
|
||||||
|
|
||||||
IntercalateNil @ intercalate(?sep, nil, nil) <-;
|
IntercalateNil @ intercalate(?sep, nil, nil) <-;
|
||||||
|
@ -16,15 +37,27 @@
|
||||||
LatexIntLit @ latex(intlit(?i), ?l) <- latex(?i, ?l);
|
LatexIntLit @ latex(intlit(?i), ?l) <- latex(?i, ?l);
|
||||||
LatexStrLit @ latex(strlit(?s), ?l) <- latex(?s, ?l);
|
LatexStrLit @ latex(strlit(?s), ?l) <- latex(?s, ?l);
|
||||||
LatexVar @ latex(var(?s), ?l) <- latex(?s, ?l);
|
LatexVar @ latex(var(?s), ?l) <- latex(?s, ?l);
|
||||||
LatexPlus @ latex(plus(?e_1, ?e_2), ?l) <- latex(?e_1, ?l_1), latex(?e_2, ?l_2), join([?l_1, " + ", ?l_2], ?l);
|
LatexPlus @ latex(plus(?e_1, ?e_2), ?l) <-
|
||||||
|
latex(?e_1, ?l_1), latex(?e_2, ?l_2),
|
||||||
|
parenth(?e_1, plus(?e_1, ?e_2), left, ?l_1, ?lp_1),
|
||||||
|
parenth(?e_2, plus(?e_1, ?e_2), right, ?l_2, ?lp_2),
|
||||||
|
join([?lp_1, " + ", ?lp_2], ?l);
|
||||||
LatexPair @ latex(pair(?e_1, ?e_2), ?l) <- latex(?e_1, ?l_1), latex(?e_2, ?l_2), join(["(", ?l_1, ", ", ?l_2, ")"], ?l);
|
LatexPair @ latex(pair(?e_1, ?e_2), ?l) <- latex(?e_1, ?l_1), latex(?e_2, ?l_2), join(["(", ?l_1, ", ", ?l_2, ")"], ?l);
|
||||||
LatexAbs @ latex(abs(?x, ?t, ?e), ?l) <- latex(?e, ?l_e), latex(?t, ?l_t), latex(?x, ?l_x), join(["\\\\lambda ", ?l_x, " : ", ?l_t, " . ", ?l_e], ?l);
|
LatexAbs @ latex(abs(?x, ?t, ?e), ?l) <- latex(?e, ?l_e), latex(?t, ?l_t), latex(?x, ?l_x), join(["\\\\lambda ", ?l_x, " : ", ?l_t, " . ", ?l_e], ?l);
|
||||||
LatexApp @ latex(app(?e_1, ?e_2), ?l) <- latex(?e_1, ?l_1), latex(?e_2, ?l_2), join([?l_1, " \\\\enspace ", ?l_2], ?l);
|
LatexApp @ latex(app(?e_1, ?e_2), ?l) <-
|
||||||
|
latex(?e_1, ?l_1), latex(?e_2, ?l_2),
|
||||||
|
parenth(?e_1, app(?e_1, ?e_2), left, ?l_1, ?lp_1),
|
||||||
|
parenth(?e_2, app(?e_1, ?e_2), right, ?l_2, ?lp_2),
|
||||||
|
join([?lp_1, " \\\\enspace ", ?lp_2], ?l);
|
||||||
|
|
||||||
LatexTInt @ latex(tint, "\\\\text{tint}") <-;
|
LatexTInt @ latex(tint, "\\\\text{tint}") <-;
|
||||||
LatexTStr @ latex(tstr, "\\\\text{tstr}") <-;
|
LatexTStr @ latex(tstr, "\\\\text{tstr}") <-;
|
||||||
LatexTArr @ latex(tarr(?t_1, ?t_2), ?l) <- latex(?t_1, ?l_1), latex(?t_2, ?l_2), join([?l_1, " \\\\to ", ?l_2], ?l);
|
LatexTArr @ latex(tarr(?t_1, ?t_2), ?l) <-
|
||||||
LatexTPair @ latex(tpair(?t_1, ?t_2), ?l) <- latex(?t_1, ?l_1), latex(?t_2, ?l_2), join([?l_1, " \\\\times ", ?l_2], ?l);
|
latex(?t_1, ?l_1), latex(?t_2, ?l_2),
|
||||||
|
parenth(?t_1, tarr(?t_1, ?t_2), left, ?l_1, ?lp_1),
|
||||||
|
parenth(?t_2, tarr(?t_1, ?t_2), right, ?l_2, ?lp_2),
|
||||||
|
join([?lp_1, " \\\\to ", ?lp_2], ?l);
|
||||||
|
LatexTPair @ latex(tpair(?t_1, ?t_2), ?l) <- latex(?t_1, ?l_1), latex(?t_2, ?l_2), join(["(", ?l_1, ", ", ?l_2, ")"], ?l);
|
||||||
|
|
||||||
LatexTypeEmpty @ latex(empty, "\\\\varnothing") <-;
|
LatexTypeEmpty @ latex(empty, "\\\\varnothing") <-;
|
||||||
LatexTypeExtend @ latex(extend(?a, ?b, ?c), ?l) <- latex(?a, ?l_a), latex(?b, ?l_b), latex(?c, ?l_c), join([?l_a, " , ", ?l_b, " : ", ?l_c], ?l);
|
LatexTypeExtend @ latex(extend(?a, ?b, ?c), ?l) <- latex(?a, ?l_a), latex(?b, ?l_b), latex(?c, ?l_c), join([?l_a, " , ", ?l_b, " : ", ?l_c], ?l);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user