Add elsif support (Martin Whitaker)
This commit is contained in:
parent
8dcd09797f
commit
29aa68302e
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#ifdef HAVE_CVS_IDENT
|
||||
#ident "$Id: lexor.lex,v 1.47 2007/05/25 18:21:39 steve Exp $"
|
||||
#ident "$Id: lexor.lex,v 1.48 2007/05/30 23:21:20 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "config.h"
|
||||
|
|
@ -118,11 +118,11 @@ static void ifdef_leave(void)
|
|||
if (strcmp(istack->path,cur->path) != 0) {
|
||||
fprintf(stderr, "%s:%u: warning: "
|
||||
"This `endif matches an ifdef in another file.\n",
|
||||
istack->path, istack->lineno);
|
||||
istack->path, istack->lineno+1);
|
||||
|
||||
fprintf(stderr, "%s:%u: : "
|
||||
"This is the odd matched `ifdef.\n",
|
||||
cur->path, cur->lineno);
|
||||
cur->path, cur->lineno+1);
|
||||
}
|
||||
|
||||
free(cur->path);
|
||||
|
|
@ -316,7 +316,24 @@ W [ \t\b\f]+
|
|||
yy_push_state(IFDEF_SUPR);
|
||||
}
|
||||
|
||||
<IFDEF_TRUE>`else { BEGIN(IFDEF_FALSE); }
|
||||
<IFDEF_TRUE>`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* {
|
||||
BEGIN(IFDEF_SUPR);
|
||||
}
|
||||
<IFDEF_FALSE>`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* {
|
||||
char*name = strchr(yytext, '`');
|
||||
assert(name);
|
||||
name += 6;
|
||||
name += strspn(name, " \t\b\f");
|
||||
|
||||
if (is_defined(name)) {
|
||||
BEGIN(IFDEF_TRUE);
|
||||
} else {
|
||||
BEGIN(IFDEF_FALSE);
|
||||
}
|
||||
}
|
||||
<IFDEF_SUPR>`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* { }
|
||||
|
||||
<IFDEF_TRUE>`else { BEGIN(IFDEF_SUPR); }
|
||||
<IFDEF_FALSE>`else { BEGIN(IFDEF_TRUE); }
|
||||
<IFDEF_SUPR>`else { }
|
||||
|
||||
|
|
@ -329,6 +346,42 @@ W [ \t\b\f]+
|
|||
|
||||
<IFDEF_FALSE,IFDEF_TRUE,IFDEF_SUPR>`endif { ifdef_leave(); yy_pop_state(); }
|
||||
|
||||
`ifdef {
|
||||
fprintf(stderr, "%s:%u: `ifdef without a macro name - ignored.\n",
|
||||
istack->path, istack->lineno+1);
|
||||
error_count += 1;
|
||||
}
|
||||
|
||||
`ifndef {
|
||||
fprintf(stderr, "%s:%u: `ifndef without a macro name - ignored.\n",
|
||||
istack->path, istack->lineno+1);
|
||||
error_count += 1;
|
||||
}
|
||||
|
||||
`elsif {
|
||||
fprintf(stderr, "%s:%u: `elsif without a macro name - ignored.\n",
|
||||
istack->path, istack->lineno+1);
|
||||
error_count += 1;
|
||||
}
|
||||
|
||||
`elsif{W}[a-zA-Z_][a-zA-Z0-9_$]* {
|
||||
fprintf(stderr, "%s:%u: `elsif without a matching `ifdef - ignored.\n",
|
||||
istack->path, istack->lineno+1);
|
||||
error_count += 1;
|
||||
}
|
||||
|
||||
`else {
|
||||
fprintf(stderr, "%s:%u: `else without a matching `ifdef - ignored.\n",
|
||||
istack->path, istack->lineno+1);
|
||||
error_count += 1;
|
||||
}
|
||||
|
||||
`endif {
|
||||
fprintf(stderr, "%s:%u: `endif without a matching `ifdef - ignored.\n",
|
||||
istack->path, istack->lineno+1);
|
||||
error_count += 1;
|
||||
}
|
||||
|
||||
/* This pattern notices macros and arranges for them to be replaced. */
|
||||
`[a-zA-Z][a-zA-Z0-9_$]* { def_match(); }
|
||||
|
||||
|
|
@ -766,7 +819,7 @@ static void lexor_done()
|
|||
ifdef_stack = cur->next;
|
||||
|
||||
fprintf(stderr, "%s:%u: error: This `ifdef lacks an `endif.\n",
|
||||
cur->path, cur->lineno);
|
||||
cur->path, cur->lineno+1);
|
||||
|
||||
free(cur->path);
|
||||
free(cur);
|
||||
|
|
|
|||
Loading…
Reference in New Issue