Skip to content

Commit

Permalink
Added helper for creating keyword pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Aug 1, 2013
1 parent 786fb58 commit ccb7d1b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Chromatism/Chromatism/JLTokenizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ - (void)setup
// Method call parts
[[self addToken:JLTokenTypeOtherMethodNames withPattern:@"(?<=\\w+):\\s*[^\\s;\\]]+" andScope:lineScope] setCaptureGroup:1];

[self addToken:JLTokenTypeKeyword withPattern:@"\\b(true|false|yes|no|TRUE|FALSE|bool|BOOL|nil|id|void|self|NULL|if|else|strong|weak|nonatomic|atomic|assign|copy|typedef|enum|auto|break|case|const|char|continue|do|default|double|extern|float|for|goto|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|volatile|while|nonatomic|atomic|nonatomic|readonly|super)\\b" andScope:lineScope];
NSString *keywords = @"true false yes no TRUE FALSE bool BOOL nil id void self NULL if else strong weak nonatomic atomic assign copy typedef enum auto break case const char continue do default double extern float for goto int long register return short signed sizeof static struct switch typedef union unsigned volatile while nonatomic atomic nonatomic readonly super";

[self addToken:JLTokenTypeKeyword withKeywords:keywords andScope:lineScope];
[self addToken:JLTokenTypeKeyword withPattern:@"@[a-zA-Z0-9_]+" andScope:lineScope];

// Other Class Names
Expand Down Expand Up @@ -205,9 +207,6 @@ - (JLTokenPattern *)addToken:(NSString *)type withIdentifier:(NSString *)identif
NSParameterAssert(type);
NSParameterAssert(pattern);
NSParameterAssert(scope);
UIColor *color = self.colors[type];

NSAssert(color, @"%@ didn't return a color in color dictionary %@", type, self.colors);

JLTokenPattern *token = [JLTokenPattern tokenPatternWithPattern:pattern];
token.identifier = identifier;
Expand All @@ -218,6 +217,12 @@ - (JLTokenPattern *)addToken:(NSString *)type withIdentifier:(NSString *)identif
return token;
}

- (JLTokenPattern *)addToken:(NSString *)type withKeywords:(NSString *)keywords andScope:(JLScope *)scope
{
NSString *pattern = [NSString stringWithFormat:@"\\b(%@)\\b", [[keywords componentsSeparatedByString:@" "] componentsJoinedByString:@"|"]];
return [self addToken:type withPattern:pattern andScope:scope];
}

- (void)clearColorAttributesInRange:(NSRange)range textStorage:(NSTextStorage *)storage;
{
[storage removeAttribute:NSForegroundColorAttributeName range:range];
Expand Down

0 comments on commit ccb7d1b

Please sign in to comment.