mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-27 20:41:58 +03:00
Added option (-l) to lemon parser to have it skip printing line numbers (#line ... ). (CVS 6008)
FossilOrigin-Name: ccb9393a7a10f0970419b860af293b0bdad7f894
This commit is contained in:
40
tool/lemon.c
40
tool/lemon.c
@ -271,6 +271,7 @@ struct lemon {
|
||||
int tablesize; /* Size of the parse tables */
|
||||
int basisflag; /* Print only basis configurations */
|
||||
int has_fallback; /* True if any %fallback is seen in the grammar */
|
||||
int nolinenosflag; /* True if #line statements should not be printed */
|
||||
char *argv0; /* Name of the program */
|
||||
};
|
||||
|
||||
@ -1401,12 +1402,14 @@ char **argv;
|
||||
static int quiet = 0;
|
||||
static int statistics = 0;
|
||||
static int mhflag = 0;
|
||||
static int nolinenosflag = 0;
|
||||
static struct s_options options[] = {
|
||||
{OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
|
||||
{OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
|
||||
{OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."},
|
||||
{OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
|
||||
{OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file"},
|
||||
{OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file."},
|
||||
{OPT_FLAG, "l", (char*)&nolinenosflag, "Do not print #line statements."},
|
||||
{OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."},
|
||||
{OPT_FLAG, "s", (char*)&statistics,
|
||||
"Print parser stats to standard output."},
|
||||
@ -1435,6 +1438,7 @@ char **argv;
|
||||
lem.argv0 = argv[0];
|
||||
lem.filename = OptArg(0);
|
||||
lem.basisflag = basisflag;
|
||||
lem.nolinenosflag = nolinenosflag;
|
||||
Symbol_new("$");
|
||||
lem.errsym = Symbol_new("error");
|
||||
lem.errsym->useCnt = 0;
|
||||
@ -2340,7 +2344,7 @@ to follow the previous rule.");
|
||||
}
|
||||
nOld = lemonStrlen(zOld);
|
||||
n = nOld + nNew + 20;
|
||||
addLineMacro = psp->insertLineMacro &&
|
||||
addLineMacro = !psp->gp->nolinenosflag && psp->insertLineMacro &&
|
||||
(psp->decllinenoslot==0 || psp->decllinenoslot[0]!=0);
|
||||
if( addLineMacro ){
|
||||
for(z=psp->filename, nBack=0; *z; z++){
|
||||
@ -3119,18 +3123,18 @@ char *str;
|
||||
int *lineno;
|
||||
{
|
||||
if( str==0 ) return;
|
||||
(*lineno)++;
|
||||
while( *str ){
|
||||
if( *str=='\n' ) (*lineno)++;
|
||||
putc(*str,out);
|
||||
if( *str=='\n' ) (*lineno)++;
|
||||
str++;
|
||||
}
|
||||
if( str[-1]!='\n' ){
|
||||
putc('\n',out);
|
||||
(*lineno)++;
|
||||
}
|
||||
tplt_linedir(out,*lineno+2,lemp->outname);
|
||||
(*lineno)+=2;
|
||||
if (!lemp->nolinenosflag) {
|
||||
(*lineno)++; tplt_linedir(out,*lineno,lemp->outname);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3146,7 +3150,6 @@ int *lineno;
|
||||
{
|
||||
char *cp = 0;
|
||||
|
||||
int linecnt = 0;
|
||||
if( sp->type==TERMINAL ){
|
||||
cp = lemp->tokendest;
|
||||
if( cp==0 ) return;
|
||||
@ -3154,7 +3157,7 @@ int *lineno;
|
||||
}else if( sp->destructor ){
|
||||
cp = sp->destructor;
|
||||
fprintf(out,"{\n"); (*lineno)++;
|
||||
tplt_linedir(out,sp->destLineno,lemp->filename); (*lineno)++;
|
||||
if (!lemp->nolinenosflag) { (*lineno)++; tplt_linedir(out,sp->destLineno,lemp->filename); }
|
||||
}else if( lemp->vardest ){
|
||||
cp = lemp->vardest;
|
||||
if( cp==0 ) return;
|
||||
@ -3168,13 +3171,14 @@ int *lineno;
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if( *cp=='\n' ) linecnt++;
|
||||
if( *cp=='\n' ) (*lineno)++;
|
||||
fputc(*cp,out);
|
||||
}
|
||||
(*lineno) += 3 + linecnt;
|
||||
fprintf(out,"\n");
|
||||
tplt_linedir(out,*lineno,lemp->outname);
|
||||
fprintf(out,"}\n");
|
||||
fprintf(out,"\n"); (*lineno)++;
|
||||
if (!lemp->nolinenosflag) {
|
||||
(*lineno)++; tplt_linedir(out,*lineno,lemp->outname);
|
||||
}
|
||||
fprintf(out,"}\n"); (*lineno)++;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3346,18 +3350,16 @@ struct lemon *lemp;
|
||||
int *lineno;
|
||||
{
|
||||
char *cp;
|
||||
int linecnt = 0;
|
||||
|
||||
/* Generate code to do the reduce action */
|
||||
if( rp->code ){
|
||||
tplt_linedir(out,rp->line,lemp->filename);
|
||||
if (!lemp->nolinenosflag) { (*lineno)++; tplt_linedir(out,rp->line,lemp->filename); }
|
||||
fprintf(out,"{%s",rp->code);
|
||||
for(cp=rp->code; *cp; cp++){
|
||||
if( *cp=='\n' ) linecnt++;
|
||||
if( *cp=='\n' ) (*lineno)++;
|
||||
} /* End loop */
|
||||
(*lineno) += 3 + linecnt;
|
||||
fprintf(out,"}\n");
|
||||
tplt_linedir(out,*lineno,lemp->outname);
|
||||
fprintf(out,"}\n"); (*lineno)++;
|
||||
if (!lemp->nolinenosflag) { (*lineno)++; tplt_linedir(out,*lineno,lemp->outname); }
|
||||
} /* End if( rp->code ) */
|
||||
|
||||
return;
|
||||
|
Reference in New Issue
Block a user