📄 safescanner.h
字号:
/* GLIB - Library of useful routines for C programming * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//* * Modified by the GLib Team and others 1997-2000. See the AUTHORS * file for a list of people on the GLib Team. See the ChangeLog * files for a list of changes. These files are distributed with * GLib at ftp://ftp.gtk.org/pub/gtk/. */#ifndef __SAFE_SCANNER_H__#define __SAFE_SCANNER_H__#include <glib.h>//G_BEGIN_DECLStypedef struct _SafeScanner SafeScanner;typedef struct _SafeScannerConfig SafeScannerConfig;typedef union _SafeTokenValue SafeTokenValue;typedef void (*SafeScannerMsgFunc) (SafeScanner *scanner, gchar *message, gboolean error);/* SafeScanner: Flexible lexical scanner for general purpose. *//* Character sets */#define G_CSET_A_2_Z "ABCDEFGHIJKLMNOPQRSTUVWXYZ"#define G_CSET_a_2_z "abcdefghijklmnopqrstuvwxyz"#define G_CSET_DIGITS "0123456789"#define G_CSET_LATINC "\300\301\302\303\304\305\306"\ "\307\310\311\312\313\314\315\316\317\320"\ "\321\322\323\324\325\326"\ "\330\331\332\333\334\335\336"#define G_CSET_LATINS "\337\340\341\342\343\344\345\346"\ "\347\350\351\352\353\354\355\356\357\360"\ "\361\362\363\364\365\366"\ "\370\371\372\373\374\375\376\377"/* Error types */typedef enum{ SAFE_ERR_UNKNOWN, SAFE_ERR_UNEXP_EOF, SAFE_ERR_UNEXP_EOF_IN_STRING, SAFE_ERR_UNEXP_EOF_IN_COMMENT, SAFE_ERR_NON_DIGIT_IN_CONST, SAFE_ERR_DIGIT_RADIX, SAFE_ERR_FLOAT_RADIX, SAFE_ERR_FLOAT_MALFORMED} SafeErrorType;/* Token types */typedef enum{ SAFE_TOKEN_EOF = 0, SAFE_TOKEN_LEFT_PAREN = '(', SAFE_TOKEN_RIGHT_PAREN = ')', SAFE_TOKEN_LEFT_CURLY = '{', SAFE_TOKEN_RIGHT_CURLY = '}', SAFE_TOKEN_LEFT_BRACE = '[', SAFE_TOKEN_RIGHT_BRACE = ']', SAFE_TOKEN_EQUAL_SIGN = '=', SAFE_TOKEN_COMMA = ',', SAFE_TOKEN_NONE = 256, SAFE_TOKEN_ERROR, SAFE_TOKEN_CHAR, SAFE_TOKEN_BINARY, SAFE_TOKEN_OCTAL, SAFE_TOKEN_INT, SAFE_TOKEN_HEX, SAFE_TOKEN_FLOAT, SAFE_TOKEN_STRING, SAFE_TOKEN_SYMBOL, SAFE_TOKEN_IDENTIFIER, SAFE_TOKEN_IDENTIFIER_NULL, SAFE_TOKEN_COMMENT_SINGLE, SAFE_TOKEN_COMMENT_MULTI, SAFE_TOKEN_LAST} SafeTokenType;union _SafeTokenValue{ gpointer v_symbol; gchar *v_identifier; gulong v_binary; gulong v_octal; gulong v_int; gdouble v_float; gulong v_hex; gchar *v_string; gchar *v_comment; guchar v_char; guint v_error;};struct _SafeScannerConfig{ /* Character sets */ gchar *cset_skip_characters; /* default: " \t\n" */ gchar *cset_identifier_first; gchar *cset_identifier_nth; gchar *cpair_comment_single; /* default: "#\n" */ /* Should symbol lookup work case sensitive? */ guint case_sensitive : 1; /* Boolean values to be adjusted "on the fly" * to configure scanning behaviour. */ guint skip_comment_multi : 1; /* C like comment */ guint skip_comment_single : 1; /* single line comment */ guint scan_comment_multi : 1; /* scan multi line comments? */ guint scan_identifier : 1; guint scan_identifier_1char : 1; guint scan_identifier_NULL : 1; guint scan_symbols : 1; guint scan_binary : 1; guint scan_octal : 1; guint scan_float : 1; guint scan_hex : 1; /* `0x0ff0' */ guint scan_hex_dollar : 1; /* `$0ff0' */ guint scan_string_sq : 1; /* string: 'anything' */ guint scan_string_dq : 1; /* string: "\\-escapes!\n" */ guint numbers_2_int : 1; /* bin, octal, hex => int */ guint int_2_float : 1; /* int => SAFE_TOKEN_FLOAT? */ guint identifier_2_string : 1; guint char_2_token : 1; /* return SAFE_TOKEN_CHAR? */ guint symbol_2_token : 1; guint scope_0_fallback : 1; /* try scope 0 on lookups? */ guint padding_dummy;};struct _SafeScanner{ /* unused fields */ gpointer user_data; guint max_parse_errors; /* safe_scanner_error() increments this field */ guint parse_errors; /* name of input stream, featured by the default message handler */ const gchar *input_name; /* quarked data */ GData *qdata; /* link into the scanner configuration */ SafeScannerConfig *config; /* fields filled in after safe_scanner_get_next_token() */ SafeTokenType token; SafeTokenValue value; guint line; guint position; /* fields filled in after safe_scanner_peek_next_token() */ SafeTokenType next_token; SafeTokenValue next_value; guint next_line; guint next_position; /* to be considered private */ GHashTable *symbol_table; gint input_fd; const gchar *text; const gchar *text_end; gchar *buffer; guint scope_id; /* handler function for _warn and _error */ SafeScannerMsgFunc msg_handler;};SafeScanner* safe_scanner_new (const SafeScannerConfig *config_templ);void safe_scanner_destroy (SafeScanner *scanner);void safe_scanner_input_file (SafeScanner *scanner, gint input_fd);void safe_scanner_sync_file_offset (SafeScanner *scanner);void safe_scanner_input_text (SafeScanner *scanner, const gchar *text, guint text_len);SafeTokenType safe_scanner_get_next_token (SafeScanner *scanner);SafeTokenType safe_scanner_peek_next_token (SafeScanner *scanner);SafeTokenType safe_scanner_cur_token (SafeScanner *scanner);SafeTokenValue safe_scanner_cur_value (SafeScanner *scanner);guint safe_scanner_cur_line (SafeScanner *scanner);guint safe_scanner_cur_position (SafeScanner *scanner);gboolean safe_scanner_eof (SafeScanner *scanner);guint safe_scanner_set_scope (SafeScanner *scanner, guint scope_id);void safe_scanner_scope_add_symbol (SafeScanner *scanner, guint scope_id, const gchar *symbol, gpointer value);void safe_scanner_scope_remove_symbol (SafeScanner *scanner, guint scope_id, const gchar *symbol);gpointer safe_scanner_scope_lookup_symbol (SafeScanner *scanner, guint scope_id, const gchar *symbol);void safe_scanner_scope_foreach_symbol (SafeScanner *scanner, guint scope_id, GHFunc func, gpointer user_data);gpointer safe_scanner_lookup_symbol (SafeScanner *scanner, const gchar *symbol);void safe_scanner_unexp_token (SafeScanner *scanner, SafeTokenType expected_token, const gchar *identifier_spec, const gchar *symbol_spec, const gchar *symbol_name, const gchar *message, gint is_error);void safe_scanner_error (SafeScanner *scanner, const gchar *format, ...) G_GNUC_PRINTF (2,3);void safe_scanner_warn (SafeScanner *scanner, const gchar *format, ...) G_GNUC_PRINTF (2,3);#ifndef G_DISABLE_DEPRECATED/* keep downward source compatibility */#define safe_scanner_add_symbol( scanner, symbol, value ) G_STMT_START { \ safe_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \} G_STMT_END#define safe_scanner_remove_symbol( scanner, symbol ) G_STMT_START { \ safe_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \} G_STMT_END#define safe_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \ safe_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \} G_STMT_END/* The following two functions are deprecated and will be removed in * the next major release. They do no good. */#define safe_scanner_freeze_symbol_table(scanner) ((void)0)#define safe_scanner_thaw_symbol_table(scanner) ((void)0)#endif /* G_DISABLE_DEPRECATED *///G_END_DECLS#endif /* __SAFE_SCANNER_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -