Skip to content

Commit f5cde50

Browse files
committed
* dupe symbol literals in grammar
1 parent b660137 commit f5cde50

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

res/dupe_literals.grammar

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[t setTokenizerState:t.symbolState from:'"' to:'"'];
55
}
66

7-
start = none+;
7+
start = (none | quote | block)+;
88
none = 'none' | 'NONE' | 'None';
9-
quote = '"'! Word '"'!;
9+
quote = '"'! Word '"'!;
10+
block = '|' Word '|';

test/DupeLiteralsParser.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
enum {
44
DUPELITERALS_TOKEN_KIND_NONE_1 = 14,
55
DUPELITERALS_TOKEN_KIND_NONE_2,
6+
DUPELITERALS_TOKEN_KIND_PIPE,
67
DUPELITERALS_TOKEN_KIND_NONE,
78
DUPELITERALS_TOKEN_KIND_QUOTE,
89
};

test/DupeLiteralsParser.m

+21-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ - (id)initWithDelegate:(id)d {
1515
self.startRuleName = @"start";
1616
self.tokenKindTab[@"NONE"] = @(DUPELITERALS_TOKEN_KIND_NONE_1);
1717
self.tokenKindTab[@"None"] = @(DUPELITERALS_TOKEN_KIND_NONE_2);
18+
self.tokenKindTab[@"|"] = @(DUPELITERALS_TOKEN_KIND_PIPE);
1819
self.tokenKindTab[@"none"] = @(DUPELITERALS_TOKEN_KIND_NONE);
1920
self.tokenKindTab[@"\""] = @(DUPELITERALS_TOKEN_KIND_QUOTE);
2021

2122
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_NONE_1] = @"NONE";
2223
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_NONE_2] = @"None";
24+
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_PIPE] = @"|";
2325
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_NONE] = @"none";
2426
self.tokenKindNameTab[DUPELITERALS_TOKEN_KIND_QUOTE] = @"\"";
2527

@@ -50,8 +52,16 @@ - (void)start {
5052
- (void)start_ {
5153

5254
do {
53-
[self none_];
54-
} while ([self predicts:DUPELITERALS_TOKEN_KIND_NONE, DUPELITERALS_TOKEN_KIND_NONE_1, DUPELITERALS_TOKEN_KIND_NONE_2, 0]);
55+
if ([self predicts:DUPELITERALS_TOKEN_KIND_NONE, DUPELITERALS_TOKEN_KIND_NONE_1, DUPELITERALS_TOKEN_KIND_NONE_2, 0]) {
56+
[self none_];
57+
} else if ([self predicts:DUPELITERALS_TOKEN_KIND_QUOTE, 0]) {
58+
[self quote_];
59+
} else if ([self predicts:DUPELITERALS_TOKEN_KIND_PIPE, 0]) {
60+
[self block_];
61+
} else {
62+
[self raise:@"No viable alternative found in rule 'start'."];
63+
}
64+
} 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'."];}}]);
5565

5666
[self fireDelegateSelector:@selector(parser:didMatchStart:)];
5767
}
@@ -80,4 +90,13 @@ - (void)quote_ {
8090
[self fireDelegateSelector:@selector(parser:didMatchQuote:)];
8191
}
8292

93+
- (void)block_ {
94+
95+
[self match:DUPELITERALS_TOKEN_KIND_PIPE discard:NO];
96+
[self matchWord:NO];
97+
[self match:DUPELITERALS_TOKEN_KIND_PIPE discard:NO];
98+
99+
[self fireDelegateSelector:@selector(parser:didMatchBlock:)];
100+
}
101+
83102
@end

0 commit comments

Comments
 (0)