1 /* json-scanner.h: Tokenizer for JSON
3 * This file is part of JSON-GLib
4 * Copyright (C) 2008 OpenedHand
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * JsonScanner is a specialized tokenizer for JSON adapted from
24 * the GScanner tokenizer in GLib; GScanner came with this notice:
26 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
27 * file for a list of people on the GLib Team. See the ChangeLog
28 * files for a list of changes. These files are distributed with
29 * GLib at ftp://ftp.gtk.org/pub/gtk/.
31 * JsonScanner: modified by Emmanuele Bassi <ebassi@openedhand.com>
34 #ifndef __JSON_SCANNER_H__
35 #define __JSON_SCANNER_H__
41 typedef struct _JsonScanner JsonScanner;
42 typedef struct _JsonScannerConfig JsonScannerConfig;
44 typedef void (* JsonScannerMsgFunc) (JsonScanner *scanner,
50 * @JSON_TOKEN_INVALID: marker
51 * @JSON_TOKEN_TRUE: symbol for 'true' bareword
52 * @JSON_TOKEN_FALSE: symbol for 'false' bareword
53 * @JSON_TOKEN_NULL: symbol for 'null' bareword
54 * @JSON_TOKEN_VAR: symbol for 'var' bareword
55 * @JSON_TOKEN_LAST: marker
57 * Tokens for JsonScanner-based parser, extending #GTokenType.
60 JSON_TOKEN_INVALID = G_TOKEN_LAST,
73 * Tokenizer scanner for JSON. See #GScanner
82 guint max_parse_errors;
84 /* json_scanner_error() increments this field */
87 /* name of input stream, featured by the default message handler */
88 const gchar *input_name;
93 /* link into the scanner configuration */
94 JsonScannerConfig *config;
96 /* fields filled in after json_scanner_get_next_token() */
102 /* fields filled in after json_scanner_peek_next_token() */
103 GTokenType next_token;
104 GTokenValue next_value;
108 /* to be considered private */
109 GHashTable *symbol_table;
112 const gchar *text_end;
116 /* handler function for _warn and _error */
117 JsonScannerMsgFunc msg_handler;
120 JsonScanner *json_scanner_new (void);
121 void json_scanner_destroy (JsonScanner *scanner);
122 void json_scanner_input_file (JsonScanner *scanner,
124 void json_scanner_sync_file_offset (JsonScanner *scanner);
125 void json_scanner_input_text (JsonScanner *scanner,
128 GTokenType json_scanner_get_next_token (JsonScanner *scanner);
129 GTokenType json_scanner_peek_next_token (JsonScanner *scanner);
130 GTokenType json_scanner_cur_token (JsonScanner *scanner);
131 GTokenValue json_scanner_cur_value (JsonScanner *scanner);
132 guint json_scanner_cur_line (JsonScanner *scanner);
133 guint json_scanner_cur_position (JsonScanner *scanner);
134 gboolean json_scanner_eof (JsonScanner *scanner);
135 guint json_scanner_set_scope (JsonScanner *scanner,
137 void json_scanner_scope_add_symbol (JsonScanner *scanner,
141 void json_scanner_scope_remove_symbol (JsonScanner *scanner,
143 const gchar *symbol);
144 gpointer json_scanner_scope_lookup_symbol (JsonScanner *scanner,
146 const gchar *symbol);
147 void json_scanner_scope_foreach_symbol (JsonScanner *scanner,
151 gpointer json_scanner_lookup_symbol (JsonScanner *scanner,
152 const gchar *symbol);
153 void json_scanner_unexp_token (JsonScanner *scanner,
154 GTokenType expected_token,
155 const gchar *identifier_spec,
156 const gchar *symbol_spec,
157 const gchar *symbol_name,
158 const gchar *message,
160 void json_scanner_error (JsonScanner *scanner,
162 ...) G_GNUC_PRINTF (2,3);
163 void json_scanner_warn (JsonScanner *scanner,
165 ...) G_GNUC_PRINTF (2,3);
169 #endif /* __JSON_SCANNER_H__ */