add predicates to arg_eval functions
[mala.git] / engine / engine.h
bloba5445b7795551709a2d8826125de1c85f84b84df
1 /*
2 engine.h - MaLa core engine
4 Copyright (C) 2004, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
20 #ifndef MALA_ENGINE_H
21 #define MALA_ENGINE_H
23 #include "mala_types.h"
24 #include "stringbucket.h"
25 #include "stringlist.h"
26 //#include "action.h"
29 Build a table of common strings, this strings are
30 a) get never garbage collected
31 b) are fast accessible with their symbolic index
33 #define MALA_COMMON_STRINGS \
34 { \
35 MALA_EXPAND (FALSE, "--FALSE"), \
36 MALA_EXPAND (TRUE, "--TRUE"), \
37 MALA_EXPAND (ZERO, "0"), \
38 MALA_EXPAND (NULL, "--NULL"), \
39 MALA_EXPAND (EXCLAMATIONMARK, "!"), \
40 MALA_EXPAND (ASSIGN, "="), \
41 MALA_EXPAND (BACKQUOTE, "`"), \
42 MALA_EXPAND (NOT, "--NOT"), \
43 MALA_EXPAND (LITERAL, "--LITERAL"), \
44 MALA_EXPAND (ENVSUBST, "--ENVSUBST"), \
45 MALA_EXPAND (SETENV, "--SETENV"), \
46 MALA_EXPAND (SECTION, "--SECTION"), \
47 MALA_EXPAND (HERE, "--HERE"), \
48 MALA_EXPAND (BEGIN, "--BEGIN"), \
49 MALA_EXPAND (END, "--END"), \
50 MALA_EXPAND (DEL, "--DEL"), \
51 MALA_EXPAND (DEFAULT_PARSER, "--DEFAULT-PARSER"), \
52 MALA_EXPAND (FLAG_LITERAL_EXPANSION, "--FLAG-LITERAL-EXPANSION"), \
53 MALA_EXPAND (FLAG_EXCLAM_EXPANSION, "--FLAG-EXCLAM-EXPANSION"), \
54 MALA_EXPAND (FLAG_NO_EXPANSION, "--FLAG-NO-EXPANSION"), \
55 MALA_EXPAND (FLAG_NUMSPLIT_EXPANSION, "--FLAG-NUMSPLIT-EXPANSION"), \
56 MALA_EXPAND (FLAG_CHAR_EXPANSION, "--FLAG-CHAR-EXPANSION"), \
57 MALA_EXPAND (FLAG_ASSIGN_EXPANSION, "--FLAG-ASSIGN-EXPANSION"), \
58 MALA_EXPAND (FLAG_SETENV_EXPANSION, "--FLAG-SETENV-EXPANSION"), \
59 MALA_EXPAND (FLAG_ENVVAR_EXPANSION, "--FLAG-ENVVAR-EXPANSION"), \
60 MALA_EXPAND (FLAG_UNDERSCORE_EXPANSION, "--FLAG-UNDERSCORE-EXPANSION"), \
61 MALA_EXPAND (FLAG_BRACKET_EXPANSION, "--FLAG-BRACKET-EXPANSION"), \
62 MALA_EXPAND (FLAG_ASSIGN_CONTRACTION, "--FLAG-ASSIGN-CONTRACTION"), \
63 MALA_EXPAND (ERROR_MISSING_ARGUMENT, "--ERROR-MISSING-ARGUMENT"), \
64 MALA_EXPAND (ERROR_MISSING_END, "--ERROR-MISSING-END"), \
65 MALA_EXPAND (ERROR_END_WITHOUT_BEGIN, "--ERROR-END-WITHOUT-BEGIN"), \
66 MALA_EXPAND (ERROR_BLOCK_NOT_ALLOWED, "--ERROR-BLOCK-NOT-ALLOWED"), \
67 MALA_EXPAND (ERROR_PARAMETER_SYNTAX, "--ERROR-PARAMETER-SYNTAX"), \
68 MALA_EXPAND (ERROR_WRONG_TYPE, "--ERROR-WRONG-TYPE"), \
69 MALA_EXPAND (MAX, NULL) \
72 #define MALA_EXPAND(E,s) MALA_STRING_##E
73 enum mala_common_strings_enum MALA_COMMON_STRINGS;
74 #undef MALA_EXPAND
77 //#ifdef MALA_PRIVATE
78 struct mala_engine_struct
81 * every tokenized word is collected in 'words'
82 * actions can be bound to these words through the strings user variable
84 mala_stringbucket words;
85 mala_stringlist program;
86 mala_stringlist arguments;
88 MalaString common_string[MALA_STRING_MAX];
90 /*TODO static ringbuffer char ringbuffer *[10] */
92 //const char * argv_0;
94 int negated:1;
96 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
97 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
98 unsigned blockcnt;
100 int state;
102 //#endif
105 \f/**/
110 * Mala engine
112 MalaEngine
113 mala_engine_new ();
115 #if 0
116 MalaEngine
117 mala_engine_new_main (int (*initfunc) (MalaEngine),
118 int argc, char ** argv,
119 mala_actioninit * actions_init);
120 #endif
122 void
123 mala_engine_free (MalaEngine self);
126 mala_engine_actions_register (MalaEngine, MalaActionInit);
129 mala_engine_exception (MalaEngine self,
130 MalaStringListNode_ref pptr,
131 MalaStringListNode here,
132 MalaString message);
135 mala_engine_ppexpand_define (MalaEngine self, const char * name, int argc, char **argv);
138 mala_engine_pushback_word (MalaEngine self, const char * word);
140 MalaStringList
141 mala_engine_getprogram (MalaEngine self);
143 mala_state
144 mala_engine_state_get (MalaEngine self);
146 void
147 mala_engine_clearstate (MalaEngine self);
150 mala_engine_negated (MalaEngine self);
152 void
153 mala_engine_clear_negated (MalaEngine self);
155 void
156 mala_engine_dumpprogram (MalaEngine self, FILE* stream, const char * prefix, const char * suffix);
158 void
159 mala_engine_dumpargs (MalaEngine self, FILE* stream, const char * prefix, const char * suffix);
161 MalaEngine
162 mala_engine_run (MalaEngine self);
164 MalaEngine
165 mala_engine_step (MalaEngine);
168 mala_engine_eval (MalaEngine self, MalaStringListNode_ref pptr);
170 //int
171 //mala_engine_expansions (MalaEngine self, MalaStringListNode_ref pptr);
175 mala_engine_string_istrue (MalaEngine self, MalaString str);
178 mala_engine_check_expansionflag (MalaEngine self, int flag);
182 mala_engine_ppexpand (MalaEngine self, MalaStringList list, MalaStringListNode_ref pptr);
185 mala_engine_literal_expansion (MalaEngine self,
186 MalaStringList list,
187 MalaStringListNode_ref pptr);
190 mala_engine_backquote_expansion (MalaEngine self,
191 MalaStringList list,
192 MalaStringListNode_ref pptr);
195 mala_engine_numsplit_expansion (MalaEngine self,
196 MalaStringList list,
197 MalaStringListNode_ref pptr);
200 mala_engine_exclam_expansion (MalaEngine self,
201 MalaStringList list,
202 MalaStringListNode_ref pptr);
205 mala_engine_no_expansion (MalaEngine self,
206 MalaStringList list,
207 MalaStringListNode_ref pptr);
210 mala_engine_assign_expansion (MalaEngine self,
211 MalaStringList list,
212 MalaStringListNode_ref pptr);
215 mala_engine_envvar_expansion (MalaEngine self,
216 MalaStringList list,
217 MalaStringListNode_ref pptr);
220 mala_engine_char_expansion (MalaEngine self,
221 MalaStringList list,
222 MalaStringListNode_ref pptr);
225 mala_engine_underscore_expansion (MalaEngine self,
226 MalaStringList list,
227 MalaStringListNode_ref pptr);
229 int mala_engine_setenv_expansion (MalaEngine self,
230 MalaStringList list,
231 MalaStringListNode_ref pptr);
233 int mala_engine_bracket_expansion (MalaEngine self,
234 MalaStringList list,
235 MalaStringListNode_ref pptr);
237 int mala_engine_assign_contraction (MalaEngine self,
238 MalaStringList list,
239 MalaStringListNode_ref pptr);
242 mala_engine_add_action_cstr (MalaEngine self, const char* cname, void* data,
243 MalaParserFunc parser, MalaDataFactory factory,
244 MalaAction parent);
247 mala_engine_add_action (MalaEngine self, MalaString name, void* data,
248 MalaParserFunc parser, MalaDataFactory factory,
249 MalaAction parent);
251 MalaStringListNode
252 mala_engine_arg_eval (MalaEngine self,
253 MalaStringListNode_ref pptr,
254 unsigned nth,
255 int times,
256 MalaDataFactory type);
259 mala_engine_arg_eval_fmt (MalaEngine self,
260 MalaStringListNode_ref pptr,
261 unsigned nth,
262 const char* fmt,
263 void * dest,
264 MalaPredicate pred,
265 void * constraint);
267 MalaString
268 mala_engine_arg_eval_string (MalaEngine self,
269 MalaStringListNode_ref pptr,
270 unsigned nth,
271 MalaPredicate pred,
272 void * constraint);
275 #if 0 /*TODO*/
277 MalaEngine
278 mala_engine_new_initfunc (int (*initfunc) (MalaEngine));
282 void
283 mala_engine_pushfront_program (MalaEngine self, int args, char ** argv);
287 mala_engine_erase_action (MalaEngine, const t_uchar * key);
290 mala_engine_eval (MalaEngine self, LList pptr);
293 mala_engine_deepeval (MalaEngine self, LList pptr);
297 mala_engine_exception (MalaEngine, LList begin, LList end, const char *);
299 MalaAction
300 mala_engine_action_new (MalaEngine, t_uchar** name, void** data,
301 MalaParserFunc parser, MalaDataDestructor destructor);
304 MalaAction
305 mala_engine_getaction (MalaEngine, const t_uchar * name);
307 MalaAction
308 mala_engine_getprevaction (MalaEngine, const t_uchar * name);
310 #endif /*TODO*/
316 #endif /*MALA_ENGINE_H*/
318 // Local Variables:
319 // mode: C
320 // c-file-style: "gnu"
321 // End:
322 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7
323 // end_of_file