summaryrefslogtreecommitdiff
path: root/tikzit/src/common/TikzGraphAssembler.m
diff options
context:
space:
mode:
Diffstat (limited to 'tikzit/src/common/TikzGraphAssembler.m')
-rw-r--r--tikzit/src/common/TikzGraphAssembler.m44
1 files changed, 37 insertions, 7 deletions
diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m
index 7d8d0e7..050b5fe 100644
--- a/tikzit/src/common/TikzGraphAssembler.m
+++ b/tikzit/src/common/TikzGraphAssembler.m
@@ -34,8 +34,16 @@ extern int yylex_destroy(void);
static NSLock *parseLock = nil;
static id currentAssembler = nil;
+int yylineno;
+int yyleng;
+int lineno;
+int tokenpos;
+char *yystr;
+char linebuff[500];
+
+
void yyerror(const char *str) {
- NSLog(@"Parse error: %s", 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
@@ -81,6 +89,10 @@ int yywrap() {
- (BOOL)parseTikz:(NSString*)tikz forGraph:(Graph*)gr {
[parseLock lock];
+
+ lineno = 1;
+ tokenpos = 0;
+ linebuff[0] = 0;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
currentAssembler = self;
@@ -93,12 +105,14 @@ int yywrap() {
// the node map keeps track of the mapping of names to nodes
nodeMap = [[NSMutableDictionary alloc] init];
-
- // do the parsing
- yy_scan_string([tikz UTF8String]);
- yyparse();
- yylex_destroy();
-
+
+ // do the parsing if actual input
+ if([tikz length] > 0){
+ yy_scan_string([tikz UTF8String]);
+ yyparse();
+ yylex_destroy();
+ }
+
[nodeMap release];
nodeMap = nil;
@@ -110,6 +124,22 @@ int yywrap() {
return (graph != nil);
}
+- (BOOL)testTikz:(NSString *)tikz{
+ BOOL r;
+
+ NSString * testTikz = [NSString stringWithFormat: @"{%@}", tikz];
+
+ yy_scan_string([testTikz UTF8String]);
+ yylex();
+
+ r = !(yyleng < [testTikz length]);
+
+ [testTikz autorelease];
+ yylex_destroy();
+
+ return r;
+}
+
- (void)prepareNode {
currentNode = [[Node alloc] init];
}