--- parser3/src/main/compile.C 2001/02/20 19:21:13 1.2 +++ parser3/src/main/compile.C 2020/12/15 17:10:33 1.87 @@ -1,37 +1,34 @@ -/* - $Id: compile.C,v 1.2 2001/02/20 19:21:13 paf Exp $ +/** @file + Parser: compiler part of request class. + + Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) */ -#include "pa_array.h" -#include "code.h" -#include "compile_tools.h" -#include "compile.h" +volatile const char * IDENT_COMPILE_C="$Id: compile.C,v 1.87 2020/12/15 17:10:33 moko Exp $"; -#include +#include "pa_request.h" +#include "compile_tools.h" extern int yydebug; -extern int yyparse (void *); +extern int yyparse (Parse_control *); + +ArrayClass& Request::compile(VStateless_class* aclass, const char* source, const String* main_alias, uint file_no, int line_no_offset) { + // prepare to parse + Parse_control pc(*this, aclass, source, main_alias, file_no, line_no_offset); + + // parse=compile! + //yydebug=1; + if(yyparse(&pc)) { // error? + pc.pos_prev_c(); + if(!pc.explicit_result) + if(pc.pos.col==0) // expecting something after EOL means they've expected it BEFORE + pc.pos_prev_c(); + + exception_trace.push(Trace(0, Operation::Origin::create(file_no, pc.pos.line, pc.pos.col))); + throw Exception("parser.compile", 0, "%s", pc.error); + } -Array *real_compile(COMPILE_PARAMS) { - if(!source) - return 0; - - yydebug=1; - struct parse_control pc; - /* input */ - pc.pool=pool; - pc.source=source; -#ifndef NO_STRING_ORIGIN - pc.file=file; - pc.line=1; -#endif - /* state to initial */ - pc.pending_state=0; - pc.string=string_create(pool); - pc.ls=LS_USER; - pc.sp=0; - /* parse! */ - int parse_error=yyparse(&pc); - /* result */ - return parse_error?0:static_cast(pc.result); + // result + return *pc.cclasses; }