summaryrefslogtreecommitdiff
path: root/tikzit/src/common
diff options
context:
space:
mode:
authorrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-03-10 16:16:25 +0000
committerrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-03-10 16:16:25 +0000
commit84d4bc6f0f38e237f2a40faaf75e921211ab0ac6 (patch)
treed3a644fed47ea2b24cf6c9a50480bd766f036bc9 /tikzit/src/common
parent4f15081a2cdf33c1ec6ba8c3c90ae81a7d4b42e8 (diff)
Better parse error reporting
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@424 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
Diffstat (limited to 'tikzit/src/common')
-rw-r--r--tikzit/src/common/NSError+Tikzit.h3
-rw-r--r--tikzit/src/common/TikzGraphAssembler.h4
-rw-r--r--tikzit/src/common/TikzGraphAssembler.m15
3 files changed, 19 insertions, 3 deletions
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 {