diff options
author | Alex Merry <dev@randomguy3.me.uk> | 2013-03-26 12:54:41 +0000 |
---|---|---|
committer | Alex Merry <dev@randomguy3.me.uk> | 2013-03-26 12:54:41 +0000 |
commit | 3bfdc232f22f0fa5be20e0b603a8287626ec0c2f (patch) | |
tree | e54537047ac72238bc4eb2cd467d12e3a48b6939 /tikzit/src/common/TikzGraphAssembler.m | |
parent | 0f969b6ced7e9ebcbe4bc4e17867ff32d67f27bb (diff) |
Add edge anchor editing to GTK port
Includes functions for testing if an anchor is valid.
Diffstat (limited to 'tikzit/src/common/TikzGraphAssembler.m')
-rw-r--r-- | tikzit/src/common/TikzGraphAssembler.m | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m index c49298f..6b191a2 100644 --- a/tikzit/src/common/TikzGraphAssembler.m +++ b/tikzit/src/common/TikzGraphAssembler.m @@ -113,21 +113,44 @@ } + (BOOL)validateTikzPropertyNameOrValue:(NSString*)tikz { - BOOL r; - - NSString * testTikz = [NSString stringWithFormat: @"{%@}", tikz]; - + BOOL valid; + + NSString * testTikz = [NSString stringWithFormat: @"{%@}", tikz]; + void *scanner; yylex_init (&scanner); yyset_extra(nil, scanner); yy_scan_string([testTikz UTF8String], scanner); YYSTYPE lval; YYLTYPE lloc; - yylex(&lval, &lloc, scanner); - r = !(yyget_leng(scanner) < [testTikz length]); + int result = yylex(&lval, &lloc, scanner); + valid = (result == DELIMITEDSTRING) && + (yyget_leng(scanner) == [testTikz length]); yylex_destroy(scanner); - - return r; + + return valid; +} + ++ (BOOL)validateTikzEdgeAnchor:(NSString*)tikz { + BOOL valid = YES; + + NSString * testTikz = [NSString stringWithFormat: @"(1.%@)", tikz]; + + void *scanner; + yylex_init (&scanner); + yyset_extra(nil, scanner); + yy_scan_string([testTikz UTF8String], scanner); + YYSTYPE lval; + YYLTYPE lloc; + valid = valid && (yylex(&lval, &lloc, scanner) == LEFTPARENTHESIS); + valid = valid && (yylex(&lval, &lloc, scanner) == REFSTRING); + valid = valid && (yylex(&lval, &lloc, scanner) == FULLSTOP); + valid = valid && (yylex(&lval, &lloc, scanner) == REFSTRING); + valid = valid && (yylex(&lval, &lloc, scanner) == RIGHTPARENTHESIS); + valid = valid && (lloc.last_column == [testTikz length]); + yylex_destroy(scanner); + + return valid; } @end |