diff --git a/guiapp/messagehandler.cpp b/guiapp/messagehandler.cpp index 70c4225..cb46ddd 100644 --- a/guiapp/messagehandler.cpp +++ b/guiapp/messagehandler.cpp @@ -210,7 +210,12 @@ bool MessageHandler::call_alias(QString alias, QStringList args) { } else if( alias == "quit" || alias == "q" ) { if( args.count() > 0 ) { irc->quit( args.join( " " ) ); } else { irc->quit(); } + } else if(alias == "echo") { + windows["status"]->echo(args.join(" ")); } else { + //TODO: Script error! Unknown alias.... WHEREVER WE ARE IN WHICHEVER SCRIPT IT IS THAT WE'RE RUNNING!! + //BUT WAIT!!!!! NO!!!! The script manager is the only thing handling that!!! + //IN FACT, ALL THE ABOVE ALIASES BELONG IN THE IRC CLIENT LIBRARY, REALLY! PERHAPS? return false; } return true; diff --git a/mirc/includes/parser.h b/mirc/includes/parser.h index e6f26ce..1175b61 100644 --- a/mirc/includes/parser.h +++ b/mirc/includes/parser.h @@ -41,7 +41,8 @@ typedef QMap mirc_aliases; enum mirc_engine_stage { PARSE, - EXECUTE + EXECUTE, + TERMINATED }; class mirc_script_engine : public QObject { @@ -50,6 +51,7 @@ private: MIRCScriptManager *manager; mirc_aliases::iterator current_alias; mirc_variables::iterator current_variable; + QStringList current_value; QStack stack; public: @@ -69,6 +71,7 @@ public: void declare_variable(char const* str, char const* end); void assign_variable(char const* str, char const* end); void fetch_variable(char const*, char const*); + void append_value(char const* str, char const *end); void append_expression(char const* str, char const *end); void clear_stack(char const*, char const*); }; @@ -84,8 +87,10 @@ struct mirc_script : public grammar { struct definition { rule script, space, + nospace, identifier, string, + value, expression, expression_group, parameters, @@ -109,6 +114,7 @@ struct mirc_script : public grammar { s_action v_def ( bind( &mirc_script_engine::declare_variable, self.actions, _1, _2 ) ); s_action v_assign ( bind( &mirc_script_engine::assign_variable, self.actions, _1, _2 ) ); s_action v_fetch ( bind( &mirc_script_engine::fetch_variable, self.actions, _1, _2 ) ); + s_action v_append ( bind( &mirc_script_engine::append_value, self.actions, _1, _2 ) ); s_action e_append ( bind( &mirc_script_engine::append_expression, self.actions, _1, _2 ) ); s_action s_code ( bind( &mirc_script_engine::store_code, self.actions, _1, _2 ) ); s_action c_stack ( bind( &mirc_script_engine::clear_stack, self.actions, _1, _2 ) ); @@ -124,17 +130,24 @@ struct mirc_script : public grammar { | str_p("$&") >> *blank_p >> eol_p ) ; + nospace + = +space >> str_p("$+") >> +space + ; identifier = alpha_p >> *alnum_p ; string - = ( variable[e_append][v_fetch] - | alias_function[e_append] - | (+(graph_p - ch_p(',') - ch_p('(') - ch_p(')')))[e_append] + = (+(graph_p - ch_p(',') - ch_p('(') - ch_p(')'))) + ; + value + = ( variable[v_append][v_fetch] + | alias_function[v_append] + | string[v_append] ) ; expression - = string >> *(*space >> string) + = (*nospace >> value)[e_append] + >> *(+space >> (+(*nospace >> value))[e_append]) ; expression_group = expression | expression_group diff --git a/mirc/src/parser.cpp b/mirc/src/parser.cpp index 5bdc07c..4d957b8 100644 --- a/mirc/src/parser.cpp +++ b/mirc/src/parser.cpp @@ -70,6 +70,13 @@ void mirc_script_engine::assign_variable(char const* str, char const* end) { void mirc_script_engine::fetch_variable(char const*, char const*) { if (stage != EXECUTE) return; + if (!current_value.isEmpty()) { + QString var = current_value.last(); + current_value.removeLast(); + var = (manager->hasVariable(var) ? manager->variable(var) : vars[var]); + current_value << var; + } +/* if (!stack.isEmpty()) { QStringList values = stack.pop(); if (!values.isEmpty()) { @@ -79,19 +86,24 @@ void mirc_script_engine::fetch_variable(char const*, char const*) { } stack.push(values); } +*/ +} +void mirc_script_engine::append_value(char const* str, char const *end) { + if (stage != EXECUTE) return; + + string s(str, end); + current_value << s.c_str(); } void mirc_script_engine::append_expression(char const* str, char const *end) { if (stage != EXECUTE) return; - + string s(str, end); QStringList list; - if (stack.isEmpty()) { - list << s.c_str(); - } else { - list = stack.pop(); - list << s.c_str(); - } + if (!stack.isEmpty()) list = stack.pop(); + //list << s.c_str(); + list << current_value.join(""); stack.push(list); + current_value.clear(); } void mirc_script_engine::clear_stack(char const*, char const*) { diff --git a/mirc/test.mrc b/mirc/test.mrc index 477ebe5..b913545 100644 --- a/mirc/test.mrc +++ b/mirc/test.mrc @@ -3,7 +3,8 @@ set name Correl %first = Correl %middle = Joseph %name = %first $& - %middle Roush + %middle $+ Roush $& + $+ ... how are you? echo Hello, %name! alias dostuff { ; Not very useful, but good for testing the parser!