forked from gavinkwoe/todparsekit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPKSymbol.m
73 lines (58 loc) · 1.55 KB
/
PKSymbol.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// PKSymbol.m
// ParseKit
//
// Created by Todd Ditchendorf on 7/13/08.
// Copyright 2009 Todd Ditchendorf. All rights reserved.
//
#import <ParseKit/PKSymbol.h>
#import <ParseKit/PKToken.h>
@interface PKSymbol ()
@property (nonatomic, retain) PKToken *symbol;
@end
@implementation PKSymbol
+ (id)symbol {
return [[[self alloc] initWithString:nil] autorelease];
}
+ (id)symbolWithString:(NSString *)s {
return [[[self alloc] initWithString:s] autorelease];
}
- (id)initWithString:(NSString *)s {
self = [super initWithString:s];
if (self) {
if ([s length]) {
self.symbol = [PKToken tokenWithTokenType:PKTokenTypeSymbol stringValue:s floatValue:0.0];
}
}
return self;
}
- (void)dealloc {
self.symbol = nil;
[super dealloc];
}
- (BOOL)qualifies:(id)obj {
if (symbol) {
return [symbol isEqual:obj];
} else {
PKToken *tok = (PKToken *)obj;
return tok.isSymbol;
}
}
- (NSString *)description {
NSString *className = [NSStringFromClass([self class]) substringFromIndex:2];
if ([name length]) {
if (symbol) {
return [NSString stringWithFormat:@"%@ (%@) %@", className, name, symbol.stringValue];
} else {
return [NSString stringWithFormat:@"%@ (%@)", className, name];
}
} else {
if (symbol) {
return [NSString stringWithFormat:@"%@ %@", className, symbol.stringValue];
} else {
return [NSString stringWithFormat:@"%@", className];
}
}
}
@synthesize symbol;
@end