Handle preprocessor lines like "#pragma"

This commit is contained in:
Martin Carlberg
2013-01-07 20:29:35 +01:00
parent bf32b90702
commit cfe718f4ef
3 changed files with 22 additions and 2 deletions
+5
View File
@@ -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, "//");
}
});
+15 -2
View File
@@ -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
+2
View File
@@ -202,6 +202,8 @@ if (!exports.acorn) {
exports.MethodDeclarationStatement = ignore;
exports.PreprocessStatement = ignore;
exports.MethodDeclarationStatement = function(node, st, c) {
c(node.body, st, "Statement");
}