I need to split a JavaScript file into single instructions. For example
a = 2;
foo()
function bar() {
b = 5;
print(\"spam\");
}
has to
JavaScript is tricky to parse; you need a full JavaScript parser. The DMS Software Reengineering Toolkit can parse full JavaScript and build a corresponding AST. AST operators can then be used to walk over the tree to "split it". Even easier, however, is to apply source-to-source transformations that look for one surface syntax (JavaScript) pattern, and replace it by another. You can use such transformations to insert the instrumentation into the code, rather than splitting the code to make holds in which to do the insertions. After the transformations are complete, DMS can regenerate valid JavaScript code (complete with the orignal comments if unaffected).