2 std.c - MaLa standard parser module
4 Copyright (C) 2005, 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.
25 static mala_actioninit std_actions
[] =
28 MALA_PARSER("--", mala__parser, NULL, NULL, NULL),
29 MALA_PARSER_BRIEF("--", ""),
30 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
34 MALA_MACRO_PARSER("--BRIEF", "--BRIEF.%1"),
35 MALA_PARSER_BRIEF("--BRIEF", "gives a short note about a command"),
36 MALA_PARSER_HELP("--BRIEF", ("--HELP-ACTION", "TODO")),
38 MALA_MACRO_PARSER("--HELP", "--HELP.%1"),
39 MALA_PARSER_BRIEF("--HELP", "gives help about some command"),
40 MALA_PARSER_HELP("--HELP", ("--HELP-ACTION", "TODO")),
42 MALA_PARSER("--DEF", mala_macrodef_parser, NULL, NULL, NULL),
43 MALA_PARSER_BRIEF("--DEF", "defines a new macro"),
44 MALA_PARSER_HELP("--DEF", ("--HELP-ACTION", "TODO")),
46 MALA_PARSER("--BEGIN", mala_block_parser, NULL, NULL, NULL),
47 MALA_PARSER_BRIEF("--BEGIN", "starts a block of code"),
48 MALA_PARSER_HELP("--BEGIN", ("--HELP-ACTION", "TODO")),
51 MALA_PARSER("--NOT", mala_not_parser
, NULL
, NULL
, NULL
),
52 MALA_PARSER_BRIEF("--NOT", "negates logic"),
53 MALA_PARSER_HELP("--NOT", ("--HELP-ACTION", "TODO")),
55 MALA_PARSER("--LITERAL", mala_literal_parser
, NULL
, NULL
, NULL
),
56 MALA_PARSER_BRIEF("--LITERAL", "Treats the next word literally"),
57 MALA_PARSER_HELP("--LITERAL", ("--HELP-ACTION", "TODO")),
59 MALA_PARSER("--PRINTL", mala_printl_parser
, NULL
, NULL
, NULL
),
60 MALA_PARSER_BRIEF("--PRINTL", "prints a word to stdout"),
61 MALA_PARSER_HELP("--PRINTL", ("--HELP-ACTION", "blah")),
63 MALA_NULL_PARSER("--NULL"),
64 MALA_PARSER_BRIEF("--NULL","does nothing"),
65 MALA_PARSER_HELP("--NULL",("--HELP-ACTION","blah")),
67 MALA_TRUE_PARSER("--FLAG-NUMSPLIT-EXPANSION"),
68 MALA_PARSER_BRIEF("--FLAG-NUMSPLIT-EXPANSION", "TODO"),
69 MALA_PARSER_HELP("--FLAG-NUMSPLIT-EXPANSION", ("--HELP-ACTION", "TODO")),
71 MALA_TRUE_PARSER("--FLAG-LITERAL-EXPANSION"),
72 MALA_PARSER_BRIEF("--FLAG-LITERAL-EXPANSION", "words beginning with a single backquote will be preprocessed as '--LITERAL' 'theword'"),
73 MALA_PARSER_HELP("--FLAG-LITERAL-EXPANSION", ("--HELP-ACTION", "TODO")),
75 MALA_TRUE_PARSER("--FLAG-EXCLAM-EXPANSION"),
76 MALA_PARSER_BRIEF("--FLAG-EXCLAM-EXPANSION", "a single ! will be preprocessed as --NOT"),
77 MALA_PARSER_HELP("--FLAG-EXCLAM-EXPANSION", ("--HELP-ACTION", "TODO")),
79 MALA_TRUE_PARSER("--FLAG-NO-EXPANSION"),
80 MALA_PARSER_BRIEF("--", ""),
81 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
83 MALA_TRUE_PARSER("--FLAG-ASSIGN-EXPANSION"),
84 MALA_PARSER_BRIEF("--", ""),
85 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
87 MALA_TRUE_PARSER("--FLAG-ENVVAR-EXPANSION"),
88 MALA_PARSER_BRIEF("--", ""),
89 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
91 MALA_TRUE_PARSER("--FLAG-CHAR-EXPANSION"),
92 MALA_PARSER_BRIEF("--", ""),
93 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
95 MALA_TRUE_PARSER("--FLAG-UNDERSCORE-EXPANSION"),
96 MALA_PARSER_BRIEF("--", ""),
97 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
99 MALA_TRUE_PARSER("--FLAG-SETENV-EXPANSION"),
100 MALA_PARSER_BRIEF("--", ""),
101 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
103 MALA_TRUE_PARSER("--FLAG-BRACKET-EXPANSION"),
104 MALA_PARSER_BRIEF("--", ""),
105 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
107 MALA_TRUE_PARSER("--FLAG-ASSIGN-CONTRACTION"),
108 MALA_PARSER_BRIEF("--", ""),
109 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
111 MALA_SUBSTITUTE_PARSER("--BRIEF-ACTION","--PRINTL"),
112 MALA_PARSER_BRIEF("--", ""),
113 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
115 MALA_SUBSTITUTE_PARSER("--HELP-ACTION","--PRINTL"),
116 MALA_PARSER_BRIEF("--", ""),
117 MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")),
124 mala_module_std_init (MalaEngine self
)
126 return mala_engine_actions_register (self
, std_actions
);
131 mala_substitute_parser (MalaEngine eng
,
132 MalaStringListNode_ref pptr
,
135 if (!mala_stringlist_after_new (&eng
->program
, *pptr
, (MalaString
) data
))
138 mala_stringlist_elem_delete_fwd (&eng
->program
, pptr
);
144 mala_expand_parser (MalaEngine eng
,
145 MalaStringListNode_ref pptr
,
148 MalaStringListNode itr
;
149 MalaStringListNode end
;
151 end
= mala_stringlist_next (*pptr
);
153 for (itr
= mala_stringlist_tail ((MalaStringList
) data
);
154 !mala_stringlist_is_end ((MalaStringList
) data
, itr
);
155 mala_stringlist_rev (&itr
))
157 if (!mala_stringlist_after_new (&eng
->program
, *pptr
, itr
->string
))
161 mala_stringlist_elem_delete_fwd (&eng
->program
, pptr
);
166 /* remove already added things */
167 for (itr
= mala_stringlist_next (*pptr
);
169 mala_stringlist_elem_delete_fwd (&eng
->program
, &itr
));
176 mala_macro_parser (MalaEngine eng
,
177 MalaStringListNode_ref pptr
,
181 mala_stringlist_elem_delete_fwd (&eng
->program
, pptr
);
186 mala_null_parser (MalaEngine eng
,
187 MalaStringListNode_ref pptr
,
191 mala_stringlist_elem_delete_fwd (&eng
->program
, pptr
);
196 mala_printl_parser (MalaEngine eng
,
197 MalaStringListNode_ref pptr
,
202 mala_engine_try_eval_arg_n (eng
, pptr
, 1);
204 if (mala_stringlist_is_tail (&eng
->program
, *pptr
))
205 return mala_engine_exception (eng
, pptr
, *pptr
,
206 eng
->common_string
[MALA_STRING_ERROR_MISSING_ARGUMENT
]);
208 if (eng
->state
> MALA_EFAULT
)
211 printf("%s\n",mala_string_cstr (mala_stringlist_next (*pptr
)->string
));
213 mala_stringlist_elem_delete_fwd (&eng
->program
, pptr
);
214 mala_stringlist_elem_delete_fwd (&eng
->program
, pptr
);
219 mala_literal_parser (MalaEngine eng
,
220 MalaStringListNode_ref pptr
,
225 if (eng
->state
> MALA_EFAULT
)
228 if (mala_stringlist_is_tail (&eng
->program
, *pptr
))
229 return mala_engine_exception (eng
, pptr
, *pptr
,
230 eng
->common_string
[MALA_STRING_ERROR_MISSING_ARGUMENT
]);
232 mala_stringlist_elem_delete_fwd (&eng
->program
, pptr
);
237 mala_not_parser (MalaEngine eng
,
238 MalaStringListNode_ref pptr
,
243 if (eng
->state
> MALA_EFAULT
)
246 if (mala_stringlist_is_tail (&eng
->program
, *pptr
))
247 return mala_engine_exception (eng
, pptr
, *pptr
,
248 eng
->common_string
[MALA_STRING_ERROR_MISSING_ARGUMENT
]);
250 mala_stringlist_elem_delete_fwd (&eng
->program
, pptr
);
251 eng
->negated
= !eng
->negated
;
259 // c-file-style: "gnu"
261 // arch-tag: 687e1195-8aad-4425-983d-9767a25c3793