Skip to content

Instantly share code, notes, and snippets.

@starakaj
Created February 22, 2021 21:46
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 starakaj/4ea3aa2850fe3870bd9130b4f56e7136 to your computer and use it in GitHub Desktop.
Save starakaj/4ea3aa2850fe3870bd9130b4f56e7136 to your computer and use it in GitHub Desktop.
Creating statements
function translateSource(data: string, outPath: string) {
let paintFunctionStatements: Statement[] = [];
const parser = new html2.Parser({
onopentag(name: string, attribs: {[s: string]: string}) {
if (name === "rect") {
const statements = makeStatementsFromRectAttribs(attribs);
paintFunctionStatemens = paintFunctionStatements.concat(statements);
}
}
});
parser.parseComplete(data);
const program: Program = makePaintProgramForStatements(paintFunctionStatements);
const outputString = generate(program);
fs.writeFile(outPath, outputString, { encoding: "utf8" }, () => {
console.log(`Wrote output to ${outPath}`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment