--- parser3/src/classes/op.C 2001/10/09 07:06:00 1.48 +++ parser3/src/classes/op.C 2001/10/10 12:52:13 1.52 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: op.C,v 1.48 2001/10/09 07:06:00 parser Exp $ + $Id: op.C,v 1.52 2001/10/10 12:52:13 parser Exp $ */ #include "classes.h" @@ -46,7 +46,7 @@ static void _if(Request& r, const String false/*don't intercept string*/).as_bool(); if(condition) r.write_pass_lang(r.process(params->as_junction(1, "'then' parameter must be code"))); - else if(params->size()==3) + else if(params->size()>2) r.write_pass_lang(r.process(params->as_junction(2, "'else' parameter must be code"))); } @@ -174,7 +174,7 @@ static void _for(Request& r, const Strin int from=params->as_int(1, "from must be int", r); int to=params->as_int(2, "to must be int", r); Value& body_code=params->as_junction(3, "body must be code"); - Value *delim_code=params->size()==3+1+1?¶ms->as_junction(3+1, "delim must be code"):0; + Value *delim_maybe_code=params->size()>4?¶ms->get(4):0; bool need_delim=false; VInt *vint=new(pool) VInt(pool, 0); @@ -188,10 +188,10 @@ static void _for(Request& r, const Strin r.self/*root*/->put_element(var_name, vint); Value& processed_body=r.process(body_code); - if(delim_code) { // delimiter set? + if(delim_maybe_code) { // delimiter set? const String *string=processed_body.get_string(); if(need_delim && string && string->size()) // need delim & iteration produced string? - r.write_pass_lang(r.process(*delim_code)); + r.write_pass_lang(r.process(*delim_maybe_code)); need_delim=true; } r.write_pass_lang(processed_body); @@ -204,7 +204,7 @@ static void _eval(Request& r, const Stri Value *result=r.process(expr, 0/*no name YET*/, true/*don't intercept string*/).as_expr_result(); - if(params->size()==2) { + if(params->size()>1) { Value& fmt=params->as_no_junction(1, "fmt must not be code"); Pool& pool=r.pool(); @@ -216,6 +216,15 @@ static void _eval(Request& r, const Stri r.write_no_lang(*result); } +static void _error(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + + const String& serror=params->as_string(0, "message must be string"); + PTHROW(0, 0, + &method_name, + "%s", serror.cstr()); +} + static void _connect(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -340,7 +349,7 @@ MOP::MOP(Pool& apool) : Methoded(apool), add_native_method("process", Method::CT_ANY, _process, 1, 1); // ^rem{code} - add_native_method("rem", Method::CT_ANY, _rem, 1, 1000); + add_native_method("rem", Method::CT_ANY, _rem, 1, 10000); // ^while(condition){code} add_native_method("while", Method::CT_ANY, _while, 2, 2); @@ -355,6 +364,9 @@ MOP::MOP(Pool& apool) : Methoded(apool), // ^eval(expr)[format] add_native_method("eval", Method::CT_ANY, _eval, 1, 2); + // ^error[msg] + add_native_method("error", Method::CT_ANY, _error, 1, 1); + // ^connect[protocol://user:pass@host[:port]/database]{code with ^sql-s} add_native_method("connect", Method::CT_ANY, _connect, 2, 2); @@ -365,7 +377,7 @@ MOP::MOP(Pool& apool) : Methoded(apool), add_native_method("switch", Method::CT_ANY, _switch, 2, 2); // ^case[value]{code} - add_native_method("case", Method::CT_ANY, _case, 2, 1000); + add_native_method("case", Method::CT_ANY, _case, 2, 10000); } // constructor & configurator