From d119a78273afe3570b3a2ce052e6eec3ee9f2e53 Mon Sep 17 00:00:00 2001 From: iska Date: Fri, 24 Oct 2014 01:08:06 +0200 Subject: [PATCH] Add stream location to Parse Error tokens for more comprehensive reporting --- HTMLKit/HTMLParseErrorToken.h | 3 ++- HTMLKit/HTMLParseErrorToken.m | 10 +++++++++- HTMLKit/HTMLTokenizer.m | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/HTMLKit/HTMLParseErrorToken.h b/HTMLKit/HTMLParseErrorToken.h index 5aac863..0f27a57 100644 --- a/HTMLKit/HTMLParseErrorToken.h +++ b/HTMLKit/HTMLParseErrorToken.h @@ -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 diff --git a/HTMLKit/HTMLParseErrorToken.m b/HTMLKit/HTMLParseErrorToken.m index e670b76..6097443 100644 --- a/HTMLKit/HTMLParseErrorToken.m +++ b/HTMLKit/HTMLParseErrorToken.m @@ -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 diff --git a/HTMLKit/HTMLTokenizer.m b/HTMLKit/HTMLTokenizer.m index 66eb95d..e411e46 100644 --- a/HTMLKit/HTMLTokenizer.m +++ b/HTMLKit/HTMLTokenizer.m @@ -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]; }