aboutsummaryrefslogtreecommitdiff
path: root/tool/lemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'tool/lemon.c')
-rw-r--r--tool/lemon.c50
1 files changed, 40 insertions, 10 deletions
diff --git a/tool/lemon.c b/tool/lemon.c
index 40e4e2894..97e5fab44 100644
--- a/tool/lemon.c
+++ b/tool/lemon.c
@@ -2638,8 +2638,10 @@ static void parseonetoken(struct pstate *psp)
}
nOld = lemonStrlen(zOld);
n = nOld + nNew + 20;
- addLineMacro = !psp->gp->nolinenosflag && psp->insertLineMacro &&
- (psp->decllinenoslot==0 || psp->decllinenoslot[0]!=0);
+ addLineMacro = !psp->gp->nolinenosflag
+ && psp->insertLineMacro
+ && psp->tokenlineno>1
+ && (psp->decllinenoslot==0 || psp->decllinenoslot[0]!=0);
if( addLineMacro ){
for(z=psp->filename, nBack=0; *z; z++){
if( *z=='\\' ) nBack++;
@@ -3617,6 +3619,16 @@ PRIVATE void tplt_xfer(char *name, FILE *in, FILE *out, int *lineno)
}
}
+/* Skip forward past the header of the template file to the first "%%"
+*/
+PRIVATE void tplt_skip_header(FILE *in, int *lineno)
+{
+ char line[LINESIZE];
+ while( fgets(line,LINESIZE,in) && (line[0]!='%' || line[1]!='%') ){
+ (*lineno)++;
+ }
+}
+
/* The next function finds the template file and opens it, returning
** a pointer to the opened file. */
PRIVATE FILE *tplt_open(struct lemon *lemp)
@@ -4287,6 +4299,7 @@ void ReportTable(
int mnTknOfst, mxTknOfst;
int mnNtOfst, mxNtOfst;
struct axset *ax;
+ char *prefix;
lemp->minShiftReduce = lemp->nstate;
lemp->errAction = lemp->minShiftReduce + lemp->nrule;
@@ -4375,7 +4388,22 @@ void ReportTable(
fprintf(sql, "COMMIT;\n");
}
lineno = 1;
- tplt_xfer(lemp->name,in,out,&lineno);
+
+ /* The first %include directive begins with a C-language comment,
+ ** then skip over the header comment of the template file
+ */
+ if( lemp->include==0 ) lemp->include = "";
+ for(i=0; ISSPACE(lemp->include[i]); i++){
+ if( lemp->include[i]=='\n' ){
+ lemp->include += i+1;
+ i = -1;
+ }
+ }
+ if( lemp->include[0]=='/' ){
+ tplt_skip_header(in,&lineno);
+ }else{
+ tplt_xfer(lemp->name,in,out,&lineno);
+ }
/* Generate the include code, if any */
tplt_print(out,lemp,lemp->include,&lineno);
@@ -4387,17 +4415,19 @@ void ReportTable(
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate #defines for all tokens */
+ if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
+ else prefix = "";
if( mhflag ){
const char *prefix;
fprintf(out,"#if INTERFACE\n"); lineno++;
- if( lemp->tokenprefix ) prefix = lemp->tokenprefix;
- else prefix = "";
- for(i=1; i<lemp->nterminal; i++){
- fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
- lineno++;
- }
- fprintf(out,"#endif\n"); lineno++;
+ }else{
+ fprintf(out,"#ifndef %s%s\n", prefix, lemp->symbols[1]->name);
+ }
+ for(i=1; i<lemp->nterminal; i++){
+ fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
+ lineno++;
}
+ fprintf(out,"#endif\n"); lineno++;
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate the defines */