Show
Ignore:
Timestamp:
10/26/06 13:50:27 (7 years ago)
Author:
mmh
Message:

Merge scanner-opt-branch (r4121:r4221) to trunk.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/lib/conf-lex.l

    r3300 r4222  
    3333 
    3434char sensors_lex_error[100]; 
     35 
     36int sensors_yylineno; 
    3537 
    3638#define buffer_malloc() sensors_malloc_array(&buffer,&buffer_count,\ 
     
    4749%} 
    4850 
    49 /* Scanner for configuration files */ 
     51 /* Scanner for configuration files */ 
    5052 
    5153%option nodefault 
    5254%option noyywrap 
    53 %option yylineno 
    5455%option nounput 
    5556 
    56 /* States. 'Normal' states STRING and MIDDLE share some rules; other states 
    57    have only their own rules */ 
    58 %s MIDDLE 
     57 /* All states are exclusive */ 
     58 
     59%x MIDDLE 
    5960%x STRING 
    6061%x ERR 
    6162 
    62 /* Any whitespace-like character */ 
    63 BLANK           [[:space:]] 
     63 /* Any whitespace-like character */ 
     64 
     65BLANK           [ \f\t\v] 
    6466 
    6567IDCHAR          [[:alnum:]_] 
    6668 
    67 /* Note: `10', `10.4' and `.4' are valid, `10.' is not */ 
     69 /* Note: `10', `10.4' and `.4' are valid, `10.' is not */ 
     70 
    6871FLOAT   [[:digit:]]*\.?[[:digit:]]+ 
    6972 
    70 /* Only positive whole numbers are recognized here */ 
     73 /* Only positive whole numbers are recognized here */ 
     74 
    7175NUM     0|([1-9][[:digit:]]*) 
    7276 
    73 /* Only number between 1 and 255, octally represented. */ 
     77 /* Only number between 1 and 255, octally represented. */ 
     78 
    7479OCTESC          (1[0-7]{0,2})|([2-7][0-7]?)|(0[1-7][0-7]?)|(00[1-7]) 
    7580 
     
    7782%% 
    7883 
    79  
    80  /* End of line: It may be the end of this line. Same for End of file. */ 
    81 <MIDDLE>\n      | 
    82 <MIDDLE><<EOF>> { 
    83                   BEGIN(INITIAL); 
    84                   return EOL; 
    85                 } 
    86  
    87  /* We want to match any blank, except End of line; that is why we have to 
    88     match whitespace one by one! */ 
    89 {BLANK}         /* Eat up a blank */ 
    90  
    91  /* Escaped End of line: eat and be happy */ 
    92 <MIDDLE>\\\n    /* Eat this! */ 
    93  
    94  /* Remove a comment; we do not change the state, this is done when the \n is 
    95     eaten */ 
    96 #[^\n]*         /* Eat this! */ 
    97  
    98  /* Some keywords at the beginning of lines */ 
    99 <INITIAL>"label" { 
     84 /* 
     85  * STATE: INITIAL 
     86  */ 
     87 
     88<INITIAL>{ 
     89 
     90<<EOF>>         { /* EOF from this state terminates */ 
     91                  return 0; 
     92                } 
     93 
     94{BLANK}+        ; /* eat as many blanks as possible at once */ 
     95 
     96{BLANK}*\n      { /* eat a bare newline (possibly preceded by blanks) */ 
     97                  sensors_yylineno++; 
     98                } 
     99 
     100 /* comments */ 
     101 
     102#.*             ; /* eat the rest of the line after comment char */ 
     103 
     104#.*\n           { /* eat the rest of the line after comment char */ 
     105                  sensors_yylineno++; 
     106                } 
     107 
     108 /* 
     109  * Keywords must be followed by whitespace - eat that too. 
     110  * If there isn't trailing whitespace, we still need to 
     111  * accept it as lexically correct (even though the parser 
     112  * will reject it anyway.) 
     113  */ 
     114 
     115label{BLANK}*   { 
    100116                  sensors_yylval.line = sensors_yylineno; 
    101117                  BEGIN(MIDDLE); 
     
    103119                } 
    104120 
    105 <INITIAL>"set"  { 
     121set{BLANK}*     { 
    106122                  sensors_yylval.line = sensors_yylineno; 
    107123                  BEGIN(MIDDLE); 
     
    109125                } 
    110126 
    111 <INITIAL>"compute" { 
     127compute{BLANK}* { 
    112128                  sensors_yylval.line = sensors_yylineno; 
    113129                  BEGIN(MIDDLE); 
     
    115131                } 
    116132 
    117 <INITIAL>"bus"  { 
     133bus{BLANK}*     { 
    118134                  sensors_yylval.line = sensors_yylineno; 
    119135                  BEGIN(MIDDLE); 
     
    121137                } 
    122138 
    123 <INITIAL>"chip" { 
     139chip{BLANK}*    { 
    124140                  sensors_yylval.line = sensors_yylineno; 
    125141                  BEGIN(MIDDLE); 
    126142                  return CHIP; 
    127143                } 
    128 <INITIAL>"ignore" { 
     144 
     145ignore{BLANK}*  { 
    129146                  sensors_yylval.line = sensors_yylineno; 
    130147                  BEGIN(MIDDLE); 
     
    133150 
    134151 /* Anything else at the beginning of a line is an error */ 
    135 <INITIAL>.      { 
     152 
     153[a-z]+          | 
     154.               { 
    136155                  yymore(); 
    137156                  BEGIN(ERR); 
    138                 } 
    139  
    140 <ERR>[^\n]*\n   { 
    141                   BEGIN(INITIAL); 
    142157                  strcpy(sensors_lex_error,"Invalid keyword"); 
    143158                  return ERROR; 
    144159                } 
     160} 
     161 
     162 /* 
     163  * STATE: ERROR 
     164  */ 
     165 
     166<ERR>{ 
     167 
     168.*              ; /* eat whatever is left on this line */ 
     169 
     170\n              { 
     171                  BEGIN(INITIAL); 
     172                  sensors_yylineno++; 
     173                  return EOL; 
     174                } 
     175} 
     176 
     177 /* 
     178  * STATE: MIDDLE 
     179  */ 
     180 
     181<MIDDLE>{ 
     182 
     183{BLANK}+        ; /* eat as many blanks as possible at once */ 
     184 
     185\n              { /* newline here sends EOL token to parser */ 
     186                  BEGIN(INITIAL); 
     187                  sensors_yylineno++; 
     188                  return EOL; 
     189                } 
     190 
     191<<EOF>>         { /* EOF here sends EOL token to parser also */ 
     192                  BEGIN(INITIAL); 
     193                  return EOL; 
     194                } 
     195 
     196\\{BLANK}*\n    { /* eat an escaped newline with no state change */ 
     197                  sensors_yylineno++; 
     198                } 
     199 
     200 /* comments */ 
     201 
     202#.*             ; /* eat the rest of the line after comment char */ 
     203 
     204#.*\n           { /* eat the rest of the line after comment char */ 
     205                  BEGIN(INITIAL); 
     206                  sensors_yylineno++; 
     207                  return EOL; 
     208                } 
    145209 
    146210 /* A number */ 
    147 <MIDDLE>{FLOAT} { 
     211 
     212{FLOAT}         { 
    148213                  sensors_yylval.value = atof(sensors_yytext); 
    149214                  return FLOAT; 
     
    151216 
    152217 /* Some operators */ 
    153 <MIDDLE>"+"     { 
    154                   return '+'; 
    155                 } 
    156  
    157 <MIDDLE>"-"     { 
    158                   return '-'; 
    159                 } 
    160  
    161 <MIDDLE>"*"     { 
    162                   return '*'; 
    163                 } 
    164  
    165 <MIDDLE>"/"     { 
    166                   return '/'; 
    167                 } 
    168  
    169 <MIDDLE>"("     { 
    170                   return '('; 
    171                 } 
    172  
    173 <MIDDLE>")"     { 
    174                   return ')'; 
    175                 } 
    176 <MIDDLE>","     { 
    177                   return ','; 
    178                 } 
    179 <MIDDLE>"@"     { 
    180                   return '@'; 
    181                 } 
    182 <MIDDLE>"^"     { 
    183                   return '^'; 
    184                 } 
    185 <MIDDLE>"`"     { 
    186                   return '`'; 
    187                 } 
     218 
     219"+"             return '+'; 
     220"-"             return '-'; 
     221"*"             return '*'; 
     222"/"             return '/'; 
     223"("             return '('; 
     224")"             return ')'; 
     225","             return ','; 
     226"@"             return '@'; 
     227"^"             return '^'; 
     228"`"             return '`'; 
    188229 
    189230 /* Quoted string */ 
    190 <MIDDLE>\"      { 
     231 
     232\"              { 
    191233                  buffer_malloc(); 
    192234                  BEGIN(STRING); 
    193235                } 
    194236 
     237 /* A normal, unquoted identifier */ 
     238 
     239{IDCHAR}+       { 
     240                  sensors_yylval.name = strdup(sensors_yytext); 
     241                  if (! sensors_yylval.name) 
     242                    sensors_fatal_error("conf-lex.l", 
     243                                        "Allocating a new string"); 
     244                   
     245                  return NAME; 
     246                } 
     247 
     248 /* anything else is bogus */ 
     249 
     250.               | 
     251[[:digit:]]*\.  | 
     252\\{BLANK}*      { 
     253                  yymore(); 
     254                  BEGIN(ERR); 
     255                  return ERROR; 
     256                } 
     257} 
     258 
     259 /* 
     260  * STATE: STRING 
     261  */ 
     262 
     263<STRING>{ 
     264 
    195265 /* Oops, newline while in a string is not good */ 
    196 <STRING>\n      | 
    197 <STRING>\\\n    { 
     266 
     267\n              | 
     268\\\n            { 
    198269                  buffer_add_char("\0"); 
    199270                  strcpy(sensors_lex_error,"No matching double quote"); 
     
    204275 
    205276 /* At the end */ 
    206 <STRING>\"      { 
     277 
     278\"              { 
    207279                  buffer_add_char("\0"); 
    208280                  sensors_yylval.name = strdup(buffer); 
     
    215287                } 
    216288 
    217 <STRING>\\a     { 
     289\\a             { 
    218290                  buffer_add_char("\a"); 
    219291                } 
    220292 
    221 <STRING>\\b     { 
     293\\b             { 
    222294                  buffer_add_char("\b"); 
    223295                } 
    224296 
    225 <STRING>\\f     { 
     297\\f             { 
    226298                  buffer_add_char("\f"); 
    227299                } 
    228300 
    229 <STRING>\\n     { 
     301\\n             { 
    230302                  buffer_add_char("\n"); 
    231303                } 
    232304 
    233 <STRING>\\r     { 
     305\\r             { 
    234306                  buffer_add_char("\r"); 
    235307                } 
    236308 
    237 <STRING>\\t     { 
     309\\t             { 
    238310                  buffer_add_char("\t"); 
    239311                } 
    240312 
    241 <STRING>\\v     { 
     313\\v             { 
    242314                  buffer_add_char("\v"); 
    243315                } 
    244316 
    245317 /* We can't support \0, this would cause havoc! */ 
    246 <STRING>\\{OCTESC} { 
     318 
     319\\{OCTESC}      { 
    247320                  int res; 
    248321                  sscanf(sensors_yytext+1,"%o",&res); 
     
    251324 
    252325 /* Other escapes: just copy the character behind the slash */ 
    253 <STRING>\\.     { 
     326 
     327\\.             { 
    254328                  buffer_add_char(&sensors_yytext[1]); 
    255329                } 
    256330 
    257  /* Anything else */ 
    258 <STRING>[^\\\n\"]+ { 
     331 /* This prevents backing up; it is otherwise purely redundant */ 
     332 
     333\\00            { 
     334                  buffer_add_char("00"); 
     335                } 
     336 
     337 /* Anything else (including a bare '\' which may be followed by EOF) */ 
     338 
     339\\              | 
     340[^\\\n\"]+      { 
    259341                  buffer_add_string(sensors_yytext); 
    260342                } 
    261  
    262  /* A normal, unquoted identifier */ 
    263 <MIDDLE>{IDCHAR}+ { 
    264                   sensors_yylval.name = strdup(sensors_yytext); 
    265                   if (! sensors_yylval.name) 
    266                     sensors_fatal_error("conf-lex.l", 
    267                                         "Allocating a new string"); 
    268                    
    269                   return NAME; 
    270                 } 
     343} 
    271344 
    272345%% 
     
    290363 
    291364        sensors_yy_switch_to_buffer(scan_buf); 
     365        sensors_yylineno = 1; 
    292366        return 0; 
    293367}