else_parser
[mala.git] / engine / engine.h
blobda0e655b19d15f9b54f8d48fc20fdc44969b9cc4
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 (EMPTY, ""), \
36 MALA_EXPAND (FALSE, "--FALSE"), \
37 MALA_EXPAND (TRUE, "--TRUE"), \
38 MALA_EXPAND (ZERO, "0"), \
39 MALA_EXPAND (PASS, "--PASS"), \
40 MALA_EXPAND (EXCLAMATIONMARK, "!"), \
41 MALA_EXPAND (ASSIGN, "="), \
42 MALA_EXPAND (BACKQUOTE, "`"), \
43 MALA_EXPAND (NOT, "--NOT"), \
44 MALA_EXPAND (LITERAL, "--LITERAL"), \
45 MALA_EXPAND (ENVSUBST, "--ENVSUBST"), \
46 MALA_EXPAND (SETENV, "--SETENV"), \
47 MALA_EXPAND (SECTION, "--SECTION"), \
48 MALA_EXPAND (HERE, "--HERE"), \
49 MALA_EXPAND (BEGIN, "--BEGIN"), \
50 MALA_EXPAND (END, "--END"), \
51 MALA_EXPAND (DEL, "--DEL"), \
52 MALA_EXPAND (DEFAULT_PARSER, "--DEFAULT-PARSER"), \
53 MALA_EXPAND (FLAG_LITERAL_EXPANSION, "--FLAG-LITERAL-EXPANSION"), \
54 MALA_EXPAND (FLAG_EXCLAM_EXPANSION, "--FLAG-EXCLAM-EXPANSION"), \
55 MALA_EXPAND (FLAG_NO_EXPANSION, "--FLAG-NO-EXPANSION"), \
56 MALA_EXPAND (FLAG_NUMSPLIT_EXPANSION, "--FLAG-NUMSPLIT-EXPANSION"), \
57 MALA_EXPAND (FLAG_CHAR_EXPANSION, "--FLAG-CHAR-EXPANSION"), \
58 MALA_EXPAND (FLAG_ASSIGN_EXPANSION, "--FLAG-ASSIGN-EXPANSION"), \
59 MALA_EXPAND (FLAG_SETENV_EXPANSION, "--FLAG-SETENV-EXPANSION"), \
60 MALA_EXPAND (FLAG_ENVVAR_EXPANSION, "--FLAG-ENVVAR-EXPANSION"), \
61 MALA_EXPAND (FLAG_UNDERSCORE_EXPANSION, "--FLAG-UNDERSCORE-EXPANSION"), \
62 MALA_EXPAND (FLAG_BRACKET_EXPANSION, "--FLAG-BRACKET-EXPANSION"), \
63 MALA_EXPAND (FLAG_ASSIGN_CONTRACTION, "--FLAG-ASSIGN-CONTRACTION"), \
64 MALA_EXPAND (ERROR_MISSING_ARGUMENT, "--ERROR-MISSING-ARGUMENT"), \
65 MALA_EXPAND (ERROR_MISSING_END, "--ERROR-MISSING-END"), \
66 MALA_EXPAND (ERROR_END_WITHOUT_BEGIN, "--ERROR-END-WITHOUT-BEGIN"), \
67 MALA_EXPAND (ERROR_BLOCK_NOT_ALLOWED, "--ERROR-BLOCK-NOT-ALLOWED"), \
68 MALA_EXPAND (ERROR_PARAMETER_SYNTAX, "--ERROR-PARAMETER-SYNTAX"), \
69 MALA_EXPAND (ERROR_WRONG_TYPE, "--ERROR-WRONG-TYPE"), \
70 MALA_EXPAND (MAX, NULL) \
73 #define MALA_EXPAND(E,s) MALA_STRING_##E
74 enum mala_common_strings_enum MALA_COMMON_STRINGS;
75 #undef MALA_EXPAND
77 const char * mala_engine_states [MALA_STATE_TABLE_SIZEOF+1];
79 //#ifdef MALA_PRIVATE
80 struct mala_engine_struct
83 * every tokenized word is collected in 'words'
84 * actions can be bound to these words through the strings user variable
86 mala_stringbucket words;
87 mala_stringlist program;
88 mala_stringlist arguments;
90 MalaString common_string[MALA_STRING_MAX];
92 /*TODO static ringbuffer char ringbuffer *[10] */
94 //const char * argv_0;
96 int negated:1;
97 int trace:1;
99 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
100 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
101 unsigned blockcnt;
103 int state;
105 //#endif
108 \f/**/
113 * Mala engine
115 MalaEngine
116 mala_engine_new ();
118 #if 0
119 MalaEngine
120 mala_engine_new_main (int (*initfunc) (MalaEngine),
121 int argc, char ** argv,
122 mala_actioninit * actions_init);
123 #endif
125 void
126 mala_engine_free (MalaEngine self);
129 mala_engine_actions_register (MalaEngine, MalaActionInit);
132 mala_engine_exception (MalaEngine self,
133 MalaStringListNode_ref pptr,
134 MalaStringListNode here,
135 MalaString message);
138 mala_engine_ppexpand_define (MalaEngine self, const char * name, int argc, char **argv);
141 mala_engine_pushback_word (MalaEngine self, const char * word);
143 MalaStringList
144 mala_engine_getprogram (MalaEngine self);
146 mala_state
147 mala_engine_state_get (MalaEngine self);
149 const char *
150 mala_engine_state_str (MalaEngine self);
152 void
153 mala_engine_clearstate (MalaEngine self);
156 mala_engine_negated (MalaEngine self);
158 void
159 mala_engine_clear_negated (MalaEngine self);
161 void
162 mala_engine_dumpprogram (MalaEngine self, FILE* stream, const char * prefix, const char * suffix);
164 void
165 mala_engine_dumpargs (MalaEngine self, FILE* stream, const char * prefix, const char * suffix);
167 MalaEngine
168 mala_engine_run (MalaEngine self);
170 MalaEngine
171 mala_engine_step (MalaEngine);
174 mala_engine_eval (MalaEngine self, MalaStringListNode_ref pptr);
176 void
177 mala_engine_command_done (MalaEngine eng, MalaStringListNode_ref pptr, int args);
181 //int
182 //mala_engine_expansions (MalaEngine self, MalaStringListNode_ref pptr);
186 mala_engine_string_istrue (MalaEngine self, MalaString str);
189 mala_engine_check_expansionflag (MalaEngine self, int flag);
193 mala_engine_ppexpand (MalaEngine self, MalaStringList list, MalaStringListNode_ref pptr);
196 mala_engine_literal_expansion (MalaEngine self,
197 MalaStringList list,
198 MalaStringListNode_ref pptr);
201 mala_engine_backquote_expansion (MalaEngine self,
202 MalaStringList list,
203 MalaStringListNode_ref pptr);
206 mala_engine_numsplit_expansion (MalaEngine self,
207 MalaStringList list,
208 MalaStringListNode_ref pptr);
211 mala_engine_exclam_expansion (MalaEngine self,
212 MalaStringList list,
213 MalaStringListNode_ref pptr);
216 mala_engine_no_expansion (MalaEngine self,
217 MalaStringList list,
218 MalaStringListNode_ref pptr);
221 mala_engine_assign_expansion (MalaEngine self,
222 MalaStringList list,
223 MalaStringListNode_ref pptr);
226 mala_engine_envvar_expansion (MalaEngine self,
227 MalaStringList list,
228 MalaStringListNode_ref pptr);
231 mala_engine_char_expansion (MalaEngine self,
232 MalaStringList list,
233 MalaStringListNode_ref pptr);
236 mala_engine_underscore_expansion (MalaEngine self,
237 MalaStringList list,
238 MalaStringListNode_ref pptr);
240 int mala_engine_setenv_expansion (MalaEngine self,
241 MalaStringList list,
242 MalaStringListNode_ref pptr);
244 int mala_engine_bracket_expansion (MalaEngine self,
245 MalaStringList list,
246 MalaStringListNode_ref pptr);
248 int mala_engine_assign_contraction (MalaEngine self,
249 MalaStringList list,
250 MalaStringListNode_ref pptr);
253 mala_engine_add_action_cstr (MalaEngine self, const char* cname, void* data,
254 MalaParserFunc parser, MalaDataFactory factory,
255 MalaAction parent);
258 mala_engine_add_action (MalaEngine self, MalaString name, void* data,
259 MalaParserFunc parser, MalaDataFactory factory,
260 MalaAction parent);
262 MalaStringListNode
263 mala_engine_arg_eval (MalaEngine self,
264 MalaStringListNode_ref pptr,
265 unsigned nth,
266 int times,
267 MalaDataFactory type);
270 mala_engine_arg_eval_fmt (MalaEngine self,
271 MalaStringListNode_ref pptr,
272 unsigned nth,
273 const char* fmt,
274 void * dest,
275 MalaPredicate pred,
276 void * constraint);
278 MalaString
279 mala_engine_arg_eval_string (MalaEngine self,
280 MalaStringListNode_ref pptr,
281 unsigned nth,
282 MalaPredicate pred,
283 void * constraint);
286 #if 0 /*TODO*/
288 MalaEngine
289 mala_engine_new_initfunc (int (*initfunc) (MalaEngine));
293 void
294 mala_engine_pushfront_program (MalaEngine self, int args, char ** argv);
298 mala_engine_erase_action (MalaEngine, const t_uchar * key);
301 mala_engine_eval (MalaEngine self, LList pptr);
304 mala_engine_deepeval (MalaEngine self, LList pptr);
308 mala_engine_exception (MalaEngine, LList begin, LList end, const char *);
310 MalaAction
311 mala_engine_action_new (MalaEngine, t_uchar** name, void** data,
312 MalaParserFunc parser, MalaDataDestructor destructor);
315 MalaAction
316 mala_engine_getaction (MalaEngine, const t_uchar * name);
318 MalaAction
319 mala_engine_getprevaction (MalaEngine, const t_uchar * name);
321 #endif /*TODO*/
327 #endif /*MALA_ENGINE_H*/
329 // Local Variables:
330 // mode: C
331 // c-file-style: "gnu"
332 // End:
333 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7
334 // end_of_file