diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-18 17:13:44 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-18 17:13:44 +0200 |
commit | a520a41f74a553aea12385d034244c27825ecfe9 (patch) | |
tree | 5f8fa80ef8cc91705fd8dda134ae1ee6ce3de31c | |
parent | 49bfec9cadd9c999ace3de3745f16c951b1193b8 (diff) |
MLKReadtable: Add support for changing syntax types and setting and unsetting constituent traits.
-rw-r--r-- | MLKReadtable.h | 38 | ||||
-rw-r--r-- | MLKReadtable.m | 68 |
2 files changed, 73 insertions, 33 deletions
diff --git a/MLKReadtable.h b/MLKReadtable.h index f1fe16d..00da691 100644 --- a/MLKReadtable.h +++ b/MLKReadtable.h @@ -32,6 +32,32 @@ enum MLKReadtableCase MLKReadtableCase_PRESERVE }; +enum MLKSyntaxType +{ + CONSTITUENT = 0, + WHITESPACE = 1, + TERMINATING_MACRO = 2, + NONTERMINATING_MACRO = 3, + SINGLE_ESCAPE = 4, + MULTI_ESCAPE = 5 +}; + +enum MLKConstituentTrait +{ + ALPHABETIC = 1, + INVALID = 2, + PACKAGE_MARKER = 4, + ALPHA_DIGIT = 8, + EXPONENT_MARKER = 16, + NUMBER_MARKER = 32, + RATIO_MARKER = 64, + DECIMAL_POINT = 128, + MINUS_SIGN = 256, + PLUS_SIGN = 512, + SIGN = 1024, + DOT = 2048 +}; + @interface MLKReadtable : MLKLispValue <NSCopying> { @@ -77,7 +103,15 @@ enum MLKReadtableCase -(MLKFuncallable *) macroFunctionForCharacter:(unichar)ch; -(unichar) charWithReadtableCase:(unichar)ch; -// For internal use. -(int) characterConstituentTraits:(unichar)ch; --(int) characterSyntaxType:(unichar)ch; +-(BOOL) character:(unichar)ch + hasTrait:(enum MLKConstituentTrait)trait; +-(enum MLKSyntaxType) characterSyntaxType:(unichar)ch; + +-(void) setSyntaxType:(enum MLKSyntaxType)type + forCharacter:(unichar)ch; +-(void) setConstituentTrait:(enum MLKConstituentTrait)trait + forCharacter:(unichar)ch; +-(void) unsetConstituentTrait:(enum MLKConstituentTrait)trait + forCharacter:(unichar)ch; @end diff --git a/MLKReadtable.m b/MLKReadtable.m index c94e7ea..8d56d72 100644 --- a/MLKReadtable.m +++ b/MLKReadtable.m @@ -23,34 +23,6 @@ #import <Foundation/NSValue.h> -enum MLKSyntaxType -{ - CONSTITUENT = 0, - WHITESPACE = 1, - TERMINATING_MACRO = 2, - NONTERMINATING_MACRO = 3, - SINGLE_ESCAPE = 4, - MULTI_ESCAPE = 5 -}; - - -enum MLKConstituentTrait -{ - ALPHABETIC = 1, - INVALID = 2, - PACKAGE_MARKER = 4, - ALPHA_DIGIT = 8, - EXPONENT_MARKER = 16, - NUMBER_MARKER = 32, - RATIO_MARKER = 64, - DECIMAL_POINT = 128, - MINUS_SIGN = 256, - PLUS_SIGN = 512, - SIGN = 1024, - DOT = 2048 -}; - - @implementation MLKReadtable -(MLKReadtable *) initSuper { @@ -89,7 +61,7 @@ enum MLKConstituentTrait [self isTerminatingMacroCharacter:ch]); } --(int) characterSyntaxType:(unichar)ch +-(enum MLKSyntaxType) characterSyntaxType:(unichar)ch { NSNumber *type = [_traits objectForKey:[NSNumber numberWithLong:ch]]; if (!type) @@ -157,12 +129,21 @@ DEFINE_SYNTAX_PREDICATE(isConstituentCharacter:, CONSTITUENT) return [traits intValue]; } +-(BOOL) character:(unichar)ch + hasTrait:(enum MLKConstituentTrait)trait +{ + NSNumber *traits = [_traits objectForKey:[NSNumber numberWithLong:ch]]; + if (!traits) + return (trait == ALPHABETIC); + else + return [traits intValue] & trait; +} + #define DEFINE_TRAIT_PREDICATE(SELECTOR, TRAIT) \ -(BOOL) SELECTOR (unichar)ch \ { \ - return ([self characterConstituentTraits:ch] \ - & TRAIT); \ + return ([self character:ch hasTrait:TRAIT]); \ } DEFINE_TRAIT_PREDICATE(isInvalid:, INVALID) @@ -179,6 +160,31 @@ DEFINE_TRAIT_PREDICATE(isSign:, SIGN) DEFINE_TRAIT_PREDICATE(isDot:, DOT) +-(void) setSyntaxType:(enum MLKSyntaxType)type + forCharacter:(unichar)ch +{ + [_syntaxTable setObject:[NSNumber numberWithInt:type] + forKey:[NSNumber numberWithLong:ch]]; +} + +-(void) setConstituentTrait:(enum MLKConstituentTrait)trait + forCharacter:(unichar)ch +{ + int traits = [self characterConstituentTraits:ch]; + traits = traits | trait; + [_traits setObject:[NSNumber numberWithInt:traits] + forKey:[NSNumber numberWithLong:ch]]; +} + +-(void) unsetConstituentTrait:(enum MLKConstituentTrait)trait + forCharacter:(unichar)ch +{ + int traits = [self characterConstituentTraits:ch]; + traits = traits & ~trait; + [_traits setObject:[NSNumber numberWithInt:traits] + forKey:[NSNumber numberWithLong:ch]]; +} + -(BOOL) isDecimalDigit:(unichar)ch { return [self isDigit:ch inBase:10]; |