From bc49c6720e20a64dc8708e96df89b616c90e4ddf Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 19 Jun 2008 20:15:06 +0200 Subject: Fix the reader's token recognition code. --- MLKError.m | 5 +++++ MLKReader.h | 2 ++ MLKReader.m | 17 +++++++++++++++-- MLKReadtable.m | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/MLKError.m b/MLKError.m index eeb59b1..3aad324 100644 --- a/MLKError.m +++ b/MLKError.m @@ -32,6 +32,11 @@ return AUTORELEASE ([[MLKError alloc] initWithMessage:aString]); } +-(NSString *) reason +{ + return message; +} + -(void) dealloc { RELEASE (message); diff --git a/MLKReader.h b/MLKReader.h index 072829a..ec30c40 100644 --- a/MLKReader.h +++ b/MLKReader.h @@ -28,6 +28,8 @@ recursive:(BOOL)recursive preserveWhitespace:(BOOL)preserveWhitespace; ++(id) readFromString:(NSString *)string; + +(id) interpretToken:(NSString *)token readtable:(MLKReadtable *)table; +(BOOL) isPotentialNumber:(NSString *)token diff --git a/MLKReader.m b/MLKReader.m index 2341d32..779ffdd 100644 --- a/MLKReader.m +++ b/MLKReader.m @@ -29,6 +29,7 @@ #import "MLKFloat.h" #import "MLKInteger.h" #import "MLKRatio.h" +#import "MLKStringInputStream.h" #import #import @@ -106,13 +107,14 @@ if ([readtable isConstituentCharacter:ch]) { + //NSLog (@"--> Constituent"); token = [NSMutableString stringWithCapacity:8]; - [token appendFormat:@"%C", [readtable charWithReadtableCase: - [stream readChar]]]; + [token appendFormat:@"%C", [readtable charWithReadtableCase:ch]]; } while (![stream isEOF]) { + //NSLog (@"..."); ch = [stream readChar]; if ([readtable isConstituentCharacter:ch] || [readtable isNonTerminatingMacroCharacter:ch] || @@ -150,6 +152,7 @@ } } + //NSLog (@"--> Interpret token: %@", token); return [self interpretToken:token readtable:readtable]; } @@ -450,4 +453,14 @@ return symbol; } } + ++(id) readFromString:(NSString *)string +{ + return [self readFromStream:[[MLKStringInputStream alloc] + initWithString:string] + eofError:YES + eofValue:nil + recursive:NO + preserveWhitespace:NO]; +} @end diff --git a/MLKReadtable.m b/MLKReadtable.m index 393c4d1..dd2a428 100644 --- a/MLKReadtable.m +++ b/MLKReadtable.m @@ -63,7 +63,7 @@ -(enum MLKSyntaxType) characterSyntaxType:(unichar)ch { - NSNumber *type = [_traits objectForKey:[NSNumber numberWithLong:ch]]; + NSNumber *type = [_syntaxTable objectForKey:[NSNumber numberWithLong:ch]]; if (!type) return CONSTITUENT; else -- cgit v1.2.3