Skip to content

Commit

Permalink
* should support dupe literal quote defs in grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
itod committed Apr 13, 2014
1 parent 5166829 commit b660137
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions ParserGenApp/PGTokenKindDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ + (void)initialize {
+ (PGTokenKindDescriptor *)descriptorWithStringValue:(NSString *)s name:(NSString *)name {
NSParameterAssert(s);
NSParameterAssert(name);


// escape double quotes
s = [s stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

PGTokenKindDescriptor *desc = sCache[name];

// This handles cases where the grammar has two literal tokens
Expand All @@ -62,9 +65,6 @@ + (PGTokenKindDescriptor *)descriptorWithStringValue:(NSString *)s name:(NSStrin
if (!desc) {
desc = [[[PGTokenKindDescriptor alloc] init] autorelease];

// escape double quotes
s = [s stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

desc.stringValue = s;
desc.name = name;

Expand Down
2 changes: 1 addition & 1 deletion res/dupe_literals.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

start = none+;
none = 'none' | 'NONE' | 'None';
//quote = '"' Word '"';
quote = '"'! Word '"'!;
1 change: 1 addition & 0 deletions test/DupeLiteralsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum {
DUPELITERALS_TOKEN_KIND_NONE_1 = 14,
DUPELITERALS_TOKEN_KIND_NONE_2,
DUPELITERALS_TOKEN_KIND_NONE,
DUPELITERALS_TOKEN_KIND_QUOTE,
};

@interface DupeLiteralsParser : PKParser
Expand Down
11 changes: 11 additions & 0 deletions test/DupeLiteralsParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ - (id)initWithDelegate:(id)d {
self.tokenKindTab[@"NONE"] = @(DUPELITERALS_TOKEN_KIND_NONE_1);
self.tokenKindTab[@"None"] = @(DUPELITERALS_TOKEN_KIND_NONE_2);
self.tokenKindTab[@"none"] = @(DUPELITERALS_TOKEN_KIND_NONE);
self.tokenKindTab[@"\""] = @(DUPELITERALS_TOKEN_KIND_QUOTE);

self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_NONE_1] = @"NONE";
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_NONE_2] = @"None";
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_NONE] = @"none";
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_QUOTE] = @"\"";

}
return self;
Expand Down Expand Up @@ -69,4 +71,13 @@ - (void)none_ {
[self fireDelegateSelector:@selector(parser:didMatchNone:)];
}

- (void)quote_ {

[self match:DUPELITERALS_TOKEN_KIND_QUOTE discard:YES];
[self matchWord:NO];
[self match:DUPELITERALS_TOKEN_KIND_QUOTE discard:YES];

[self fireDelegateSelector:@selector(parser:didMatchQuote:)];
}

@end

0 comments on commit b660137

Please sign in to comment.