From 4097b345be721795492243c00cb7446d8ff161c8 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 15 Jun 2008 13:23:01 +0200 Subject: MLKReader: Add method -isPotentialNumber:readtable:. --- MLKReader.h | 6 +++++- MLKReader.m | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/MLKReader.h b/MLKReader.h index 9e62e9d..3586f99 100644 --- a/MLKReader.h +++ b/MLKReader.h @@ -18,7 +18,7 @@ #include -@class MLKStream; +@class MLKStream, MLKReadtable; @interface MLKReader : NSObject @@ -27,4 +27,8 @@ eofValue:(id)eofValue recursive:(BOOL)recursive preserveWhitespace:(BOOL)preserveWhitespace; + ++(id) interpretToken:(NSString *)token readtable:(MLKReadtable *)table; + ++(BOOL) isPotentialNumber:(NSString *)token readtable:(MLKReadtable *)table; @end diff --git a/MLKReader.m b/MLKReader.m index fe216ca..72d9c62 100644 --- a/MLKReader.m +++ b/MLKReader.m @@ -43,7 +43,7 @@ MLKReadtable *readtable; BOOL escaped; - readtable = [[[MLKDynamicContext currentContext] environment] + readtable = [[MLKDynamicContext currentContext] valueForBinding:[[MLKPackage findPackage:@"COMMON-LISP"] intern:@"*READTABLE*"]]; @@ -132,7 +132,7 @@ [stream unreadChar:ch]; break; } - else if ([readtable isInvalidConstituent:ch]) + else if ([readtable isInvalid:ch]) { [[[MLKReaderError alloc] initWithStream:stream] raise]; } @@ -144,6 +144,72 @@ } } - // FIXME: Check the token for meaning. + return [self interpretToken:token readtable:readtable]; +} + ++(BOOL) isPotentialNumber:(NSString *)token readtable:(MLKReadtable *)readtable +{ + // Check whether the token is a potential number. + // + // See CLHS 2.3.1.1. + int i; + unichar first; + + // 1. Does it consist solely of characters allowed in a potential + // number? + for (i = 0; i < [token length]; i++) + { + unichar ch = [token characterAtIndex:i]; + if (!([readtable isDigit:ch] + || [readtable isSign:ch] + || [readtable isRatioMarker:ch] + || [readtable isDecimalPoint:ch] + || ch == '^' + || ch == '_' + || ([readtable isNumberMarker:ch] + // Adjacent number markers aren't to be considered number + // markers at all. + && (i == 0 + || ![readtable + isNumberMarker:[token characterAtIndex:(i-1)]])))) + return NO; + } + + // 2. Does the token contain a digit? + for (i = 0; i < [token length]; i++) + { + unichar ch = [token characterAtIndex:i]; + if ([readtable isDigit:ch]) + goto digitFound; + } + return NO; + + digitFound: + // 3. Is the first character okay? + first = [token characterAtIndex:0]; + if (!([readtable isDigit:first] + || [readtable isSign:first] + || [readtable isDecimalPoint:first] + || first == '^' + || first == '_')) + return NO; + + // 4. Does the token not end with a sign? + if ([readtable isSign:[token characterAtIndex:([token length]-1)]]) + return NO; + + return YES; +} + ++(id) interpretToken:(NSString *)token readtable:(MLKReadtable *)readtable +{ + if ([self isPotentialNumber:token readtable:readtable]) + { + // ??? + } + else + { + + } } @end -- cgit v1.2.3