Skip to content

Commit

Permalink
* dupe symbol literals in grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
itod committed Apr 13, 2014
1 parent b660137 commit f5cde50
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 3 additions & 2 deletions res/dupe_literals.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[t setTokenizerState:t.symbolState from:'"' to:'"'];
}

start = none+;
start = (none | quote | block)+;
none = 'none' | 'NONE' | 'None';
quote = '"'! Word '"'!;
quote = '"'! Word '"'!;
block = '|' Word '|';
1 change: 1 addition & 0 deletions test/DupeLiteralsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
enum {
DUPELITERALS_TOKEN_KIND_NONE_1 = 14,
DUPELITERALS_TOKEN_KIND_NONE_2,
DUPELITERALS_TOKEN_KIND_PIPE,
DUPELITERALS_TOKEN_KIND_NONE,
DUPELITERALS_TOKEN_KIND_QUOTE,
};
Expand Down
23 changes: 21 additions & 2 deletions test/DupeLiteralsParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ - (id)initWithDelegate:(id)d {
self.startRuleName = @"start";
self.tokenKindTab[@"NONE"] = @(DUPELITERALS_TOKEN_KIND_NONE_1);
self.tokenKindTab[@"None"] = @(DUPELITERALS_TOKEN_KIND_NONE_2);
self.tokenKindTab[@"|"] = @(DUPELITERALS_TOKEN_KIND_PIPE);
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_PIPE] = @"|";
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_NONE] = @"none";
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_QUOTE] = @"\"";

Expand Down Expand Up @@ -50,8 +52,16 @@ - (void)start {
- (void)start_ {

do {
[self none_];
} while ([self predicts:DUPELITERALS_TOKEN_KIND_NONE, DUPELITERALS_TOKEN_KIND_NONE_1, DUPELITERALS_TOKEN_KIND_NONE_2, 0]);
if ([self predicts:DUPELITERALS_TOKEN_KIND_NONE, DUPELITERALS_TOKEN_KIND_NONE_1, DUPELITERALS_TOKEN_KIND_NONE_2, 0]) {
[self none_];
} else if ([self predicts:DUPELITERALS_TOKEN_KIND_QUOTE, 0]) {
[self quote_];
} else if ([self predicts:DUPELITERALS_TOKEN_KIND_PIPE, 0]) {
[self block_];
} else {
[self raise:@"No viable alternative found in rule 'start'."];
}
} while ([self speculate:^{ if ([self predicts:DUPELITERALS_TOKEN_KIND_NONE, DUPELITERALS_TOKEN_KIND_NONE_1, DUPELITERALS_TOKEN_KIND_NONE_2, 0]) {[self none_]; } else if ([self predicts:DUPELITERALS_TOKEN_KIND_QUOTE, 0]) {[self quote_]; } else if ([self predicts:DUPELITERALS_TOKEN_KIND_PIPE, 0]) {[self block_]; } else {[self raise:@"No viable alternative found in rule 'start'."];}}]);

[self fireDelegateSelector:@selector(parser:didMatchStart:)];
}
Expand Down Expand Up @@ -80,4 +90,13 @@ - (void)quote_ {
[self fireDelegateSelector:@selector(parser:didMatchQuote:)];
}

- (void)block_ {

[self match:DUPELITERALS_TOKEN_KIND_PIPE discard:NO];
[self matchWord:NO];
[self match:DUPELITERALS_TOKEN_KIND_PIPE discard:NO];

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

@end

0 comments on commit f5cde50

Please sign in to comment.