--- parser3/src/main/compile.y 2001/03/16 09:26:43 1.102 +++ parser3/src/main/compile.y 2001/03/24 16:29:09 1.112 @@ -1,20 +1,22 @@ -/* - Parser +/** @file + Parser: compiler(lexical parser and grammar). + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.102 2001/03/16 09:26:43 paf Exp $ + $Id: compile.y,v 1.112 2001/03/24 16:29:09 paf Exp $ */ -/* - TODO.parser4: - cache compiled code from request to request. to do that... - 1: make method definitions, @CLASS, @BASE, @USE instructions, +/** + @todo parser4: + - cache compiled code from request to request. to do that... + -#: make method definitions, @CLASS, @BASE, @USE instructions, which would be executed afterwards, and actions now performed at compile time would be delayed to run time. - 2: make cache expiration on time and on disk-change of class source - 3: in apache use subpools for compiled class storage - 4: in iis make up specialized Pool object for that + -#: make cache expiration on time and on disk-change of class source + -#: in apache use subpools for compiled class storage + -#: in iis make up specialized Pool object for that */ %{ @@ -22,12 +24,12 @@ #define YYPARSE_PARAM pc #define YYLEX_PARAM pc #define YYDEBUG 1 -#define YYERROR_VERBOSE +#define YYERROR_VERBOSE 1 #define yyerror(msg) real_yyerror((parse_control *)pc, msg) #define YYPRINT(file, type, value) yyprint(file, type, value) +#include "pa_config_includes.h" #include -#include #include #include "compile_tools.h" @@ -50,6 +52,7 @@ int yylex(YYSTYPE *lvalp, void *pc); #define POOL *PC->pool #undef NEW #define NEW new(POOL) +#ifndef DOXYGEN %} %pure_parser @@ -130,7 +133,7 @@ control_method: '@' STRING '\n' YYERROR; } if(command==CLASS_NAME) { - if(PC->cclass!=&PC->request->root_class) { // already changed from default? + if(PC->cclass!=&PC->request->ROOT) { // already changed from default? strcpy(PC->error, "class already have a name '"); strncat(PC->error, PC->cclass->name().cstr(), 100); strcat(PC->error, "'"); @@ -143,7 +146,7 @@ control_method: '@' STRING '\n' PC->cclass=NEW VClass(POOL); PC->cclass->set_name(*name); // defaulting base. may change with @BASE - PC->cclass->set_base(PC->request->root_class); + PC->cclass->set_base(PC->request->ROOT); // append to request's classes PC->request->classes().put(*name, PC->cclass); } else { @@ -152,20 +155,17 @@ control_method: '@' STRING '\n' } } else { if(command==USE_CONTROL_METHOD_NAME) { - for(int i=0; isize(); i+=2) { - String file(*SLA2S(strings_code, i)); - file.APPEND_CONST(".p"); - PC->request->use_file(file.cstr()); - } + for(int i=0; isize(); i+=2) + PC->request->use_file( + PC->request->absolute(*SLA2S(strings_code, i))); } else if(command==BASE_NAME) { - if(PC->cclass->base()!=&PC->request->root_class) { // already changed from default? + if(PC->cclass->base()!=&PC->request->ROOT) { // already changed from default? strcpy(PC->error, "class already have a base '"); strncat(PC->error, PC->cclass->base()->name().cstr(), 100); strcat(PC->error, "'"); YYERROR; } if(strings_code->size()==1*2) { - // TODO: преодолеть self и циклические base const String& base_name=*SLA2S(strings_code); VClass *base=static_cast( PC->request->classes().get(base_name)); @@ -174,6 +174,11 @@ control_method: '@' STRING '\n' strcat(PC->error, ": undefined class in @"BASE_NAME); YYERROR; } + // @CLASS == @BASE sanity check + if(PC->cclass==base) { + strcpy(PC->error, "@"CLASS_NAME" equals @"BASE_NAME); + YYERROR; + } PC->cclass->set_base(*base); } else { strcpy(PC->error, "@"BASE_NAME" must contain sole name"); @@ -377,7 +382,7 @@ store_code_param_part: ; store_expr_param_part: write_expr_value { $$=N(POOL); - PCA($$, $1); + PEA($$, $1); }; store_curly_param_part: maybe_codes { $$=N(POOL); @@ -520,6 +525,7 @@ empty_string_value: /* empty */ { $$=VL( empty: /* empty */ { $$=N(POOL) }; %% +#endif /* 000$111(2222)00 @@ -537,7 +543,7 @@ empty: /* empty */ { $$=N(POOL) }; 4:[^({]=pop */ -int yylex(YYSTYPE *lvalp, void *pc) { +static int yylex(YYSTYPE *lvalp, void *pc) { #define lexical_brackets_nestage PC->brackets_nestages[PC->sp] #define RC {result=c; goto break2; } @@ -584,6 +590,17 @@ int yylex(YYSTYPE *lvalp, void *pc) { // skip analysis = forced literal continue; } + if(c=='#' && PC->col==1) { + if(end!=begin) { + // append piece till # + PC->string->APPEND(begin, end-begin, PC->file, begin_line); + } + // reset piece 'begin' position & line + begin=PC->source; + begin_line=PC->line; + // fall into COMMENT lexical state [wait for \n] + push_LS(PC, LS_COMMENT); + } switch(PC->ls) { // USER'S = NOT OURS @@ -604,6 +621,18 @@ int yylex(YYSTYPE *lvalp, void *pc) { } break; + // #COMMENT + case LS_COMMENT: + if(c=='\n') { + // skip comment + begin=PC->source; + begin_line=PC->line; + + pop_LS(PC); + continue; + } + break; + // STRING IN EXPRESSION case LS_EXPRESSION_STRING: switch(c) { @@ -1010,19 +1039,12 @@ break2: return result; } -int real_yyerror(parse_control *pc, char *s) /* Called by yyparse on error */ - { - strncpy(pc->error, s, MAX_STRING); // TODO: перепроверить с треклятым последним байтом +static int real_yyerror(parse_control *pc, char *s) { // Called by yyparse on error + strncpy(pc->error, s, MAX_STRING); return 1; - } - -static void - yyprint( - FILE *file, - int type, - YYSTYPE value) - { - if(type==STRING) - fprintf(file, " \"%s\"", SLA2S(value)->cstr()); - } +} +static void yyprint(FILE *file, int type, YYSTYPE value) { + if(type==STRING) + fprintf(file, " \"%s\"", SLA2S(value)->cstr()); +}