-
Notifications
You must be signed in to change notification settings - Fork 1
/
canonicalizer.html
117 lines (110 loc) · 4.79 KB
/
canonicalizer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://github.com/stan-dev/stanc3/releases/download/nightly/stanc.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="prism/prism.css">
<link rel="stylesheet" href="https://prismjs.com/plugins/line-numbers/prism-line-numbers.css">
<link rel="stylesheet" href="prism/prism-live.css">
<link rel="stylesheet" href="style.css">
<script src="demo.js"></script>
<title>Stan canonicalizer</title>
</head>
<body>
<main>
<div class="page-links"><a href="index.html">Print C++</a></div>
<div class="page-links"><a href="pedantic.html">Pedantic check</a></div>
<div class="page-links"><a href="signatures.html">Supported signatures</a></div>
<div class="page-links"><a href="optimization.html">Optimization diff</a></div>
<div class="page-links"><a href="autoformat.html">Auto format</a></div>
<div class="page-links selected-link"><a class="selected" href="canonicalizer.html">Canonicalizer</a></div>
<div style="clear:both;"></div>
<textarea id="model" class="prism-live line-numbers language-stan" spellcheck="false"></textarea>
<div class="buttons">
<div class="action_btn">
<button id="compile" class="action_btn submit">Print canonical</button>
<button id="url" class="action_btn cancel">Generate URL</button>
<p id="saved"></p>
</div>
</div>
<input type="checkbox" name="parantheses" checked=checked
id="parentheses" /> Parentheses
<input type="checkbox" name="braces" checked=checked id="braces" />
Braces
<input type="checkbox" name="deprecations" checked=checked
id="deprecations" /> Deprecations
<br/><br/>
Line length limit: <input type= "number" id="line-length" value = "78" style="width: 60px;" />
<div id="url-box" class="error-box"></div>
<div id="error" class="error-box"></div>
<pre><code id = "result" class="language-stan"></code></pre>
</main>
</body>
<script>
function canonicalizer(line_length) {
let line_length_arg = "max-line-length=" + line_length.toString()
let args = ["auto-format", line_length_arg]
let canonicalize_modes = ""
if ($("#parentheses")[0].checked) {
canonicalize_modes += "parentheses"
}
if ($("#braces")[0].checked) {
if (canonicalize_modes.length > 0) {
canonicalize_modes += ","
}
canonicalize_modes += "braces"
}
if ($("#deprecations")[0].checked) {
if (canonicalize_modes.length > 0) {
canonicalize_modes += ","
}
canonicalize_modes += "deprecations"
}
if (canonicalize_modes.length > 0) {
args.push("canonicalize="+canonicalize_modes)
}
var model = stanc("test_model",$("#model").val(), args);
if(model.errors) {
$("#error").html(model.errors[1].replace(/\n/g, "<br/>").replace(/\s/g, ' '));
$("#result").html("");
} else {
$("#result").html(Prism.highlight(model.result, Prism.languages.stan, 'stan'));
$("#error").html("");
}
}
$(document).ready(function(){
let model_url = GetURLParameter("model")
let line_length = GetURLParameter("line_length")
if (!line_length) {
line_length = 78
} else {
$("#line-length").val(line_length)
}
let model = "cGFyYW1ldGVycyB7CiAgcmVhbCB5WzVdOwogIHJlYWwgeDsKfQptb2RlbCB7CiAgZm9yIChpIGluIDEgOiA1KQogICAgdGFyZ2V0ICs9IG5vcm1hbF9sb2coeCwgeVtpXSwgKDAuNSArIDEpKTsKfQ%3D%3D"
if (model_url) {
model = model_url
}
decoded_model = atob(decodeURIComponent(model))
$("#model").val(decoded_model)
$("code", $("#model").prev()).html(decoded_model)
Prism.highlightAll()
$("#model").focus(function () {
$("#url-box").html("");
})
$("#compile").click(function() {
line_length = $("#line-length").val()
canonicalizer(line_length);
});
canonicalizer(line_length);
$("#url").click(function () {
let url = window.location.href.split('?')[0] + "?line_length="+ $("#line-length").val() + "&model=" + encodeURIComponent(btoa($("#model").val()))
$("#url-box").html(url);
});
});
</script>
<script src="https://blissfuljs.com/bliss.shy.min.js"></script>
<script src="prism/prism.js"></script>
<script src="https://prismjs.com/plugins/line-numbers/prism-line-numbers.js"></script>
<script src="prism/prism-live.js"></script>
</html>