forked from mz2/Fragaria
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathExampleCustomParser.m
44 lines (31 loc) · 1.15 KB
/
ExampleCustomParser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// ExampleCustomParser.m
// Fragaria Simple
//
// Created by Daniele Cattaneo on 28/12/2018.
//
#import "ExampleCustomParser.h"
@implementation ExampleCustomParser
- (NSArray *)syntaxDefinitionNames
{
return @[@"Example Custom Parser"];
}
- (nonnull MGSSyntaxParser *)parserForSyntaxDefinitionName:(nonnull NSString *)syndef
{
return self;
}
- (NSRange)parseForClient:(id<MGSSyntaxParserClient>)client
{
NSString *string = client.stringToParse;
NSRange realRange = [client resetTokenGroupsInRange:client.rangeToParse];
/* Color as an instruction every word starting with an uppercase letter */
NSCharacterSet *uppercase = [NSCharacterSet uppercaseLetterCharacterSet];
[string enumerateSubstringsInRange:realRange options:NSStringEnumerationByWords usingBlock:
^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
if ([substring length] > 0 && [uppercase characterIsMember:[substring characterAtIndex:0]]) {
[client setGroup:MGSSyntaxGroupInstruction forTokenInRange:substringRange atomic:YES];
}
}];
return realRange;
}
@end