Add stream location to Parse Error tokens for more comprehensive reporting

This commit is contained in:
iska
2014-10-24 01:08:06 +02:00
parent 7c4e39af07
commit d119a78273
3 changed files with 13 additions and 3 deletions
+2 -1
View File
@@ -12,7 +12,8 @@
@interface HTMLParseErrorToken : HTMLToken
@property (nonatomic, copy) NSString *reason;
@property (nonatomic, assign) NSUInteger location;
- (instancetype)initWithReasonMessage:(NSString *)reason;
- (instancetype)initWithReasonMessage:(NSString *)reason andStreamLocation:(NSUInteger)location;
@end
+9 -1
View File
@@ -11,20 +11,28 @@
@interface HTMLParseErrorToken ()
{
NSString *_reason;
NSUInteger _location;
}
@end
@implementation HTMLParseErrorToken
@synthesize reason = _reason;
@synthesize location = _location;
- (instancetype)initWithReasonMessage:(NSString *)reason
- (instancetype)initWithReasonMessage:(NSString *)reason andStreamLocation:(NSUInteger)location
{
self = [super init];
if (self) {
self.type = HTMLTokenTypeParseError;
_reason = [reason copy];
_location = location;
}
return self;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p Reason=%@ Location=%lu>", self.class, self, _reason, _location];
}
@end
+2 -1
View File
@@ -166,7 +166,8 @@
va_start(args, format);
NSString *message = [[NSString alloc] initWithFormat:format arguments:args];
va_end(args);
HTMLParseErrorToken *token = [[HTMLParseErrorToken alloc] initWithReasonMessage:message];
HTMLParseErrorToken *token = [[HTMLParseErrorToken alloc] initWithReasonMessage:message
andStreamLocation:_inputStreamReader.currentLocation];
[self emitToken:token];
}