--- parser3/src/classes/Attic/root.C 2001/03/12 17:00:46 1.25 +++ parser3/src/classes/Attic/root.C 2001/03/12 18:19:36 1.28 @@ -3,7 +3,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: root.C,v 1.25 2001/03/12 17:00:46 paf Exp $ + $Id: root.C,v 1.28 2001/03/12 18:19:36 paf Exp $ */ #include @@ -39,10 +39,8 @@ static void _untaint(Request& r, const S Temp_lang temp_lang(r, lang); Value *vbody=static_cast(params->get(1)); // forcing ^untaint[]{this param type} - if(!vbody->get_junction()) - R_THROW(0, 0, - &method_name, - "body must be junction"); + r.fail_if_junction_(false, *vbody, + method_name, "body must be junction"); r.write_pass_lang(r.process(*vbody)); } @@ -83,6 +81,53 @@ static void _process(Request& r, const S } } +static void _rem(Request& r, const String& method_name, Array *params) { + // forcing ^rem{this param type} + r.fail_if_junction_(false, *static_cast(params->get(0)), + method_name, "body must be junction"); +} + +static void _while(Request& r, const String& method_name, Array *params) { + Value& vcondition=*static_cast(params->get(0)); + // forcing ^while(this param type){} + r.fail_if_junction_(false, vcondition, + method_name, "condition must be junction"); + + Value& body=*static_cast(params->get(1)); + // forcing ^while(){this param type} + r.fail_if_junction_(false, body, + method_name, "body must be junction"); + + // while... + int endless_loop_count=0; + while(true) { + if(++endless_loop_count>=1973) // endless loop? + R_THROW(0, 0, + &method_name, + "endless loop detected"); + + bool condition= + r.process( + vcondition, + 0/*no name*/, + false/*don't intercept string*/).get_bool(); + if(!condition) // ...condition is true + break; + + // write processed body + r.write_pass_lang(r.process(body)); + } +} + +static void _use(Request& r, const String& method_name, Array *params) { + Value& vfile=*static_cast(params->get(0)); + // forcing ^rem{this param type} + r.fail_if_junction_(true, vfile, + method_name, "file name must not be junction"); + + char *file=vfile.as_string().cstr(); + r.use_file(r.absolute(file)); +} void initialize_root_class(Pool& pool, VClass& vclass) { // ^if(condition){code-when-true} @@ -94,4 +139,13 @@ void initialize_root_class(Pool& pool, V // ^process[code] vclass.add_native_method("process", _process, 1, 1); + + // ^rem{code} + vclass.add_native_method("rem", _rem, 1, 1); + + // ^while(condition){code} + vclass.add_native_method("while", _while, 2, 2); + + // ^use[file] + vclass.add_native_method("use", _use, 1, 1); }