From 47ecd40c4fa137f1a1b1a69bc3a6cfd574fb615a Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Fri, 9 Apr 2010 14:26:29 -0700 Subject: [PATCH] Made the pre-processor capable of recognizing and ignoring Xcode's '#pragma mark' mark-ups Conflicts: Objective-J/Preprocessor.js --- Objective-J/Preprocessor.js | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Objective-J/Preprocessor.js b/Objective-J/Preprocessor.js index d90a71b075..83bf6f45ec 100644 --- a/Objective-J/Preprocessor.js +++ b/Objective-J/Preprocessor.js @@ -34,6 +34,8 @@ var TOKEN_ACCESSORS = "accessors", TOKEN_SUPER = "super", TOKEN_VAR = "var", TOKEN_IN = "in", + TOKEN_PRAGMA = "pragma", + TOKEN_MARK = "mark", TOKEN_EQUAL = '=', TOKEN_PLUS = '+', @@ -50,6 +52,7 @@ var TOKEN_ACCESSORS = "accessors", TOKEN_OPEN_BRACKET = '[', TOKEN_DOUBLE_QUOTE = '"', TOKEN_PREPROCESSOR = '@', + TOKEN_HASH = '#', TOKEN_CLOSE_BRACKET = ']', TOKEN_QUESTION_MARK = '?', TOKEN_OPEN_PARENTHESIS = '(', @@ -363,6 +366,33 @@ Preprocessor.prototype.directive = function(tokens, aStringBuffer, allowedDirect return buffer; } +Preprocessor.prototype.hash = function(tokens, aStringBuffer) +{ + // Grab the next token, C preprocessor directives follow '#' immediately. + var buffer = aStringBuffer ? aStringBuffer : new StringBuffer(), + token = tokens.next(); + + // #pragma (C Preprocessor directive) + if (token === TOKEN_PRAGMA) + { + token = tokens.skip_whitespace(); + + // '#pragma mark' directive is used in Xcode editor for creating labels, + // which is irrelevant to Cappuccino - just swallow this line + if (token === TOKEN_MARK) + { + while ((token = tokens.next()).indexOf("\n") < 0); + } + } + // if not a #pragma directive, it should not be processed here + else + { + tokens.previous(); + CONCAT(aStringBuffer, TOKEN_HASH); + return; + } +} + Preprocessor.prototype.implementation = function(tokens, /*StringBuffer*/ aStringBuffer) { var buffer = aStringBuffer, @@ -542,6 +572,11 @@ Preprocessor.prototype.implementation = function(tokens, /*StringBuffer*/ aStrin CONCAT(instance_methods, this.method(tokens, ivar_names)); } + // If we reach a # symbol, we may be at a C preprocessor directive. + else if (token == TOKEN_HASH) + { + this.hash(tokens, buffer); + } // Check if we've reached @end... else if (token == TOKEN_PREPROCESSOR) { @@ -896,6 +931,10 @@ Preprocessor.prototype.preprocess = function(tokens, /*StringBuffer*/ aStringBuf // If we reach an @ symbol, we are at a preprocessor directive. else if (token == TOKEN_PREPROCESSOR) this.directive(tokens, buffer); + + // If we reach a # symbol, we may be at a C preprocessor directive. + else if (token == TOKEN_HASH) + this.hash(tokens, buffer); // If we reach a bracket, we will either be preprocessing a message send, a literal // array, or an array index.