try and throw parsers
[mala.git] / engine / engine.h
blob5e68b67dca8029f1cefeb114af445f73cb329ff2
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 (except at end)
31 b) are fast accessible with their symbolic index
33 note that "--WORLD" must be the first one
36 #define MALA_COMMON_STRINGS \
37 { \
38 MALA_COMMON_STRING (WORLD, "--WORLD"), \
39 MALA_COMMON_STRING (COMMANDLINE, "--COMMANDLINE"), \
40 MALA_COMMON_STRING (PROGRAM, "--PROGRAM"), \
41 MALA_COMMON_STRING (ARGUMENTS, "--ARGUMENTS"), \
42 MALA_COMMON_STRING (FALSE, "--FALSE"), \
43 MALA_COMMON_STRING (TRUE, "--TRUE"), \
44 MALA_COMMON_STRING (EMPTY, ""), \
45 MALA_COMMON_STRING (ZERO, "0"), \
46 MALA_COMMON_STRING (PASS, "--PASS"), \
47 MALA_COMMON_STRING (EXCLAMATIONMARK, "!"), \
48 MALA_COMMON_STRING (ASSIGN, "="), \
49 MALA_COMMON_STRING (BACKQUOTE, "`"), \
50 MALA_COMMON_STRING (NOT, "--NOT"), \
51 MALA_COMMON_STRING (NO, "--NO"), \
52 MALA_COMMON_STRING (LITERAL, "--LITERAL"), \
53 MALA_COMMON_STRING (ENVSUBST, "--ENVSUBST"), \
54 MALA_COMMON_STRING (SETENV, "--SETENV"), \
55 MALA_COMMON_STRING (SECTION, "--SECTION"), \
56 MALA_COMMON_STRING (BEFORE_HERE, "--BEFORE-HERE"), \
57 MALA_COMMON_STRING (BEGIN, "--BEGIN"), \
58 MALA_COMMON_STRING (END, "--END"), \
59 MALA_COMMON_STRING (DEL, "--DEL"), \
60 MALA_COMMON_STRING (EVAL, "--EVAL"), \
61 MALA_COMMON_STRING (STOP, "--STOP"), \
62 MALA_COMMON_STRING (TRY, "--TRY"), \
63 MALA_COMMON_STRING (ERROR_MISSING_ARGUMENT, "--ERROR-MISSING-ARGUMENT"), \
64 MALA_COMMON_STRING (ERROR_MISSING_END, "--ERROR-MISSING-END"), \
65 MALA_COMMON_STRING (ERROR_END_WITHOUT_BEGIN, "--ERROR-END-WITHOUT-BEGIN"), \
66 MALA_COMMON_STRING (ERROR_MACRO_SYNTAX, "--ERROR-MACRO-SYNTAX"), \
67 MALA_COMMON_STRING (ERROR_NESTING_LIMIT_EXCEED, "--ERROR-NESTING-LIMIT-EXCEED"), \
68 MALA_COMMON_STRING (ERROR_ACTION_NOT_DEFINED, "--ERROR-ACTION-NOT-DEFINED"), \
69 MALA_COMMON_STRING (ERROR_NOT_A_PREDICATE, "--ERROR-NOT-A-PREDICATE"), \
70 MALA_COMMON_STRING (ERROR_WRONG_TYPE, "--ERROR-WRONG-TYPE"), \
71 MALA_COMMON_STRING (ERROR_OUT_OF_RANGE, "--ERROR-OUT-OF-RANGE"), \
72 MALA_COMMON_STRING (UNHANDLED_ERROR, "--UNHANDLED-ERROR"), \
73 MALA_COMMON_STRING (MAX, "") \
77 #define MALA_COMMON_STRING(E,s) MALA_STRING_##E
78 enum mala_common_strings_enum MALA_COMMON_STRINGS;
79 #undef MALA_COMMON_STRING
81 typedef enum mala_common_strings_enum mala_common_string;
83 const char * mala_engine_states [MALA_STATE_TABLE_SIZEOF+1];
85 //#ifdef MALA_PRIVATE
86 struct mala_engine_struct
89 * every tokenized word is collected in 'words'
90 * actions can be bound to these words through the strings user variable
92 acogc_root gcroot;
94 acogc_factory gcfactory_buckets;
95 acogc_factory gcfactory_strings;
96 acogc_factory gcfactory_stringbucketnodes;
97 acogc_factory gcfactory_stringlists;
98 acogc_factory gcfactory_actions;
99 acogc_factory gcfactory_programs;
101 MalaStringBucket words;
103 mala_trace engine_trace; // TODO
105 /* --BEGIN ... --END blocks are translated to --BLOCK-xxxxxxxx macros,
106 where xxxxxxxx is a monotonic incrementing counter, its value is stored here */
107 unsigned blockcnt;
109 mala_state state;
111 MalaString common_string[MALA_STRING_MAX];
116 * Mala engine
118 void
119 mala_engine_init (MalaEngine self);
121 MalaEngine
122 mala_engine_new ();
124 #if 0
125 MalaEngine
126 mala_engine_new_main (int (*initfunc) (MalaEngine),
127 int argc, char ** argv,
128 mala_actioninit * actions_init);
129 #endif
131 void
132 mala_engine_erase (MalaEngine self);
134 void
135 mala_engine_free (MalaEngine self);
137 mala_state
138 mala_engine_actions_register (MalaEngine, MalaActionInit);
141 void
142 mala_engine_action_new_cstr (MalaEngine self,
143 const char* name,
144 MalaParserFunc parser,
145 void *data,
146 acogc_alloc_type data_alloc,
147 MalaAction parent);
150 void
151 mala_engine_run_cstr (MalaEngine self,
152 const char* cmd,
153 MalaStringList_ref result);
155 mala_state
156 mala_engine_state_get (MalaEngine self);
158 const char *
159 mala_engine_state_str (MalaEngine self);
161 void
162 mala_engine_clearstate (MalaEngine self);
164 MalaString
165 mala_engine_tmpname (MalaEngine self, const char* templ);
167 static inline MalaAction
168 mala_engine_action_get_cstr (MalaEngine engine, const char * cname)
170 MalaString s = mala_stringbucket_find (engine->words, cname);
171 return s ? s->action : NULL;
174 #endif /*MALA_ENGINE_H*/
176 // Local Variables:
177 // mode: C
178 // c-file-style: "gnu"
179 // End:
180 // arch-tag: 47d718f6-e397-400c-93a6-bc71f475c0c7
181 // end_of_file