X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginsh%2Fginsh_parser.yy;h=6020efbcb4575233eba5c517771434d526339fb6;hb=5041748e650b3a2da73ae6128c83f88698d38dcf;hp=10383e8eb3fc81b05fa3f36d7c898fe6f9b01fef;hpb=e6b8c3caae6f9877f27b67522390290ae936a112;p=ginac.git diff --git a/ginsh/ginsh_parser.yy b/ginsh/ginsh_parser.yy index 10383e8e..6020efbc 100644 --- a/ginsh/ginsh_parser.yy +++ b/ginsh/ginsh_parser.yy @@ -375,6 +375,13 @@ static ex f_evalf2(const exprseq &e) return e[0].evalf(ex_to(e[1]).to_int()); } +static ex f_find(const exprseq &e) +{ + lst found; + e[0].find(e[1], found); + return found; +} + static ex f_inverse(const exprseq &e) { CHECK_ARG(0, matrix, inverse); @@ -387,6 +394,20 @@ static ex f_is(const exprseq &e) return (bool)ex_to(e[0]) ? ex(1) : ex(0); } +class apply_map_function : public map_function { + ex apply; +public: + apply_map_function(const ex & a) : apply(a) {} + virtual ~apply_map_function() {} + ex operator()(const ex & e) { return apply.subs(wild() == e, true); } +}; + +static ex f_map(const exprseq &e) +{ + apply_map_function fcn(e[1]); + return e[0].map(fcn); +} + static ex f_match(const exprseq &e) { lst repl_lst; @@ -510,6 +531,7 @@ static const fcn_init builtin_fcns[] = { {"evalf", fcn_desc(f_evalf2, 2)}, {"evalm", fcn_desc(f_evalm, 1)}, {"expand", fcn_desc(f_expand, 1)}, + {"find", fcn_desc(f_find, 2)}, {"gcd", fcn_desc(f_gcd, 2)}, {"has", fcn_desc(f_has, 2)}, {"inverse", fcn_desc(f_inverse, 1)}, @@ -518,6 +540,7 @@ static const fcn_init builtin_fcns[] = { {"lcoeff", fcn_desc(f_lcoeff, 2)}, {"ldegree", fcn_desc(f_ldegree, 2)}, {"lsolve", fcn_desc(f_lsolve, 2)}, + {"map", fcn_desc(f_map, 2)}, {"match", fcn_desc(f_match, 2)}, {"nops", fcn_desc(f_nops, 1)}, {"normal", fcn_desc(f_normal1, 1)}, @@ -714,7 +737,7 @@ static void print_help_topics(void) * Function name completion functions for readline */ -static char *fcn_generator(char *text, int state) +static char *fcn_generator(const char *text, int state) { static int len; // Length of word to complete static fcn_tab::const_iterator index; // Iterator to function being currently considered @@ -735,7 +758,7 @@ static char *fcn_generator(char *text, int state) return NULL; } -static char **fcn_completion(char *text, int start, int end) +static char **fcn_completion(const char *text, int start, int end) { if (rl_line_buffer[0] == '!') { // For shell commands, revert back to filename completion @@ -743,9 +766,9 @@ static char **fcn_completion(char *text, int start, int end) rl_basic_word_break_characters = orig_basic_word_break_characters; rl_completer_word_break_characters = rl_basic_word_break_characters; #if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2) - return completion_matches(text, (CPFunction *)filename_completion_function); + return completion_matches(const_cast(text), (CPFunction *)filename_completion_function); #else - return rl_completion_matches(text, (CPFunction *)rl_filename_completion_function); + return rl_completion_matches(text, rl_filename_completion_function); #endif } else { // Otherwise, complete function names @@ -753,9 +776,9 @@ static char **fcn_completion(char *text, int start, int end) rl_basic_word_break_characters = " \t\n\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~"; rl_completer_word_break_characters = rl_basic_word_break_characters; #if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2) - return completion_matches(text, (CPFunction *)fcn_generator); + return completion_matches(const_cast(text), (CPFunction *)fcn_generator); #else - return rl_completion_matches(text, (CPFunction *)fcn_generator); + return rl_completion_matches(text, fcn_generator); #endif } } @@ -798,7 +821,11 @@ int main(int argc, char **argv) // Init readline completer rl_readline_name = argv[0]; +#if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2) rl_attempted_completion_function = (CPPFunction *)fcn_completion; +#else + rl_attempted_completion_function = fcn_completion; +#endif orig_completion_append_character = rl_completion_append_character; orig_basic_word_break_characters = rl_basic_word_break_characters;