Angband
parser.h
Go to the documentation of this file.
1 
25 #ifndef PARSER_H
26 #define PARSER_H
27 
28 #include "h-basic.h"
29 #include "z-bitflag.h"
30 #include "z-dice.h"
31 #include "z-rand.h"
32 
33 struct parser;
34 
36  #define PARSE_ERROR(a, b) PARSE_ERROR_##a,
37  #include "list-parser-errors.h"
38  #undef PARSE_ERROR
39 
41 };
42 
43 struct parser_state {
45  unsigned int line;
46  unsigned int col;
47  char *msg;
48 };
49 
50 struct file_parser {
51  const char *name;
52  struct parser *(*init)(void);
53  errr (*run)(struct parser *p);
54  errr (*finish)(struct parser *p);
56 };
57 
58 extern const char *parser_error_str[PARSE_ERROR_MAX];
59 
60 extern struct parser *parser_new(void);
61 extern enum parser_error parser_parse(struct parser *p, const char *line);
62 extern void parser_destroy(struct parser *p);
63 extern void *parser_priv(struct parser *p);
64 extern void parser_setpriv(struct parser *p, void *v);
65 extern errr parser_reg(struct parser *p, const char *fmt,
66  enum parser_error (*func)(struct parser *p));
67 extern enum parser_error ignored(struct parser *p);
68 extern bool parser_hasval(struct parser *p, const char *name);
69 extern const char *parser_getsym(struct parser *p, const char *name);
70 extern const char *parser_getstr(struct parser *p, const char *name);
71 extern int parser_getint(struct parser *p, const char *name);
72 extern unsigned int parser_getuint(struct parser *p, const char *name);
73 extern struct random parser_getrand(struct parser *p, const char *name);
74 extern wchar_t parser_getchar(struct parser *p, const char *name);
75 extern int parser_getstate(struct parser *p, struct parser_state *s);
76 extern void parser_setstate(struct parser *p, unsigned int col, const char *msg);
77 
78 errr run_parser(struct file_parser *fp);
79 errr parse_file(struct parser *p, const char *filename);
80 void cleanup_parser(struct file_parser *fp);
81 int lookup_flag(const char **flag_table, const char *flag_name);
82 errr grab_rand_value(random_value *value, const char **value_type,
83  const char *name_and_value);
84 errr grab_int_value(int *value, const char **value_type,
85  const char *name_and_value);
86 errr grab_index_and_int(int *value, int *index, const char **value_type,
87  const char *prefix, const char *name_and_value);
88 errr grab_base_and_int(int *value, char **base, const char *name_and_value);
89 errr grab_name(const char *from, const char *what, const char *list[], int max,
90  int *num);
91 errr grab_flag(bitflag *flags, const size_t size, const char **flag_table,
92  const char *flag_name);
93 errr remove_flag(bitflag *flags, const size_t size, const char **flag_table,
94  const char *flag_name);
95 
96 #endif /* !PARSER_H */