diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-26 11:48:01 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-07-26 11:48:01 +0200 |
commit | ca1c83c21c967593dfa4fced6084e83361bc6cf3 (patch) | |
tree | 15b770bc901ef01ea4568b08026a120eb00be63d /MLKParenReader.m | |
parent | 9f9d3bcede3a4d57fb112011be7023fdd83db369 (diff) |
Reader: Support the consing dot.
Diffstat (limited to 'MLKParenReader.m')
-rw-r--r-- | MLKParenReader.m | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/MLKParenReader.m b/MLKParenReader.m index 9287ce9..b61a332 100644 --- a/MLKParenReader.m +++ b/MLKParenReader.m @@ -59,6 +59,7 @@ static unichar slurpWhitespaceAndPeek (MLKStream *stream, MLKReadtable *readtabl while ((nextChar = slurpWhitespaceAndPeek(stream, readtable)) != ')') { id item; + id dotMarker = [[NSObject alloc] init]; // FIXME: What to do about dots? Maybe add a new // singleDotAllowed:(BOOL)dotp argument to readFromStream:...? @@ -66,8 +67,35 @@ static unichar slurpWhitespaceAndPeek (MLKStream *stream, MLKReadtable *readtabl eofError:YES eofValue:nil recursive:YES - preserveWhitespace:NO]; - + preserveWhitespace:NO + singleDotMarker:dotMarker]; + + if (item == dotMarker) + { + id nextItem; + + RELEASE (dotMarker); + + nextItem = [MLKReader readFromStream:stream + eofError:YES + eofValue:nil + recursive:YES + preserveWhitespace:NO + singleDotMarker:nil]; + [tail setCdr:nextItem]; + + if ((nextChar = slurpWhitespaceAndPeek (stream, readtable)) == ')') + { + [stream readChar]; + return [NSArray arrayWithObject:cons]; + } + else + { + [NSException raise:@"MLKReaderError" + format:@"Unexpectedly read a single dot."]; + } + } + if (!tail) { cons = tail = [MLKCons cons:item with:nil]; @@ -77,6 +105,8 @@ static unichar slurpWhitespaceAndPeek (MLKStream *stream, MLKReadtable *readtabl [tail setCdr:[MLKCons cons:item with:nil]]; tail = [tail cdr]; } + + RELEASE (dotMarker); } [stream readChar]; |