正在加载此比较的其余部分。

wrap-pony-code-snippet

创建于 差异永不过期
6 删除
647 行
11 添加
650 行
(function () {
(function () {
"use strict";
"use strict";
const PLAYPEN_URL = "https://playground.ponylang.io";
const PLAYPEN_URL = "https://playground.ponylang.io";


var samples = 2;
var samples = 2;


function optionalLocalStorageGetItem(key) {
function optionalLocalStorageGetItem(key) {
try {
try {
return localStorage.getItem(key);
return localStorage.getItem(key);
} catch (e) {
} catch (e) {
return null;
return null;
}
}
}
}


function optionalLocalStorageSetItem(key, value) {
function optionalLocalStorageSetItem(key, value) {
try {
try {
window.localStorage.setItem(key, value);
window.localStorage.setItem(key, value);
} catch (e) {
} catch (e) {
// ignore
// ignore
}
}
}
}


function build_themes(themelist) {
function build_themes(themelist) {
// Load all ace themes, sorted by their proper name.
// Load all ace themes, sorted by their proper name.
var themes = themelist.themes;
var themes = themelist.themes;
themes.sort(function (a, b) {
themes.sort(function (a, b) {
if (a.caption < b.caption) {
if (a.caption < b.caption) {
return -1;
return -1;
} else if (a.caption > b.caption) {
} else if (a.caption > b.caption) {
return 1;
return 1;
}
}
return 0;
return 0;
});
});


var themeopt,
var themeopt,
themefrag = document.createDocumentFragment();
themefrag = document.createDocumentFragment();
for (var i = 0; i < themes.length; i++) {
for (var i = 0; i < themes.length; i++) {
themeopt = document.createElement("option");
themeopt = document.createElement("option");
themeopt.setAttribute("val", themes[i].theme);
themeopt.setAttribute("val", themes[i].theme);
themeopt.textContent = themes[i].caption;
themeopt.textContent = themes[i].caption;
themefrag.appendChild(themeopt);
themefrag.appendChild(themeopt);
}
}
document.getElementById("themes").appendChild(themefrag);
document.getElementById("themes").appendChild(themefrag);
}
}


function send(path, data, callback, button, message, result) {
function send(path, data, callback, button, message, result) {
button.disabled = true;
button.disabled = true;


set_result(result, "<p class=message>" + message);
set_result(result, "<p class=message>" + message);


var request = new XMLHttpRequest();
var request = new XMLHttpRequest();
request.open("POST", path, true);
request.open("POST", path, true);
request.setRequestHeader("Content-Type", "application/json");
request.setRequestHeader("Content-Type", "application/json");
request.onreadystatechange = function () {
request.onreadystatechange = function () {
button.disabled = false;
button.disabled = false;
if (request.readyState == 4) {
if (request.readyState == 4) {
var json;
var json;


try {
try {
json = JSON.parse(request.response);
json = JSON.parse(request.response);
} catch (e) {
} catch (e) {
console.log("JSON.parse(): " + e);
console.log("JSON.parse(): " + e);
}
}


if (request.status == 200) {
if (request.status == 200) {
callback(json);
callback(json);
} else if (request.status === 0) {
} else if (request.status === 0) {
set_result(result, "<p class=error>Connection failure" +
set_result(result, "<p class=error>Connection failure" +
"<p class=error-explanation>Are you connected to the Internet?");
"<p class=error-explanation>Are you connected to the Internet?");
} else {
} else {
set_result(result, "<p class=error>Something went wrong" +
set_result(result, "<p class=error>Something went wrong" +
"<p class=error-explanation>The HTTP request produced a response with status code " + request.status + ".");
"<p class=error-explanation>The HTTP request produced a response with status code " + request.status + ".");
}
}
}
}
};
};
request.timeout = 20000;
request.timeout = 20000;
request.ontimeout = function () {
request.ontimeout = function () {
set_result(result, "<p class=error>Connection timed out" +
set_result(result, "<p class=error>Connection timed out" +
"<p class=error-explanation>Are you connected to the Internet?");
"<p class=error-explanation>Are you connected to the Internet?");
};
};
request.send(JSON.stringify(data));
request.send(JSON.stringify(data));
}
}


var PYGMENTS_TO_ACE_MAPPINGS = {
var PYGMENTS_TO_ACE_MAPPINGS = {
'asm': {
'asm': {
'c': 'ace_comment', // Comment,
'c': 'ace_comment', // Comment,
'na': 'ace_support ace_function ace_directive', // Name.Attribute,
'na': 'ace_support ace_function ace_directive', // Name.Attribute,
'no': 'ace_constant', // Name.Constant,
'no': 'ace_constant', // Name.Constant,
'nl': 'ace_entity ace_name ace_function', // Name.Label,
'nl': 'ace_entity ace_name ace_function', // Name.Label,
'nv': 'ace_variable ace_parameter ace_register', // Name.Variable,
'nv': 'ace_variable ace_parameter ace_register', // Name.Variable,
'mh': 'ace_constant ace_character ace_hexadecimal', // Number.Hex,
'mh': 'ace_constant ace_character ace_hexadecimal', // Number.Hex,
'mi': 'ace_constant ace_character ace_decimal', // Number.Integer,
'mi': 'ace_constant ace_character ace_decimal', // Number.Integer,
'p': 'ace_punctuation', // Punctuation,
'p': 'ace_punctuation', // Punctuation,
's': 'ace_string', // String,
's': 'ace_string', // String,
'sc': 'ace_string', // String.Char,
'sc': 'ace_string', // String.Char,
'': '', // Text,
'': '', // Text,
},
},
'llvm-ir': {
'llvm-ir': {
'c': 'ace_comment', // Comment
'c': 'ace_comment', // Comment
'k': 'ace_keyword', // Keyword
'k': 'ace_keyword', // Keyword