mirror of
https://github.com/correl/mercenary.git
synced 2024-11-23 11:09:50 +00:00
Now supports the value concatenation operator "$+"
git-svn-id: file:///srv/svn/ircclient/trunk@7 a9804ffe-773b-11dd-bd7c-89c3ef1d2733
This commit is contained in:
parent
34b445fe87
commit
c720c5aa5e
4 changed files with 44 additions and 13 deletions
|
@ -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;
|
||||
|
|
|
@ -41,7 +41,8 @@ typedef QMap<QString, mirc_alias> 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<QStringList> 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<mirc_script> {
|
|||
struct definition {
|
||||
rule<ScannerT> script,
|
||||
space,
|
||||
nospace,
|
||||
identifier,
|
||||
string,
|
||||
value,
|
||||
expression,
|
||||
expression_group,
|
||||
parameters,
|
||||
|
@ -109,6 +114,7 @@ struct mirc_script : public grammar<mirc_script> {
|
|||
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<mirc_script> {
|
|||
| 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
|
||||
|
|
|
@ -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*) {
|
||||
|
|
|
@ -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!
|
||||
|
|
Loading…
Reference in a new issue