From b660137550f241426c8b9383d66f52f993f9e816 Mon Sep 17 00:00:00 2001 From: Todd Ditchendorf Date: Sun, 13 Apr 2014 14:31:25 -0500 Subject: [PATCH] * should support dupe literal quote defs in grammar --- ParserGenApp/PGTokenKindDescriptor.m | 8 ++++---- res/dupe_literals.grammar | 2 +- test/DupeLiteralsParser.h | 1 + test/DupeLiteralsParser.m | 11 +++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ParserGenApp/PGTokenKindDescriptor.m b/ParserGenApp/PGTokenKindDescriptor.m index 3cbd2b5..f5b7091 100644 --- a/ParserGenApp/PGTokenKindDescriptor.m +++ b/ParserGenApp/PGTokenKindDescriptor.m @@ -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 @@ -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; diff --git a/res/dupe_literals.grammar b/res/dupe_literals.grammar index d091b02..2bb0fb2 100644 --- a/res/dupe_literals.grammar +++ b/res/dupe_literals.grammar @@ -6,4 +6,4 @@ start = none+; none = 'none' | 'NONE' | 'None'; -//quote = '"' Word '"'; \ No newline at end of file +quote = '"'! Word '"'!; \ No newline at end of file diff --git a/test/DupeLiteralsParser.h b/test/DupeLiteralsParser.h index 5070c2a..f10e48b 100644 --- a/test/DupeLiteralsParser.h +++ b/test/DupeLiteralsParser.h @@ -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 diff --git a/test/DupeLiteralsParser.m b/test/DupeLiteralsParser.m index de686f9..89f60e7 100644 --- a/test/DupeLiteralsParser.m +++ b/test/DupeLiteralsParser.m @@ -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; @@ -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 \ No newline at end of file