Add stream location to Parse Error tokens for more comprehensive reporting
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user