diff --git a/res/curly_action.grammar b/res/curly_action.grammar index 8ce29ea..28ee21e 100644 --- a/res/curly_action.grammar +++ b/res/curly_action.grammar @@ -1,7 +1,8 @@ start = Word+ { + id word = nil; while (!EMPTY()) { - id word = POP_STR(); - LOG(word); - } + word = POP_STR(); + \} + PUSH(word); }; \ No newline at end of file diff --git a/src/PKDelimitState.m b/src/PKDelimitState.m index 5838578..6221ddc 100644 --- a/src/PKDelimitState.m +++ b/src/PKDelimitState.m @@ -175,7 +175,7 @@ - (PKToken *)nextTokenFromReader:(PKReader *)r startingWith:(PKUniChar)cin token for (NSUInteger j = 0; j < count; ++j) { if ('\\' == c) { - [self append:c]; // append escape backslash + //[self append:c]; // drop escape backslash c = [r read]; if (PKEOF == c) { break; diff --git a/src/PKTokenizer.m b/src/PKTokenizer.m index 254c45b..abd6a5e 100644 --- a/src/PKTokenizer.m +++ b/src/PKTokenizer.m @@ -171,7 +171,8 @@ - (void)dealloc { - (PKToken *)nextToken { NSAssert(_reader, @""); - PKUniChar c = [_reader read]; //NSLog(@"`%C`", (unichar)c); + PKUniChar c = [_reader read]; //NSLog(@"%@", [[[NSString alloc] initWithBytes:&c length:1 encoding:4] autorelease]); + PKToken *result = nil; if (PKEOF == c) { diff --git a/test/CurlyActionParser.h b/test/CurlyActionParser.h index 599588c..e9bc45f 100644 --- a/test/CurlyActionParser.h +++ b/test/CurlyActionParser.h @@ -1,11 +1,6 @@ #import -enum { - TABLEINDEX_TOKEN_KIND_BY = 14, - TABLEINDEX_TOKEN_KIND_INDEXED, - TABLEINDEX_TOKEN_KIND_NOT_UPPER, - TABLEINDEX_TOKEN_KIND_DOT, -}; + @interface CurlyActionParser : PKParser diff --git a/test/CurlyActionParser.m b/test/CurlyActionParser.m index 4df504c..d71a28f 100644 --- a/test/CurlyActionParser.m +++ b/test/CurlyActionParser.m @@ -64,130 +64,34 @@ @implementation CurlyActionParser - (id)initWithDelegate:(id)d { self = [super initWithDelegate:d]; if (self) { - self.startRuleName = @"qualifiedTableName"; - self.tokenKindTab[@"BY"] = @(TABLEINDEX_TOKEN_KIND_BY); - self.tokenKindTab[@"INDEXED"] = @(TABLEINDEX_TOKEN_KIND_INDEXED); - self.tokenKindTab[@"NOT"] = @(TABLEINDEX_TOKEN_KIND_NOT_UPPER); - self.tokenKindTab[@"."] = @(TABLEINDEX_TOKEN_KIND_DOT); + self.startRuleName = @"start"; - self.tokenKindNameTab[TABLEINDEX_TOKEN_KIND_BY] = @"BY"; - self.tokenKindNameTab[TABLEINDEX_TOKEN_KIND_INDEXED] = @"INDEXED"; - self.tokenKindNameTab[TABLEINDEX_TOKEN_KIND_NOT_UPPER] = @"NOT"; - self.tokenKindNameTab[TABLEINDEX_TOKEN_KIND_DOT] = @"."; } return self; } - (void)start { - [self qualifiedTableName_]; + [self start_]; [self matchEOF:YES]; } -- (void)qualifiedTableName_ { +- (void)start_ { - [self name_]; - [self indexOpt_]; + do { + [self matchWord:NO]; + } while ([self predicts:TOKEN_KIND_BUILTIN_WORD, 0]); [self execute:(id)^{ - // now stack contains 3 `NSString`s. - // ["mydb", "mytable", "foo"] - // NSString *indexName = POP(); - // NSString *tableName = POP(); - // NSString *dbName = POP(); - // do stuff here - - }]; - - [self fireDelegateSelector:@selector(parser:didMatchQualifiedTableName:)]; -} - -- (void)databaseName_ { - - [self matchWord:NO]; - - [self fireDelegateSelector:@selector(parser:didMatchDatabaseName:)]; -} - -- (void)tableName_ { - - [self matchWord:NO]; - - [self fireDelegateSelector:@selector(parser:didMatchTableName:)]; -} - -- (void)indexName_ { - - [self matchQuotedString:NO]; - - [self fireDelegateSelector:@selector(parser:didMatchIndexName:)]; -} - -- (void)name_ { - - if ([self speculate:^{ [self databaseName_]; [self match:TABLEINDEX_TOKEN_KIND_DOT discard:YES]; }]) { - [self databaseName_]; - [self match:TABLEINDEX_TOKEN_KIND_DOT discard:YES]; + id word = nil; + while (!EMPTY()) { + word = POP_STR(); } - [self tableName_]; - [self execute:(id)^{ - - // now stack contains 2 `PKToken`s of type Word - // [, ] - // pop their string values - NSString *tableName = POP_STR(); - NSString *dbName = POP_STR(); - PUSH(dbName); - PUSH(tableName); + PUSH(word); }]; - [self fireDelegateSelector:@selector(parser:didMatchName:)]; -} - -- (void)indexOpt_ { - - if ([self predicts:TABLEINDEX_TOKEN_KIND_INDEXED, TABLEINDEX_TOKEN_KIND_NOT_UPPER, 0]) { - [self index_]; - } else { - [self matchEmpty:NO]; - [self execute:(id)^{ - PUSH(@""); - }]; - } - - [self fireDelegateSelector:@selector(parser:didMatchIndexOpt:)]; -} - -- (void)index_ { - - if ([self predicts:TABLEINDEX_TOKEN_KIND_INDEXED, 0]) { - [self match:TABLEINDEX_TOKEN_KIND_INDEXED discard:YES]; - [self match:TABLEINDEX_TOKEN_KIND_BY discard:YES]; - [self indexName_]; - [self execute:(id)^{ - - // now top of stack will be a Quoted String `PKToken` - // […, ] - // pop its string value - NSString *indexName = POP_STR(); - // trim quotes - indexName = [indexName substringWithRange:NSMakeRange(1, [indexName length]-2)]; - // leave it on the stack for later - PUSH(indexName); - - }]; - } else if ([self predicts:TABLEINDEX_TOKEN_KIND_NOT_UPPER, 0]) { - [self match:TABLEINDEX_TOKEN_KIND_NOT_UPPER discard:YES]; - [self match:TABLEINDEX_TOKEN_KIND_INDEXED discard:YES]; - [self execute:(id)^{ - PUSH(@""); - }]; - } else { - [self raise:@"No viable alternative found in rule 'index'."]; - } - - [self fireDelegateSelector:@selector(parser:didMatchIndex:)]; + [self fireDelegateSelector:@selector(parser:didMatchStart:)]; } @end \ No newline at end of file diff --git a/test/CurlyActionParserTest.m b/test/CurlyActionParserTest.m index 27c7ec2..f6b934a 100644 --- a/test/CurlyActionParserTest.m +++ b/test/CurlyActionParserTest.m @@ -73,7 +73,6 @@ - (void)tearDown { self.factory = nil; } - - (void)testFooBarBaz { NSString *s = @"foo bar baz"; @@ -81,7 +80,7 @@ - (void)testFooBarBaz { PKAssembly *res = [_parser parseString:s error:&err]; TDNil(err); - TDEqualObjects(TDAssembly(@"[foo, bar, baz]foo/bar/baz^"), [res description]); + TDEqualObjects(TDAssembly(@"[foo]foo/bar/baz^"), [res description]); } @end diff --git a/test/TDDelimitStateTest.m b/test/TDDelimitStateTest.m index 009c585..d628f9d 100644 --- a/test/TDDelimitStateTest.m +++ b/test/TDDelimitStateTest.m @@ -219,7 +219,7 @@ - (void)testSlashSlashEscapeSemi { tok = [t nextToken]; TDTrue(tok.isDelimitedString); - TDEqualObjects(@"/foo\\/bar/", tok.stringValue); + TDEqualObjects(@"/foo/bar/", tok.stringValue); TDEquals((double)0.0, tok.doubleValue); tok = [t nextToken]; @@ -244,7 +244,7 @@ - (void)testSlashSlashEscape { tok = [t nextToken]; TDTrue(tok.isDelimitedString); - TDEqualObjects(@"/foo\\/bar/", tok.stringValue); + TDEqualObjects(@"/foo/bar/", tok.stringValue); TDEquals((double)0.0, tok.doubleValue); tok = [t nextToken]; @@ -264,7 +264,7 @@ - (void)testSlashSlashEscapeBackslash { tok = [t nextToken]; TDTrue(tok.isDelimitedString); - TDEqualObjects(@"/foo\\\\/", tok.stringValue); + TDEqualObjects(@"/foo\\/", tok.stringValue); TDEquals((double)0.0, tok.doubleValue); tok = [t nextToken]; @@ -296,7 +296,7 @@ - (void)testSlashSlashEscapeBackslashFile { tok = [t nextToken]; TDTrue(tok.isDelimitedString); - TDEqualObjects(@"/foo\\\\/", tok.stringValue); + TDEqualObjects(@"/foo\\/", tok.stringValue); TDEquals((double)0.0, tok.doubleValue); tok = [t nextToken];