diff options
author | Johan Paulsson <gonz@users.sourceforge.net> | 2013-02-28 14:17:41 +0000 |
---|---|---|
committer | Johan Paulsson <gonz@users.sourceforge.net> | 2013-02-28 14:17:41 +0000 |
commit | 607e78b8d13071fc248c5c77cb8d517c25454aaa (patch) | |
tree | c834a0e1c2431650bfd235d278edfbfa2ace7399 /tikzit | |
parent | 16d89050977ccdc9d6fafc5ee03d8be1f4ae717d (diff) |
parser: gives correct error description if parse error is on first line
Diffstat (limited to 'tikzit')
-rw-r--r-- | tikzit/src/common/TikzGraphAssembler.m | 16 |
1 files changed, 15 insertions, 1 deletions
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; |