From 2b094fba2cae71e496b03ee797da8a0c2087e65d Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Sun, 10 Jul 2005 20:58:03 +0000 Subject: [PATCH] foreach_word_parser git-archimport-id: chth@gmx.net--2004/mala-glibc--devel--0.2--patch-84 --- ChangeLog | 13 ++++ std/std.h | 6 ++ std/std_init.c | 192 +++++++++++++++++++++++++++++++++++------------------- std/std_parsers.c | 128 ++++++++++++++++++++++++++++++------ std/std_parsers.h | 12 +++- 5 files changed, 264 insertions(+), 87 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa1f942..6f6f0d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,19 @@ # arch-tag: automatic-ChangeLog--chth@gmx.net--2004/mala-glibc--devel--0.2 # +2005-07-10 20:58:03 GMT Christian Thaeter patch-84 + + Summary: + foreach_word_parser + Revision: + mala-glibc--devel--0.2--patch-84 + + + modified files: + ChangeLog std/std.h std/std_init.c std/std_parsers.c + std/std_parsers.h + + 2005-07-01 00:14:54 GMT Christian Thaeter patch-83 Summary: diff --git a/std/std.h b/std/std.h index dcf38c2..e9eec0a 100644 --- a/std/std.h +++ b/std/std.h @@ -26,6 +26,12 @@ int mala_module_std_init (MalaEngine self); +int +mala_module_std_types_init (MalaEngine self); + +int +mala_module_std_help_init (MalaEngine self); + #endif /* MALA_STD_H */ /* diff --git a/std/std_init.c b/std/std_init.c index 0721d2a..ae33b18 100644 --- a/std/std_init.c +++ b/std/std_init.c @@ -23,154 +23,211 @@ #include "mala.h" #include "std.h" +static mala_actioninit std_actions[] = { /* MALA_PARSER("--", mala__parser, NULL, NULL, NULL), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), + + + MALA_PARSER("--CHILDOF", mala__parser, NULL, NULL, NULL), + MALA_PARSER_BRIEF("--", ""), + MALA_PARSER_HELP("--", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), + + MALA_PARSER("--FOREACH-WORD", mala_foreach_word_parser, NULL, NULL, NULL), + MALA_PARSER_BRIEF("--", ""), + MALA_PARSER_HELP("--", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), */ - MALA_MACRO_PARSER("--BRIEF", ("--BRIEF_%-1")), - MALA_PARSER_BRIEF("--BRIEF", "gives a short note about a command"), - MALA_PARSER_HELP("--BRIEF", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--BRIEF", ("--TYPE_WORD","Name of a defined action")), - MALA_PARSER_RETURN("--BRIEF", ("--TYPE_VOID")), - - MALA_MACRO_PARSER("--HELP", ("--HELP_%-1")), - MALA_PARSER_BRIEF("--HELP", "gives help about some command"), - MALA_PARSER_HELP("--HELP", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + + MALA_PARSER("--FOREACH-WORD", mala_foreach_word_parser, NULL, NULL, NULL), + MALA_PARSER_BRIEF("--FOREACH-WORD", "applies an action to each word of a macro/expansion"), + MALA_PARSER_HELP("--FOREACH-WORD", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--FOREACH-WORD", ("DEFINED-ACTION", "MACRO")), + MALA_PARSER_SIGNATURE_USAGE("--FOREACH-WORD", ("Action to be applied", + "Macro consists of words on which the action" + " should be appied")), + MALA_PARSER_RESULT_TYPE("--FOREACH-WORD", ("SEQUENCE")), + MALA_PARSER_RESULT_USAGE("--FOREACH-WORD", ("Expansion which applies the Action to the macro")), MALA_PARSER("--DEF", mala_macrodef_parser, NULL, NULL, NULL), MALA_PARSER_BRIEF("--DEF", "defines a new macro"), - MALA_PARSER_HELP("--DEF", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--DEF", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--DEF", ("ACTION", "WORD-OR-BLOCK")), + MALA_PARSER_SIGNATURE_USAGE("--DEF", ("Word to be defined", + "Definition as word, or block with optional" + " %-expansions")), + MALA_PARSER_RESULT_TYPE("--DEF", ("VOID")), MALA_PARSER("--END", mala_end_parser, NULL, NULL, NULL), - MALA_PARSER_BRIEF("--END", "closes a begin block"), - MALA_PARSER_HELP("--END", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_BRIEF("--END", "closes a block"), + MALA_PARSER_HELP("--END", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--END", ("VOID")), + MALA_PARSER_RESULT_TYPE("--END", ("ERROR")), + MALA_PARSER_RESULT_USAGE("--END", ("an --END without a matching --BEGIN raises an error")), MALA_PARSER("--EXCEPTION", mala_exception_parser, NULL, NULL, NULL), MALA_PARSER_BRIEF("--EXCEPTION", "defines a new macro"), - MALA_PARSER_HELP("--EXCEPTION", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--EXCEPTION", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), MALA_PARSER("--DEL", mala_macrodelete_parser, NULL, NULL, NULL), MALA_PARSER_BRIEF("--DEL", "delete a macro"), - MALA_PARSER_HELP("--DEL", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--DEL", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), MALA_PARSER("--BEGIN", mala_begin_parser, NULL, NULL, NULL), MALA_PARSER_BRIEF("--BEGIN", "starts a block of code"), - MALA_PARSER_HELP("--BEGIN", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--BEGIN", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--BEGIN", ("WORDS","END")), + MALA_PARSER_RESULT_TYPE("--BEGIN", ("BLOCK")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), MALA_PARSER("--NOT", mala_not_parser, NULL, NULL, NULL), MALA_PARSER_BRIEF("--NOT", "negates logic"), - MALA_PARSER_HELP("--NOT", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--NOT", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), MALA_PARSER("--LITERAL", mala_literal_parser, NULL, NULL, NULL), MALA_PARSER_BRIEF("--LITERAL", "Treats the next word literally"), - MALA_PARSER_HELP("--LITERAL", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--LITERAL", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), MALA_SUBSTITUTE_PARSER("--DEFAULT-PARSER","--LITERAL"), MALA_PARSER_BRIEF("--DEFAULT-PARSER", "is used for any word which has no associated action"), - MALA_PARSER_HELP("--DEFAULT-PARSER", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--DEFAULT-PARSER", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), MALA_PARSER("--PRINTL", mala_printl_parser, NULL, NULL, NULL), - MALA_PARSER_BRIEF("--PRINTL", "prints a word to stdout"), - MALA_PARSER_HELP("--PRINTL", ("--HELP-ACTION", "blah")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_BRIEF("--PRINTL", "prints to stdout"), + MALA_PARSER_HELP("--PRINTL", ("TODO")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), + MALA_PARSER_SIGNATURE_TYPE("--PRINTL", ("WORD-OR-BLOCK")), + MALA_PARSER_RESULT_TYPE("--PRINTL", ("VOID")), + + MALA_PARSER("--PRINT", mala_print_parser, NULL, NULL, NULL), + MALA_PARSER_BRIEF("--PRINT", "prints to stdout"), + MALA_PARSER_HELP("--PRINT", ("TODO")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), + MALA_PARSER_SIGNATURE_TYPE("--PRINT", ("WORD-OR-BLOCK")), + MALA_PARSER_RESULT_TYPE("--PRINT", ("VOID")), MALA_NULL_PARSER("--NULL"), MALA_PARSER_BRIEF("--NULL","does nothing"), MALA_PARSER_HELP("--NULL",("--HELP-ACTION","blah")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), MALA_TRUE_PARSER("--FLAG-NUMSPLIT-EXPANSION"), MALA_PARSER_BRIEF("--FLAG-NUMSPLIT-EXPANSION", "TODO"), - MALA_PARSER_HELP("--FLAG-NUMSPLIT-EXPANSION", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--FLAG-NUMSPLIT-EXPANSION", ("TODO")), MALA_TRUE_PARSER("--FLAG-LITERAL-EXPANSION"), MALA_PARSER_BRIEF("--FLAG-LITERAL-EXPANSION", "words beginning with a single backquote will be " "preprocessed as '--LITERAL' 'theword'"), - MALA_PARSER_HELP("--FLAG-LITERAL-EXPANSION", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--FLAG-LITERAL-EXPANSION", ("TODO")), MALA_TRUE_PARSER("--FLAG-EXCLAM-EXPANSION"), MALA_PARSER_BRIEF("--FLAG-EXCLAM-EXPANSION", "a single ! will be preprocessed as --NOT"), - MALA_PARSER_HELP("--FLAG-EXCLAM-EXPANSION", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--FLAG-EXCLAM-EXPANSION", ("TODO")), MALA_TRUE_PARSER("--FLAG-NO-EXPANSION"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--", ("TODO")), MALA_TRUE_PARSER("--FLAG-ASSIGN-EXPANSION"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--", ("TODO")), MALA_TRUE_PARSER("--FLAG-ENVVAR-EXPANSION"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--", ("TODO")), MALA_TRUE_PARSER("--FLAG-CHAR-EXPANSION"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--", ("TODO")), MALA_TRUE_PARSER("--FLAG-UNDERSCORE-EXPANSION"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--", ("TODO")), MALA_TRUE_PARSER("--FLAG-SETENV-EXPANSION"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--", ("TODO")), MALA_TRUE_PARSER("--FLAG-BRACKET-EXPANSION"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--", ("TODO")), MALA_TRUE_PARSER("--FLAG-ASSIGN-CONTRACTION"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), + MALA_PARSER_HELP("--", ("TODO")), MALA_SUBSTITUTE_PARSER("--BRIEF-ACTION","--PRINTL"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), MALA_SUBSTITUTE_PARSER("--HELP-ACTION","--PRINTL"), MALA_PARSER_BRIEF("--", ""), - MALA_PARSER_HELP("--", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), // TODO to strings module MALA_MACRO_PARSER("--CAT",("%1%2")), MALA_PARSER_BRIEF("--CAT", "concatenates two words"), - MALA_PARSER_HELP("--CAT", ("--HELP-ACTION", "TODO")), - MALA_PARSER_SIGNATURE("--", ("")), - MALA_PARSER_RETURN("--", ("")), + MALA_PARSER_HELP("--CAT", ("TODO")), + MALA_PARSER_SIGNATURE_TYPE("--", ("")), + MALA_PARSER_SIGNATURE_USAGE("--", ("")), + MALA_PARSER_RESULT_TYPE("--", ("")), + MALA_PARSER_RESULT_USAGE("--", ("")), + + // TODO remove this + MALA_EXPAND_PARSER("TESTLIST",("TEST","LIST")), + MALA_ACTIONS_END }; @@ -179,7 +236,10 @@ mala_actioninit std_actions[] = int mala_module_std_init (MalaEngine self) { - return mala_engine_actions_register (self, std_actions); + mala_module_std_types_init (self); + mala_module_std_help_init (self); + mala_engine_actions_register (self, std_actions); + return self->state; } diff --git a/std/std_parsers.c b/std/std_parsers.c index 4996338..2ef5b46 100644 --- a/std/std_parsers.c +++ b/std/std_parsers.c @@ -84,7 +84,7 @@ mala_macro_parser (MalaEngine eng, void * data) { MalaStringListNode itr; - MalaStringListNode last; + MalaStringListNode last = NULL; MalaStringList list; const char* c; int i; @@ -92,7 +92,7 @@ mala_macro_parser (MalaEngine eng, int argt[10] = {0}; char *p; MalaString args[10]; - MalaString str; + MalaString str = NULL; // scan how much args are needed @@ -103,17 +103,9 @@ mala_macro_parser (MalaEngine eng, for (i = 1; i <= max_arg; ++i) { - //MalaStringListNode n; - if (argt[i-1] == 1) - { - if (!(last = mala_engine_eval_arg_n (eng, pptr, i)) || eng->state > MALA_EFAULT) - return eng->state; - } - else - { - if (!(last = mala_engine_get_arg_n (eng, pptr, i)) || eng->state > MALA_EFAULT) - return eng->state; - } + if (!(last = mala_engine_arg_eval (eng, pptr, i, argt[i] == 1 ? -1 : 0, NULL)) + || eng->state > MALA_EFAULT) + return eng->state; args[i] = last->string; } @@ -244,7 +236,7 @@ mala_printl_parser (MalaEngine eng, { (void) data; - mala_engine_eval_arg_n (eng, pptr, 1); + mala_engine_arg_eval (eng, pptr, 1, -1, NULL); if (mala_stringlist_is_tail (&eng->program, *pptr)) return mala_engine_exception (eng, pptr, *pptr, @@ -253,12 +245,39 @@ mala_printl_parser (MalaEngine eng, if (eng->state > MALA_EFAULT) return eng->state; + // TODO print blocks ? + printf("%s\n",mala_string_cstr (mala_stringlist_next (*pptr)->string)); mala_stringlist_elem_delete_fwd (&eng->program, pptr); mala_stringlist_elem_delete_fwd (&eng->program, pptr); return MALA_SUCCESS; } +int + +mala_print_parser (MalaEngine eng, + MalaStringListNode_ref pptr, + void * data) +{ + (void) data; + + mala_engine_arg_eval (eng, pptr, 1, -1, NULL); + + if (mala_stringlist_is_tail (&eng->program, *pptr)) + return mala_engine_exception (eng, pptr, *pptr, + eng->common_string[MALA_STRING_ERROR_MISSING_ARGUMENT]); + + if (eng->state > MALA_EFAULT) + return eng->state; + + // TODO print blocks ? + + printf("%s",mala_string_cstr (mala_stringlist_next (*pptr)->string)); + + mala_stringlist_elem_delete_fwd (&eng->program, pptr); + mala_stringlist_elem_delete_fwd (&eng->program, pptr); + return MALA_SUCCESS; +} int mala_literal_parser (MalaEngine eng, @@ -384,7 +403,7 @@ mala_block_parser (MalaEngine eng, mala_actiondesc_pop_delete (mala_string_user_get ((*pptr)->string)); - //mala_stringlist_elem_delete_fwd (&eng->program, pptr); + mala_stringlist_elem_delete_fwd (&eng->program, pptr); return MALA_SUCCESS; } @@ -398,7 +417,7 @@ mala_macrodelete_parser (MalaEngine eng, if (eng->state > MALA_EFAULT) return eng->state; - mala_engine_eval_arg_n (eng, pptr, 1); + mala_engine_arg_eval (eng, pptr, 1, -1, NULL); if (mala_stringlist_is_tail (&eng->program, *pptr)) return mala_engine_exception (eng, pptr, *pptr, @@ -420,7 +439,7 @@ mala_exception_parser (MalaEngine eng, (void) data; - mala_engine_eval_arg_n (eng, pptr, 1); + mala_engine_arg_eval (eng, pptr, 1, -1, NULL); if (mala_stringlist_is_tail (&eng->program, *pptr)) return mala_engine_exception (eng, pptr, *pptr, @@ -531,9 +550,9 @@ mala_macrodef_parser (MalaEngine eng, // evaluate both args - if (!mala_engine_eval_arg_n (eng, pptr, 1)) + if (!mala_engine_arg_eval (eng, pptr, 1, -1, NULL)) return eng->state; - if (!mala_engine_eval_arg_n (eng, pptr, 2)) + if (!mala_engine_arg_eval (eng, pptr, 2, -1, NULL)) return eng->state; // test if 2 arguments left and assign them to arg[], else error @@ -648,6 +667,77 @@ mala_macrodef_parser (MalaEngine eng, return MALA_SUCCESS; } +int +mala_foreach_word_parser (MalaEngine eng, + MalaStringListNode_ref pptr, + void * data) +{ + MalaAction act; + MalaStringListNode first; + MalaStringListNode second; + MalaStringListNode last; + MalaStringListNode itr; + (void) data; + + first = mala_engine_arg_eval (eng, pptr, 1, -1, NULL); + if (!first) + return eng->state; + act = mala_actiondesc_top ((MalaActionDesc) mala_string_user_get (first->string)); + // TODO allow blocks as first arg (define macro and delete it at later) + if (act && act->parser == mala_block_parser) + return mala_engine_exception (eng, pptr, first, + eng->common_string[MALA_STRING_ERROR_BLOCK_NOT_ALLOWED]); + + second = mala_engine_arg_eval (eng, pptr, 2, -1, (MalaDataFactory) mala_stringlist_factory); + if (!second) + return eng->state; + + last = mala_stringlist_next (second); + + act = mala_actiondesc_top ((MalaActionDesc) mala_string_user_get (second->string)); + + // expand second + if (eng->state != MALA_LITERAL) + for (itr = mala_stringlist_tail ((MalaStringList) act->data); + !mala_stringlist_is_end ((MalaStringList) act->data, itr); + mala_stringlist_rev (&itr)) + { + if (!mala_stringlist_after_new (&eng->program, second, itr->string)) + goto ealloc_node; + if (!mala_stringlist_after_new (&eng->program, second, first->string)) + goto ealloc_node; + } + else + { + if (!mala_stringlist_after_new (&eng->program, second, second->string)) + goto ealloc_node; + if (!mala_stringlist_after_new (&eng->program, second, first->string)) + goto ealloc_node; + } + + + // was a block? delete it + if (act && act->parser == mala_block_parser) + mala_actiondesc_pop_delete (mala_string_user_get (second->string)); + + mala_stringlist_elem_delete_fwd (&eng->program, pptr); + mala_stringlist_elem_delete_fwd (&eng->program, pptr); + mala_stringlist_elem_delete_fwd (&eng->program, pptr); + + return MALA_SUCCESS; + ealloc_node: + for (itr = mala_stringlist_next (second); + itr != last; + mala_stringlist_fwd (&itr)) + { + mala_stringlist_elem_delete (&eng->program, itr); + } + + return MALA_EALLOC; // TODO exception instead (needs pools, no allocation possible further) +} + + + /* realloc a string to at least needed size diff --git a/std/std_parsers.h b/std/std_parsers.h index 6e5123f..764b267 100644 --- a/std/std_parsers.h +++ b/std/std_parsers.h @@ -20,14 +20,17 @@ #ifndef MALA_STD_PARSERS_H #define MALA_STD_PARSERS_H -extern mala_actioninit std_actions[]; - int mala_null_parser (MalaEngine eng, MalaStringListNode_ref pptr, void * data); int +mala_foreach_word_parser (MalaEngine eng, + MalaStringListNode_ref pptr, + void * data); + +int mala_substitute_parser (MalaEngine eng, MalaStringListNode_ref pptr, void * data); @@ -48,6 +51,11 @@ mala_printl_parser (MalaEngine eng, void * data); int +mala_print_parser (MalaEngine eng, + MalaStringListNode_ref pptr, + void * data); + +int mala_literal_parser (MalaEngine eng, MalaStringListNode_ref pptr, void * data); -- 2.11.4.GIT