ia64/xen-unstable

view tools/xfrd/sxpr_parser.h @ 1921:24ecc060e9d7

bitkeeper revision 1.1108.21.1 (41062740xHG36OEbpVAmVX5N9WCaNw)

make vmlinuz really stripped
author cl349@freefall.cl.cam.ac.uk
date Tue Jul 27 09:58:24 2004 +0000 (2004-07-27)
parents bae23a1177c6
children
line source
1 /*
2 *
3 * This library is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU Lesser General Public License as
5 * published by the Free Software Foundation; either version 2.1 of the
6 * License, or (at your option) any later version. This library is
7 * distributed in the hope that it will be useful, but WITHOUT ANY
8 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE.
10 * See the GNU Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this library; if not, write to the Free Software Foundation,
14 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
17 #ifndef _XUTIL_SXPR_PARSER_H_
18 #define _XUTIL_SXPR_PARSER_H_
20 #include "sxpr.h"
21 #include "iostream.h"
23 /** @file
24 * Sxpr parsing definitions.
25 */
27 /** Size of a parser input buffer.
28 * Tokens read must fit into this size (including trailing null).
29 */
30 #define PARSER_BUF_SIZE 1024
32 struct Parser;
33 typedef int ParserStateFn(struct Parser *, char c);
35 typedef struct ParserState {
36 struct ParserState *parent;
37 Sxpr val;
38 int ival;
39 int count;
40 char delim;
41 ParserStateFn *fn;
42 char *name;
43 } ParserState;
45 /** Structure representing an input source for the parser.
46 * Can read from any IOStream implementation.
47 */
48 typedef struct Parser {
49 Sxpr val;
50 /** Error reporting stream (null for no reports). */
51 IOStream *error_out;
52 int eof;
53 /** Error flag. Non-zero if there has been a read error. */
54 int err;
55 /** Line number on input (from 1). */
56 int line_no;
57 /** Column number of input (reset on new line). */
58 int char_no;
59 /** Lookahead character. */
60 char c;
61 /** Buffer for reading tokens. */
62 char buf[PARSER_BUF_SIZE];
63 /** Size of token buffer. */
64 int buf_n;
65 int buf_i;
66 /** Line the last token started on. */
67 int tok_begin_line;
68 /** Character number the last token started on. */
69 int tok_begin_char;
70 /** Parsing flags. */
71 int flags;
72 ParserState *state;
73 ParserState *start_state;
74 } Parser;
76 /** Parser error codes. */
77 typedef enum {
78 PARSE_ERR_NONE=0,
79 PARSE_ERR_UNSPECIFIED,
80 PARSE_ERR_NOMEM,
81 PARSE_ERR_UNEXPECTED_EOF,
82 PARSE_ERR_TOKEN_TOO_LONG,
83 PARSE_ERR_INVALID_SYNTAX,
84 PARSE_ERR_INVALID_ESCAPE,
85 } ParseErrorId;
88 /** Parser flags. */
89 //enum {
90 //};
92 /** Raise some parser flags.
93 *
94 * @param in parser
95 * @param flags flags mask
96 */
97 inline static void parser_flags_raise(Parser *in, int flags){
98 in->flags |= flags;
99 }
101 /** Lower some parser flags.
102 *
103 * @param in parser
104 * @param flags flags mask
105 */
106 inline static void parser_flags_lower(Parser *in, int flags){
107 in->flags &= ~flags;
108 }
110 /** Clear all parser flags.
111 *
112 * @param in parser
113 */
114 inline static void parser_flags_clear(Parser *in){
115 in->flags = 0;
116 }
118 extern void Parser_free(Parser *z);
119 extern Parser * Parser_new(void);
120 extern int Parser_input(Parser *p, char *buf, int buf_n);
121 extern int Parser_input_eof(Parser *p);
122 extern int Parser_input_char(Parser *p, char c);
123 extern void set_error_stream(Parser *z, IOStream *error_out);
125 extern int parse_error_message(Parser *in, char *buf, int n);
126 extern int has_error(Parser *in);
127 extern int at_eof(Parser *in);
129 int Parser_ready(Parser *p);
130 Sxpr Parser_get_val(Parser *p);
131 Sxpr Parser_get_all(Parser *p);
133 #endif /* ! _XUTIL_SXPR_PARSER_H_ */