diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-01-02 17:37:45 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-01-02 17:38:14 -0800 |
commit | e38e23dec37f0e110775312575b825bfdd31cf2e (patch) | |
tree | 6809b18d47f22570ad0b5749c353ab760d298598 | |
parent | 1cc0066302ceb4aa02fab528c20b9145d46aac6e (diff) |
support #include x.js in our preprocessed js sources
-rw-r--r-- | src/parseTools.js | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index ff981264..874514b1 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -16,6 +16,7 @@ function processMacros(text) { // Simple #if/else/endif preprocessing for a file. Checks if the // ident checked is true in our global. +// Also handles #include x.js (similar to C #include <file>) function preprocess(text) { var lines = text.split('\n'); var ret = ''; @@ -30,25 +31,29 @@ function preprocess(text) { ret += line + '\n'; } } else { - if (line[1] && line[1] == 'i') { // if - var parts = line.split(' '); - var ident = parts[1]; - var op = parts[2]; - var value = parts[3]; - if (op) { - if (op === '==') { - showStack.push(ident in this && this[ident] == value); - } else if (op === '!=') { - showStack.push(!(ident in this && this[ident] == value)); + if (line[1] == 'i') { + if (line[2] == 'f') { // if + var parts = line.split(' '); + var ident = parts[1]; + var op = parts[2]; + var value = parts[3]; + if (op) { + if (op === '==') { + showStack.push(ident in this && this[ident] == value); + } else if (op === '!=') { + showStack.push(!(ident in this && this[ident] == value)); + } else { + error('unsupported preprecessor op ' + op); + } } else { - error('unsupported preprecessor op ' + op); + showStack.push(ident in this && this[ident] > 0); } - } else { - showStack.push(ident in this && this[ident] > 0); + } else if (line[2] == 'n') { // include + ret += '\n' + read(line.substr(line.indexOf(' ')+1)) + '\n' } - } else if (line[2] && line[2] == 'l') { // else + } else if (line[2] == 'l') { // else showStack.push(!showStack.pop()); - } else if (line[2] && line[2] == 'n') { // endif + } else if (line[2] == 'n') { // endif showStack.pop(); } else { throw "Unclear preprocessor command: " + line; |