From 0c32f34cb7bb2a2b90b5eadfd7e08c5c60eff9af Mon Sep 17 00:00:00 2001 From: Josh Hursey Date: Mon, 1 Aug 2005 22:25:47 +0000 Subject: [PATCH] Let's clean up the block comment parsing to be a bit more lex-like. This commit was SVN r6695. --- opal/mca/base/mca_base_parse_paramfile_lex.l | 38 +++++-------------- orte/mca/rds/hostfile/rds_hostfile_lex.l | 39 +++++--------------- 2 files changed, 19 insertions(+), 58 deletions(-) diff --git a/opal/mca/base/mca_base_parse_paramfile_lex.l b/opal/mca/base/mca_base_parse_paramfile_lex.l index 9ffe9f4117..80f2cc6938 100644 --- a/opal/mca/base/mca_base_parse_paramfile_lex.l +++ b/opal/mca/base/mca_base_parse_paramfile_lex.l @@ -46,42 +46,22 @@ WHITE [\f\t\v ] CHAR [A-Za-z0-9_\-\.] %x VALUE +%x comment %% {WHITE}*\n { mca_base_yynewlines++; return MCA_BASE_PARSE_NEWLINE; } #.*\n { mca_base_yynewlines++; return MCA_BASE_PARSE_NEWLINE; } "//".*\n { mca_base_yynewlines++; return MCA_BASE_PARSE_NEWLINE; } -"/*" { - register int c; - for ( ; ; ) { - /* Eat up characters till we hit the - * end of file or * - */ - while ( (c = input()) != '*' && c != EOF){ - if(c == '\n') - mca_base_yynewlines++; - } - - /* If we reach a *, then look for the - * matching / - */ - if ( c == '*') { - while ( (c = input()) == '*' ) { - if(c == '\n') - mca_base_yynewlines++; - } - if ( c == '/' ) - break; /* End of Comment */ - } - else if ( c == EOF ) { - /* EOF in comment :( */ - break; - } - } - return MCA_BASE_PARSE_NEWLINE; - } +"/*" { BEGIN(comment); + return MCA_BASE_PARSE_NEWLINE; } +[^*\n]* ; /* Eat up non '*'s */ +"*"+[^*/\n]* ; /* Eat '*'s not followed by a '/' */ +\n { mca_base_yynewlines++; + return MCA_BASE_PARSE_NEWLINE; } +"*"+"/" { BEGIN(INITIAL); /* Done with Block Comment */ + return MCA_BASE_PARSE_NEWLINE; } {WHITE}*"="{WHITE}* { BEGIN(VALUE); return MCA_BASE_PARSE_EQUAL; } {WHITE}+ ; /* whitespace */ diff --git a/orte/mca/rds/hostfile/rds_hostfile_lex.l b/orte/mca/rds/hostfile/rds_hostfile_lex.l index eaaccc89fa..02d85b302c 100644 --- a/orte/mca/rds/hostfile/rds_hostfile_lex.l +++ b/orte/mca/rds/hostfile/rds_hostfile_lex.l @@ -39,6 +39,8 @@ bool orte_rds_hostfile_done = false; WHITE [\f\t\v ] +%x comment + %% {WHITE}*\n { orte_rds_hostfile_line++; @@ -47,36 +49,15 @@ WHITE [\f\t\v ] return ORTE_RDS_HOSTFILE_NEWLINE; } "//".*\n { orte_rds_hostfile_line++; return ORTE_RDS_HOSTFILE_NEWLINE; } -"/*" { - register int c; - for ( ; ; ) { - /* Eat up characters till we hit the - * end of file or * - */ - while ( (c = input()) != '*' && c != EOF){ - if(c == '\n') - orte_rds_hostfile_line++; - } - - /* If we reach a *, then look for the - * matching / - */ - if ( c == '*') { - while ( (c = input()) == '*' ) { - if(c == '\n') - orte_rds_hostfile_line++; - } - if ( c == '/' ) - break; /* End of Comment */ - } - else if ( c == EOF ) { - /* EOF in comment :( */ - break; - } - } - return ORTE_RDS_HOSTFILE_NEWLINE; - } +"/*" { BEGIN(comment); + return ORTE_RDS_HOSTFILE_NEWLINE; } +[^*\n]* ; /* Eat up non '*'s */ +"*"+[^*/\n]* ; /* Eat '*'s not followed by a '/' */ +\n { orte_rds_hostfile_line++; + return ORTE_RDS_HOSTFILE_NEWLINE; } +"*"+"/" { BEGIN(INITIAL); /* Done with Block Comment */ + return ORTE_RDS_HOSTFILE_NEWLINE; } \"[^\"]*\" { orte_rds_hostfile_value.sval = yytext; return ORTE_RDS_HOSTFILE_QUOTED_STRING; }