From cfe718f4ef02a3314e308cba57259f6ce9fab803 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 7 Jan 2013 20:05:20 +0100 Subject: [PATCH] Handle preprocessor lines like "#pragma" --- Objective-J/ObjJAcornCompiler.js | 5 +++++ Objective-J/acorn.js | 17 +++++++++++++++-- Objective-J/acornwalk.js | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index 941005aa3..d8a67adb0 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -728,5 +728,10 @@ ObjectExpression: function(node, st, c) { } c(prop.value, st, "Expression"); } +}, +PreprocessStatement: function(node, st, c) { + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, node.start)); + st.compiler.lastPos = node.start; + CONCAT(st.compiler.jsBuffer, "//"); } }); diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 0455cef66..dffd4c9bc 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -531,8 +531,6 @@ if (!exports.acorn) { ++tokPos; } else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) { ++tokPos; - } else if (ch === 35 && options.objj) { - skipLineComment(1); } else { break; } @@ -699,6 +697,16 @@ if (!exports.acorn) { return readToken_at(code); return false; + case 35: // '#' + if (options.objj) { + var start = tokPos; + var ch = input.charCodeAt(++tokPos); + while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8329) // End of line + ch = input.charCodeAt(++tokPos); + return finishToken(_preprocess, input.slice(start, tokPos)); + } + return false; + case 126: // '~' return finishOp(_prefix, 1); } @@ -1359,6 +1367,11 @@ if (!exports.acorn) { node.filename = parseStringNumRegExpLiteral(); return finishNode(node, "ImportStatement"); + // This is a Objective-J statement + case _preprocess: + next(); + return finishNode(node, "PreprocessStatement"); + // If the statement does not start with a statement keyword or a // brace, it's an ExpressionStatement or LabeledStatement. We // simply start parsing an expression, and afterwards, if the diff --git a/Objective-J/acornwalk.js b/Objective-J/acornwalk.js index 09f359827..e03e99e1f 100644 --- a/Objective-J/acornwalk.js +++ b/Objective-J/acornwalk.js @@ -202,6 +202,8 @@ if (!exports.acorn) { exports.MethodDeclarationStatement = ignore; + exports.PreprocessStatement = ignore; + exports.MethodDeclarationStatement = function(node, st, c) { c(node.body, st, "Statement"); }