From 607e78b8d13071fc248c5c77cb8d517c25454aaa Mon Sep 17 00:00:00 2001 From: Johan Paulsson Date: Thu, 28 Feb 2013 14:17:41 +0000 Subject: parser: gives correct error description if parse error is on first line --- tikzit/src/common/TikzGraphAssembler.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m index 1dc997a..a60fe0e 100644 --- a/tikzit/src/common/TikzGraphAssembler.m +++ b/tikzit/src/common/TikzGraphAssembler.m @@ -43,6 +43,12 @@ char linebuff[500]; void yyerror(const char *str) { + // if the error is on the first line, treat specially + if(lineno == 1){ +// strcpy(linebuff, yytext+1); + NSLog(@"Problem ahoy!"); + } + NSLog(@"Parse error on line %i: %s\n%s\n%@\n", lineno, str, linebuff, [[@"" stringByPaddingToLength:(tokenpos-yyleng) withString: @" " startingAtIndex:0] stringByAppendingString:[@"" stringByPaddingToLength:yyleng withString: @"^" startingAtIndex:0]]); if (currentAssembler != nil) { NSError *error = [NSError errorWithDomain:@"net.sourceforge.tikzit" @@ -104,7 +110,15 @@ int yywrap() { lineno = 1; tokenpos = 0; - linebuff[0] = 0; + NSRange range = [tikz rangeOfString:@"\n"]; + [tikz getBytes:linebuff + maxLength:499 + usedLength:NULL + encoding:NSUTF8StringEncoding + options:0 + range:NSMakeRange(0, range.location) + remainingRange:NULL]; + linebuff[range.location] = 0; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; currentAssembler = self; -- cgit v1.2.3