summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <dev@randomguy3.me.uk>2013-03-24 15:41:25 +0000
committerAlex Merry <dev@randomguy3.me.uk>2013-03-24 16:47:01 +0000
commit2724cb0739c4b2b2187f31634f5a6c97b6f91c87 (patch)
tree993199a97e98a2bdc38eb504617fee035f5a5d67
parent9e47962ddd0dc9f6874b7ca50874d444ed81c848 (diff)
Document TikzGraphAssembler
-rw-r--r--tikzit/src/common/TikzGraphAssembler.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/tikzit/src/common/TikzGraphAssembler.h b/tikzit/src/common/TikzGraphAssembler.h
index 37279e5..c365128 100644
--- a/tikzit/src/common/TikzGraphAssembler.h
+++ b/tikzit/src/common/TikzGraphAssembler.h
@@ -24,6 +24,33 @@
#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;
@@ -32,10 +59,45 @@
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