1 /*
2  * Distributed under the Boost Software License, Version 1.0.
3  *    (See accompanying file LICENSE_1_0.txt or copy at
4  *          http://www.boost.org/LICENSE_1_0.txt)
5  */
6 module glib.gscanner;
7 
8 import glib.gtypes;
9 import glib.gdataset;
10 import glib.ghash;
11 
12 
13 
14 extern (C)
15 alias GScannerMsgFunc = void function (GScanner      *scanner,
16 						 gchar	       *message,
17 						 gboolean	error);
18 
19 enum G_CSET_A_2_Z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
20 enum G_CSET_a_2_z = "abcdefghijklmnopqrstuvwxyz";
21 enum G_CSET_DIGITS = "0123456789";
22 enum G_CSET_LATINC = "\300\301\302\303\304\305\306" ~
23 			"\307\310\311\312\313\314\315\316\317\320" ~
24 			"\321\322\323\324\325\326" ~
25 			"\330\331\332\333\334\335\336";
26 
27 enum G_CSET_LATINS = "\337\340\341\342\343\344\345\346" ~
28 			"\347\350\351\352\353\354\355\356\357\360" ~
29 			"\361\362\363\364\365\366" ~
30 			"\370\371\372\373\374\375\376\377";
31 
32 enum GErrorType
33 {
34   G_ERR_UNKNOWN,
35   G_ERR_UNEXP_EOF,
36   G_ERR_UNEXP_EOF_IN_STRING,
37   G_ERR_UNEXP_EOF_IN_COMMENT,
38   G_ERR_NON_DIGIT_IN_CONST,
39   G_ERR_DIGIT_RADIX,
40   G_ERR_FLOAT_RADIX,
41   G_ERR_FLOAT_MALFORMED
42 }
43 
44 enum GTokenType
45 {
46   G_TOKEN_EOF			=   0,
47 
48   G_TOKEN_LEFT_PAREN		= '(',
49   G_TOKEN_RIGHT_PAREN		= ')',
50   G_TOKEN_LEFT_CURLY		= '{',
51   G_TOKEN_RIGHT_CURLY		= '}',
52   G_TOKEN_LEFT_BRACE		= '[',
53   G_TOKEN_RIGHT_BRACE		= ']',
54   G_TOKEN_EQUAL_SIGN		= '=',
55   G_TOKEN_COMMA			= ',',
56 
57   G_TOKEN_NONE			= 256,
58 
59   G_TOKEN_ERROR,
60 
61   G_TOKEN_CHAR,
62   G_TOKEN_BINARY,
63   G_TOKEN_OCTAL,
64   G_TOKEN_INT,
65   G_TOKEN_HEX,
66   G_TOKEN_FLOAT,
67   G_TOKEN_STRING,
68 
69   G_TOKEN_SYMBOL,
70   G_TOKEN_IDENTIFIER,
71   G_TOKEN_IDENTIFIER_NULL,
72 
73   G_TOKEN_COMMENT_SINGLE,
74   G_TOKEN_COMMENT_MULTI,
75 
76   /*< private >*/
77   G_TOKEN_LAST
78 }
79 
80 union GTokenValue
81 {
82   gpointer	v_symbol;
83   gchar		*v_identifier;
84   gulong	v_binary;
85   gulong	v_octal;
86   gulong	v_int;
87   guint64       v_int64;
88   gdouble	v_float;
89   gulong	v_hex;
90   gchar		*v_string;
91   gchar		*v_comment;
92   guchar	v_char;
93   guint		v_error;
94 }
95 
96 struct GScannerConfig;
97 // struct GScannerConfig
98 // {
99 //   /* Character sets
100 //    */
101 //   gchar		*cset_skip_characters;		/* default: " \t\n" */
102 //   gchar		*cset_identifier_first;
103 //   gchar		*cset_identifier_nth;
104 //   gchar		*cpair_comment_single;		/* default: "#\n" */
105 //
106 //   /* Should symbol lookup work case sensitive?
107 //    */
108 //   guint		case_sensitive : 1;
109 //
110 //   /* Boolean values to be adjusted "on the fly"
111 //    * to configure scanning behaviour.
112 //    */
113 //   guint		skip_comment_multi : 1;		/* C like comment */
114 //   guint		skip_comment_single : 1;	/* single line comment */
115 //   guint		scan_comment_multi : 1;		/* scan multi line comments? */
116 //   guint		scan_identifier : 1;
117 //   guint		scan_identifier_1char : 1;
118 //   guint		scan_identifier_NULL : 1;
119 //   guint		scan_symbols : 1;
120 //   guint		scan_binary : 1;
121 //   guint		scan_octal : 1;
122 //   guint		scan_float : 1;
123 //   guint		scan_hex : 1;			/* '0x0ff0' */
124 //   guint		scan_hex_dollar : 1;		/* '$0ff0' */
125 //   guint		scan_string_sq : 1;		/* string: 'anything' */
126 //   guint		scan_string_dq : 1;		/* string: "\\-escapes!\n" */
127 //   guint		numbers_2_int : 1;		/* bin, octal, hex => int */
128 //   guint		int_2_float : 1;		/* int => G_TOKEN_FLOAT? */
129 //   guint		identifier_2_string : 1;
130 //   guint		char_2_token : 1;		/* return G_TOKEN_CHAR? */
131 //   guint		symbol_2_token : 1;
132 //   guint		scope_0_fallback : 1;		/* try scope 0 on lookups? */
133 //   guint		store_int64 : 1; 		/* use value.v_int64 rather than v_int */
134 //
135 //   /*< private >*/
136 //   guint		padding_dummy;
137 // }
138 
139 
140 struct	GScanner
141 {
142   /* unused fields */
143   gpointer		user_data;
144   guint			max_parse_errors;
145 
146   /* g_scanner_error() increments this field */
147   guint			parse_errors;
148 
149   /* name of input stream, featured by the default message handler */
150   const(gchar)		*input_name;
151 
152   /* quarked data */
153   GData			*qdata;
154 
155   /* link into the scanner configuration */
156   GScannerConfig	*config;
157 
158   /* fields filled in after g_scanner_get_next_token() */
159   GTokenType		token;
160   GTokenValue		value;
161   guint			line;
162   guint			position;
163 
164   /* fields filled in after g_scanner_peek_next_token() */
165   GTokenType		next_token;
166   GTokenValue		next_value;
167   guint			next_line;
168   guint			next_position;
169 
170   /*< private >*/
171   /* to be considered private */
172   GHashTable		*symbol_table;
173   gint			input_fd;
174   const(gchar)		*text;
175   const(gchar)		*text_end;
176   gchar			*buffer;
177   guint			scope_id;
178 
179   /*< public >*/
180   /* handler function for _warn and _error */
181   GScannerMsgFunc	msg_handler;
182 }
183 
184 
185 extern (C) {
186 
187     GScanner*	g_scanner_new			(const(GScannerConfig) *config_templ);
188 
189     void		g_scanner_destroy		(GScanner	*scanner);
190 
191     void		g_scanner_input_file		(GScanner	*scanner,
192                              gint		input_fd);
193 
194     void		g_scanner_sync_file_offset	(GScanner	*scanner);
195 
196     void		g_scanner_input_text		(GScanner	*scanner,
197                              const(gchar)	*text,
198                              guint		text_len);
199 
200     GTokenType	g_scanner_get_next_token	(GScanner	*scanner);
201 
202     GTokenType	g_scanner_peek_next_token	(GScanner	*scanner);
203 
204     GTokenType	g_scanner_cur_token		(GScanner	*scanner);
205 
206     GTokenValue	g_scanner_cur_value		(GScanner	*scanner);
207 
208     guint		g_scanner_cur_line		(GScanner	*scanner);
209 
210     guint		g_scanner_cur_position		(GScanner	*scanner);
211 
212     gboolean	g_scanner_eof			(GScanner	*scanner);
213 
214     guint		g_scanner_set_scope		(GScanner	*scanner,
215                              guint		 scope_id);
216 
217     void		g_scanner_scope_add_symbol	(GScanner	*scanner,
218                              guint		 scope_id,
219                              const(gchar)	*symbol,
220                              gpointer	value);
221 
222     void		g_scanner_scope_remove_symbol	(GScanner	*scanner,
223                              guint		 scope_id,
224                              const(gchar)	*symbol);
225 
226     gpointer	g_scanner_scope_lookup_symbol	(GScanner	*scanner,
227                              guint		 scope_id,
228                              const(gchar)	*symbol);
229 
230     void		g_scanner_scope_foreach_symbol	(GScanner	*scanner,
231                              guint		 scope_id,
232                              GHFunc		 func,
233                              gpointer	 user_data);
234 
235     gpointer	g_scanner_lookup_symbol		(GScanner	*scanner,
236                              const(gchar)	*symbol);
237 
238     void		g_scanner_unexp_token		(GScanner	*scanner,
239                              GTokenType	expected_token,
240                              const(gchar)	*identifier_spec,
241                              const(gchar)	*symbol_spec,
242                              const(gchar)	*symbol_name,
243                              const(gchar)	*message,
244                              gint		 is_error);
245 
246     void		g_scanner_error			(GScanner	*scanner,
247                              const(gchar)	*format,
248                              ...);
249 
250     void		g_scanner_warn			(GScanner	*scanner,
251                              const(gchar)	*format,
252                              ...);
253 
254 }
255