summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MLKLowLevelTests.m18
-rw-r--r--MLKReader.h4
-rw-r--r--MLKReader.m22
3 files changed, 38 insertions, 6 deletions
diff --git a/MLKLowLevelTests.m b/MLKLowLevelTests.m
index 7d78377..4eef0c9 100644
--- a/MLKLowLevelTests.m
+++ b/MLKLowLevelTests.m
@@ -122,8 +122,16 @@
UKObjectKindOf ([MLKReader readFromString:@"a"], MLKSymbol);
UKObjectKindOf ([MLKReader readFromString:@"MULK"], MLKSymbol);
UKObjectKindOf ([MLKReader readFromString:@"+"], MLKSymbol);
+ UKObjectKindOf ([MLKReader readFromString:@"1-"], MLKSymbol);
+ UKObjectKindOf ([MLKReader readFromString:@"1+"], MLKSymbol);
UKObjectKindOf ([MLKReader readFromString:@"0AA0A"], MLKSymbol);
+ UKObjectKindOf ([MLKReader readFromString:@"0AA0A"], MLKSymbol);
+ UKObjectKindOf ([MLKReader readFromString:@"0\\aA0A"], MLKSymbol);
+ UKObjectKindOf ([MLKReader readFromString:@"\\0"], MLKSymbol);
+ UKObjectKindOf ([MLKReader readFromString:@"|abc def (mulk!)|"], MLKSymbol);
+ UKObjectKindOf ([MLKReader readFromString:@"0\\.3"], MLKSymbol);
+
UKObjectKindOf ([MLKReader readFromString:@"134651234"], MLKInteger);
UKObjectKindOf ([MLKReader readFromString:@"223555."], MLKInteger);
UKObjectKindOf ([MLKReader readFromString:@"-134651234"], MLKInteger);
@@ -153,6 +161,16 @@
UKObjectKindOf ([MLKReader readFromString:@"-.5678e3"], MLKSingleFloat);
UKObjectKindOf ([MLKReader readFromString:@"+.5678e3"], MLKSingleFloat);
+ UKStringsEqual ([[MLKReader readFromString:@"a"] name], @"A");
+ UKStringsEqual ([[MLKReader readFromString:@"1+"] name], @"1+");
+ UKStringsEqual ([[MLKReader readFromString:@"mulkmulk"] name], @"MULKMULK");
+ UKStringsEqual ([[MLKReader readFromString:@"ABCDefghIJKL"] name], @"ABCDEFGHIJKL");
+ UKStringsEqual ([[MLKReader readFromString:@"class-name"] name], @"CLASS-NAME");
+ UKStringsEqual ([[MLKReader readFromString:@"\\class-\\name"] name], @"cLASS-nAME");
+ UKStringsEqual ([[MLKReader readFromString:@"|Class Name|"] name], @"Class Name");
+ UKStringsEqual ([[MLKReader readFromString:@"class\\ name"] name], @"CLASS NAME");
+ UKStringsEqual ([[MLKReader readFromString:@"\\100"] name], @"100");
+
return nil;
}
diff --git a/MLKReader.h b/MLKReader.h
index ec30c40..9a49ef9 100644
--- a/MLKReader.h
+++ b/MLKReader.h
@@ -30,7 +30,9 @@
+(id) readFromString:(NSString *)string;
-+(id) interpretToken:(NSString *)token readtable:(MLKReadtable *)table;
++(id) interpretToken:(NSString *)token
+ readtable:(MLKReadtable *)readtable
+ escaped:(BOOL)escaped;
+(BOOL) isPotentialNumber:(NSString *)token
readtable:(MLKReadtable *)table
diff --git a/MLKReader.m b/MLKReader.m
index 779ffdd..da5e743 100644
--- a/MLKReader.m
+++ b/MLKReader.m
@@ -48,6 +48,9 @@
NSMutableString *token;
MLKReadtable *readtable;
BOOL escaped;
+ BOOL ever_escaped;
+
+ ever_escaped = NO;
readtable = [[MLKDynamicContext currentContext]
valueForBinding:[[MLKPackage findPackage:@"COMMON-LISP"]
@@ -97,12 +100,14 @@
token = [NSMutableString stringWithCapacity:8];
[token appendFormat:@"%C", [stream readChar]];
+ ever_escaped = YES;
}
if ([readtable isMultipleEscapeCharacter:ch])
{
token = [NSMutableString stringWithCapacity:8];
escaped = YES;
+ ever_escaped = YES;
}
if ([readtable isConstituentCharacter:ch])
@@ -130,11 +135,14 @@
if ([stream isEOF])
[[[MLKEndOfFileError alloc] initWithStream:stream] raise];
- token = [NSMutableString stringWithCapacity:8];
[token appendFormat:@"%C", [stream readChar]];
+ ever_escaped = YES;
}
else if ([readtable isMultipleEscapeCharacter:ch])
- escaped = !escaped;
+ {
+ ever_escaped = YES;
+ escaped = !escaped;
+ }
else if ([readtable isTerminatingMacroCharacter:ch])
{
[stream unreadChar:ch];
@@ -153,7 +161,9 @@
}
//NSLog (@"--> Interpret token: %@", token);
- return [self interpretToken:token readtable:readtable];
+ return [self interpretToken:token
+ readtable:readtable
+ escaped:ever_escaped];
}
+(BOOL) isPotentialNumber:(NSString *)token
@@ -212,7 +222,9 @@
return YES;
}
-+(id) interpretToken:(NSString *)token readtable:(MLKReadtable *)readtable
++(id) interpretToken:(NSString *)token
+ readtable:(MLKReadtable *)readtable
+ escaped:(BOOL)escaped
{
int base;
@@ -221,7 +233,7 @@
intern:@"*READ-BASE*"]]
intValue];
- if ([self isPotentialNumber:token readtable:readtable base:base])
+ if (!escaped && [self isPotentialNumber:token readtable:readtable base:base])
{
unsigned long i, firstNum, secondNum, exponent, exponentMarkerPos;
unichar sign, exponentSign;