summaryrefslogtreecommitdiff
path: root/tikzit/src/common/TikzGraphAssembler.h
blob: c3651285afb984efc5b863ca49ef36063760baaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
//  TikzGraphAssembler.h
//  TikZiT
//  
//  Copyright 2010 Aleks Kissinger. All rights reserved.
//  
//  
//  This file is part of TikZiT.
//  
//  TikZiT is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//  
//  TikZiT is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with TikZiT.  If not, see <http://www.gnu.org/licenses/>.
//  

#import <Foundation/Foundation.h>
#import "Graph.h"

/**
 * Parses (a subset of) tikz code and produces the corresponding Graph
 *
 * A note on errors:
 * If parsing fails and a non-NULL error argument is given, it will be
 * populated with an error with domain TZErrorDomain and code TZ_ERR_PARSE
 * (see NSError+Tikzit.h).
 *
 * This will have a description set, typically something like
 *   "syntax error, unexpected [, expecting ("
 * It may also have the following keys (it will have all or none of these),
 * where numbers are stored using NSNumber:
 *   - startLine:    the line (starting at 1) containing the first character
 *                   of the bad token
 *   - startColumn:  the column (starting at 1; tabs count for 1) of the first
 *                   character of the bad token
 *   - endLine:      the line (starting at 1) containing the last character
 *                   of the bad token
 *   - endColumn:    the column (starting at 1; tabs count for 1) of the last
 *                   character of the bad token
 *   - syntaxString: an excerpt of the input string (typically the contents
 *                   from startLine to endLine) providing some context
 *   - tokenOffset:  the character offset (starting at 0) of the bad token
 *                   within syntaxString
 *   - tokenLength:  the character length (including newlines) of the bad token
 *                   within syntaxString
 */
@interface TikzGraphAssembler : NSObject {
	const char *tikzStr;
	Graph *graph;
	void *scanner;
	NSMutableDictionary *nodeMap;
	NSError *lastError;
}

/**
 * Parse tikz and place the result in gr
 *
 * Note that the graph must be empty; this might be used from an init
 * method, for example, although don't forget that you can return a
 * different object in init methods, providing you get the allocation
 * right.
 *
 * @param tikz   the tikz string to parse
 * @param gr     the graph to store the result in (must be empty, non-nil)
 * @param e      a location to store an error if parsing fails (may be NULL)
 * @return       YES if parsing succeeded, NO otherwise
 */
+ (BOOL) parseTikz:(NSString*)tikz forGraph:(Graph*)gr error:(NSError**)e;
/**
 * Overload for -[parseTikz:forGraph:error:] with the error set to NULL
 */
+ (BOOL) parseTikz:(NSString*)tikz forGraph:(Graph*)gr;
/**
 * Parse tikz
 *
 * @param tikz   the tikz string to parse
 * @param e      a location to store an error if parsing fails (may be NULL)
 * @return       a Graph object if parsing succeeded, nil otherwise
 */
+ (Graph*) parseTikz:(NSString*)tikz error:(NSError**)e;
/**
 * Overload for -[parseTikz:error:] with the error set to NULL
 */
+ (Graph*) parseTikz:(NSString*)tikz;
/**
 * Validate a property string or value
 *
 * Wraps the string in "{" and "}" and checks it lexes completely; in other
 * words, makes sure that "{" and "}" are balanced (ignoring escaped versions).
 * @param tikz   the string to validate
 * @return       YES if the string can be used as a property name or value, NO
 *               otherwise
 */
+ (BOOL)validateTikzPropertyNameOrValue:(NSString*)tikz;

@end

// vi:ft=objc:noet:ts=4:sts=4:sw=4