summaryrefslogtreecommitdiff
path: root/tikzit/src
diff options
context:
space:
mode:
authorJohan Paulsson <gonz@users.sourceforge.net>2013-02-26 19:18:54 +0000
committerJohan Paulsson <gonz@users.sourceforge.net>2013-02-26 19:18:54 +0000
commitce5930b13b15a98e0c365003ef56cedc1c9cb6b3 (patch)
tree039741d2907a00d7fc76d9cb0ade664201345892 /tikzit/src
parent44fc6c6fc022b7262175a71a981ddc3969132ed5 (diff)
osx gui underlines the offending line on a parser error in document message
Diffstat (limited to 'tikzit/src')
-rw-r--r--tikzit/src/common/TikzGraphAssembler.m16
-rw-r--r--tikzit/src/osx/TikzSourceController.m31
2 files changed, 42 insertions, 5 deletions
diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m
index b07ee58..1dc997a 100644
--- a/tikzit/src/common/TikzGraphAssembler.m
+++ b/tikzit/src/common/TikzGraphAssembler.m
@@ -46,8 +46,20 @@ void yyerror(const char *str) {
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"
- code:TZ_ERR_PARSE
- userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithCString:str] forKey: NSLocalizedDescriptionKey]];
+ code:TZ_ERR_PARSE
+ userInfo:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSString stringWithCString:str encoding:NSUTF8StringEncoding],
+ [NSNumber numberWithInt:lineno],
+ [NSString stringWithCString:linebuff encoding:NSUTF8StringEncoding],
+ [NSNumber numberWithInt:tokenpos],
+ [NSNumber numberWithInt:yyleng],
+ nil]
+ forKeys: [NSArray arrayWithObjects:NSLocalizedDescriptionKey,
+ @"lineNumber",
+ @"syntaxString",
+ @"tokenStart",
+ @"tokenLength",
+ nil]]];
+
[currentAssembler invalidateWithError:error];
}
}
diff --git a/tikzit/src/osx/TikzSourceController.m b/tikzit/src/osx/TikzSourceController.m
index 428c6ba..6daff0f 100644
--- a/tikzit/src/osx/TikzSourceController.m
+++ b/tikzit/src/osx/TikzSourceController.m
@@ -180,12 +180,37 @@
[status setStringValue:@"parse error"];
[status setTextColor:failedColor];
+ NSDictionary *d = [[assembler lastError] userInfo];
- NSLog(@"Parse error: %@",[assembler lastError]);
+ NSString *ts = [NSString stringWithFormat: @"Parse error on line %@: %@\n", [d valueForKey:@"lineNumber"], [d valueForKey:NSLocalizedDescriptionKey]];
+ NSMutableAttributedString *as = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat: @"Parse error on line %@: %@\n%@\n", [d valueForKey:@"lineNumber"], [d valueForKey:NSLocalizedDescriptionKey], [[d valueForKey:@"syntaxString"] stringByReplacingOccurrencesOfString:@"\t" withString:@""]]];
- NSError *e = [assembler lastError];
+ NSInteger tokenLength = [[d valueForKey:@"tokenLength"] integerValue];
+ // Bit of a mess, offset around to find correct position and correct for 4 characters for every one character of \t
+ NSInteger addedTokenStart = [[d valueForKey:@"tokenStart"] integerValue] + [ts length] - ([[[d valueForKey:@"syntaxString"] componentsSeparatedByString:@"\t"] count]-1)*4 - tokenLength;
- [errorMessage setStringValue:[[[assembler lastError] userInfo] valueForKey:NSLocalizedDescriptionKey]];
+ // Can't see if the error is a start paranthesis as only that will be underlined, underline the entire paranthesis instead
+ if(tokenLength == 1 && [[as string] characterAtIndex:addedTokenStart] == '('){
+ tokenLength += [[[as string] substringFromIndex:addedTokenStart+1] rangeOfString:@")"].location + 1;
+ }
+
+ // Same if unexpected endparanthesis
+ if(tokenLength == 1 && [[as string] characterAtIndex:addedTokenStart] == ')'){
+ NSInteger d = addedTokenStart - [[[as string] substringToIndex:addedTokenStart] rangeOfString:@"(" options:NSBackwardsSearch].location;
+
+ tokenLength += d;
+ addedTokenStart -= d;
+ }
+
+ [as beginEditing];
+ [as addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:NSUnderlineStyleSingle | NSUnderlinePatternDot], NSUnderlineStyleAttributeName,
+ [NSColor redColor], NSUnderlineColorAttributeName,
+ nil]
+ range:NSMakeRange(addedTokenStart, tokenLength)];
+ [as endEditing];
+
+ [errorMessage setAttributedStringValue:as];
[errorNotification setHidden:FALSE];
}
}