Skip to content

Instantly share code, notes, and snippets.

@MrChico
Created June 20, 2018 20:30
Show Gist options
  • Save MrChico/5cb4bce52da1027e6a84e5e5e8d5c388 to your computer and use it in GitHub Desktop.
Save MrChico/5cb4bce52da1027e6a84e5e5e8d5c388 to your computer and use it in GitHub Desktop.
const fs = require("fs");
let pre = "/private/var/folders/fb/0m3l_cnn4w57fhsv7q_lx5780000gn/T/klab/cfb53897/nodes/1103642064.json"
let post = "/private/var/folders/fb/0m3l_cnn4w57fhsv7q_lx5780000gn/T/klab/cfb53897/nodes/563029515.json"
const getTerm = nodePath => {
let read = fs.readFileSync(nodePath).toString()
return JSON.parse(read).term
}
const writeCell = (preCell, postCell) => {
//If the cell is a leaf
if (preCell.arity == 1) {
return preCell.label +
preCell.args[0].token + "=>" + postCell.args[0].token +
preCell.label.replace('<','</')
}
console.log("the label is: " + preCell.label)
let result = preCell.label + '\n'
for (let i = 0; i < preCell.arity; i++) {
result = result + writeCell(preCell.args[i], postCell.args[i]);
}
console.log("preCell is now:" + preCell.toString())
return result + '\n' + preCell.label.replace('<','</');
}
const test = () => {
let preterm = getTerm(pre);
console.log(preterm)
console.log(writeCell(preterm, getTerm(post)))
}
test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment