Skip to content

Instantly share code, notes, and snippets.

@ndmitchell
Created February 18, 2019 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndmitchell/5739a77f94ce1e0455c793aac8192ffa to your computer and use it in GitHub Desktop.
Save ndmitchell/5739a77f94ce1e0455c793aac8192ffa to your computer and use it in GitHub Desktop.
Makefile to Shake online converter outline
<!DOCTYPE html>
<html>
<head>
<title>Shake Convertor</title>
<style type="text/css">
html, body, #root, tr {width: 100%; height: 100%;}
td {height: 100%}
#input, #output {height: 100%; width: 100%;}
#output {border: 2px solid gray;}
</style>
<script src="jquery.js"></script>
<script src="convert.js"></script>
<script>
var examples =
{"simple":"output:\n need input\n echo test > output"};
$(function(){
$input = $("#input");
$output = $("#output");
$input.text(examples.simple);
$input.keyup(function(){
$output.text(convertShake($input.val()));
});
$input.keyup();
})
</script>
</head>
<body>
<table id="root">
<tr>
<td><textarea id="input"></textarea></td>
<td><pre id="output"></pre></td>
</tr>
</table>
</body>
</html>
function convertMakefile(s) // :: Makefile -> Shakefile
{
return s;
}
function convertNinja(s) // :: Ninja -> Shakefile
{
return s;
}
function convertShake(s) // :: Shakefile -> Shake
{
var res = [];
var src = s.split("\n");
res.push("import Development.Shake");
for (var i = 0; i < src.length; i++)
{
var x = src[i];
if (x.substr(0,8) === "include ")
res.push("import " + x);
}
res.push("");
res.push("main = shakeWithArgs shakeOptions $ do")
for (var i = 0; i < src.length; i++)
{
var x = src[i];
if (x.substr(0,8) === "include ")
null;
else if (x.substr(0,1) === "#")
res.push(" -- " + x.substr(1));
else if (x.charAt(x.length-1) === ":")
{
res.push(" \"" + x.substr(0,x.length-1) + "\" *> \\out -> do");
}
else if (x.trimLeft().substr(0,5) === "need ")
res.push(" need [\"" + x.trimLeft().substr(5) + "\"]");
else if (x.trim() === "")
res.push("");
else
res.push(" cmd Shell \"" + x.trim() + "\"");
}
return res.join("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment