From 84d4bc6f0f38e237f2a40faaf75e921211ab0ac6 Mon Sep 17 00:00:00 2001 From: randomguy3 Date: Sat, 10 Mar 2012 16:16:25 +0000 Subject: Better parse error reporting git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@424 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64 --- tikzit/src/common/NSError+Tikzit.h | 3 ++- tikzit/src/common/TikzGraphAssembler.h | 4 +++- tikzit/src/common/TikzGraphAssembler.m | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) (limited to 'tikzit/src/common') diff --git a/tikzit/src/common/NSError+Tikzit.h b/tikzit/src/common/NSError+Tikzit.h index a82db4d..0f45fba 100644 --- a/tikzit/src/common/NSError+Tikzit.h +++ b/tikzit/src/common/NSError+Tikzit.h @@ -25,7 +25,8 @@ enum { TZ_ERR_BADFORMAT, TZ_ERR_IO, TZ_ERR_TOOL_FAILED, - TZ_ERR_NOTDIRECTORY + TZ_ERR_NOTDIRECTORY, + TZ_ERR_PARSE }; NSString* const TZToolOutputErrorKey; diff --git a/tikzit/src/common/TikzGraphAssembler.h b/tikzit/src/common/TikzGraphAssembler.h index e976405..1b006dd 100644 --- a/tikzit/src/common/TikzGraphAssembler.h +++ b/tikzit/src/common/TikzGraphAssembler.h @@ -29,13 +29,14 @@ Node *currentNode; Edge *currentEdge; NSMutableDictionary *nodeMap; + NSError *lastError; } @property (readonly) Graph *graph; @property (readonly) GraphElementData *data; @property (readonly) Node *currentNode; @property (readonly) Edge *currentEdge; - +@property (readonly) NSError *lastError; - (BOOL)parseTikz:(NSString*)tikz; - (BOOL)parseTikz:(NSString*)tikz forGraph:(Graph*)gr; @@ -48,6 +49,7 @@ - (void)finishEdge; - (void)invalidate; +- (void)invalidateWithError:(NSError*)error; + (void)setup; + (TikzGraphAssembler*)currentAssembler; diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m index 5354710..5e60b05 100644 --- a/tikzit/src/common/TikzGraphAssembler.m +++ b/tikzit/src/common/TikzGraphAssembler.m @@ -22,6 +22,7 @@ // #import "TikzGraphAssembler.h" +#import "NSError+Tikzit.h" extern int yyparse(void); extern int yylex(void); @@ -36,7 +37,10 @@ static id currentAssembler = nil; void yyerror(const char *str) { NSLog(@"Parse error: %s", str); if (currentAssembler != nil) { - [currentAssembler invalidate]; + NSError *error = [NSError + errorWithMessage:[NSString stringWithCString:str] + code:TZ_ERR_PARSE]; + [currentAssembler invalidateWithError:error]; } } @@ -56,6 +60,7 @@ int yywrap() { } - (Graph*)graph { return graph; } +- (NSError*)lastError { return lastError; } - (GraphElementData *)data { if (currentNode != nil) { @@ -95,6 +100,7 @@ int yywrap() { yylex_destroy(); [nodeMap release]; + nodeMap = nil; currentAssembler = nil; [pool drain]; @@ -144,12 +150,19 @@ int yywrap() { - (void)dealloc { [graph release]; + [lastError release]; [super dealloc]; } - (void)invalidate { [graph release]; graph = nil; + lastError = nil; +} + +- (void)invalidateWithError:(NSError*)error { + [self invalidate]; + lastError = [error retain]; } + (void)setup { -- cgit v1.2.3