Skip to content

Commit

Permalink
Made the pre-processor capable of recognizing and ignoring Xcode's '#…
Browse files Browse the repository at this point in the history
…pragma mark' mark-ups

Conflicts:

	Objective-J/Preprocessor.js
  • Loading branch information
Ross Boucher committed Apr 9, 2010
1 parent 489f2bc commit 47ecd40
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Objective-J/Preprocessor.js
Expand Up @@ -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 = '+',
Expand All @@ -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 = '(',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 47ecd40

Please sign in to comment.