Changeset 4222 for lm-sensors/trunk/lib/conf-lex.l
- Timestamp:
- 10/26/06 13:50:27 (7 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/lib/conf-lex.l (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/lib/conf-lex.l
r3300 r4222 33 33 34 34 char sensors_lex_error[100]; 35 36 int sensors_yylineno; 35 37 36 38 #define buffer_malloc() sensors_malloc_array(&buffer,&buffer_count,\ … … 47 49 %} 48 50 49 /* Scanner for configuration files */51 /* Scanner for configuration files */ 50 52 51 53 %option nodefault 52 54 %option noyywrap 53 %option yylineno54 55 %option nounput 55 56 56 /* States. 'Normal' states STRING and MIDDLE share some rules; other states 57 have only their own rules */ 58 % sMIDDLE57 /* All states are exclusive */ 58 59 %x MIDDLE 59 60 %x STRING 60 61 %x ERR 61 62 62 /* Any whitespace-like character */ 63 BLANK [[:space:]] 63 /* Any whitespace-like character */ 64 65 BLANK [ \f\t\v] 64 66 65 67 IDCHAR [[:alnum:]_] 66 68 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 68 71 FLOAT [[:digit:]]*\.?[[:digit:]]+ 69 72 70 /* Only positive whole numbers are recognized here */ 73 /* Only positive whole numbers are recognized here */ 74 71 75 NUM 0|([1-9][[:digit:]]*) 72 76 73 /* Only number between 1 and 255, octally represented. */ 77 /* Only number between 1 and 255, octally represented. */ 78 74 79 OCTESC (1[0-7]{0,2})|([2-7][0-7]?)|(0[1-7][0-7]?)|(00[1-7]) 75 80 … … 77 82 %% 78 83 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 115 label{BLANK}* { 100 116 sensors_yylval.line = sensors_yylineno; 101 117 BEGIN(MIDDLE); … … 103 119 } 104 120 105 <INITIAL>"set"{121 set{BLANK}* { 106 122 sensors_yylval.line = sensors_yylineno; 107 123 BEGIN(MIDDLE); … … 109 125 } 110 126 111 <INITIAL>"compute"{127 compute{BLANK}* { 112 128 sensors_yylval.line = sensors_yylineno; 113 129 BEGIN(MIDDLE); … … 115 131 } 116 132 117 <INITIAL>"bus"{133 bus{BLANK}* { 118 134 sensors_yylval.line = sensors_yylineno; 119 135 BEGIN(MIDDLE); … … 121 137 } 122 138 123 <INITIAL>"chip"{139 chip{BLANK}* { 124 140 sensors_yylval.line = sensors_yylineno; 125 141 BEGIN(MIDDLE); 126 142 return CHIP; 127 143 } 128 <INITIAL>"ignore" { 144 145 ignore{BLANK}* { 129 146 sensors_yylval.line = sensors_yylineno; 130 147 BEGIN(MIDDLE); … … 133 150 134 151 /* Anything else at the beginning of a line is an error */ 135 <INITIAL>. { 152 153 [a-z]+ | 154 . { 136 155 yymore(); 137 156 BEGIN(ERR); 138 }139 140 <ERR>[^\n]*\n {141 BEGIN(INITIAL);142 157 strcpy(sensors_lex_error,"Invalid keyword"); 143 158 return ERROR; 144 159 } 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 } 145 209 146 210 /* A number */ 147 <MIDDLE>{FLOAT} { 211 212 {FLOAT} { 148 213 sensors_yylval.value = atof(sensors_yytext); 149 214 return FLOAT; … … 151 216 152 217 /* 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 '`'; 188 229 189 230 /* Quoted string */ 190 <MIDDLE>\" { 231 232 \" { 191 233 buffer_malloc(); 192 234 BEGIN(STRING); 193 235 } 194 236 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 195 265 /* Oops, newline while in a string is not good */ 196 <STRING>\n | 197 <STRING>\\\n { 266 267 \n | 268 \\\n { 198 269 buffer_add_char("\0"); 199 270 strcpy(sensors_lex_error,"No matching double quote"); … … 204 275 205 276 /* At the end */ 206 <STRING>\" { 277 278 \" { 207 279 buffer_add_char("\0"); 208 280 sensors_yylval.name = strdup(buffer); … … 215 287 } 216 288 217 <STRING>\\a{289 \\a { 218 290 buffer_add_char("\a"); 219 291 } 220 292 221 <STRING>\\b{293 \\b { 222 294 buffer_add_char("\b"); 223 295 } 224 296 225 <STRING>\\f{297 \\f { 226 298 buffer_add_char("\f"); 227 299 } 228 300 229 <STRING>\\n{301 \\n { 230 302 buffer_add_char("\n"); 231 303 } 232 304 233 <STRING>\\r{305 \\r { 234 306 buffer_add_char("\r"); 235 307 } 236 308 237 <STRING>\\t{309 \\t { 238 310 buffer_add_char("\t"); 239 311 } 240 312 241 <STRING>\\v{313 \\v { 242 314 buffer_add_char("\v"); 243 315 } 244 316 245 317 /* We can't support \0, this would cause havoc! */ 246 <STRING>\\{OCTESC} { 318 319 \\{OCTESC} { 247 320 int res; 248 321 sscanf(sensors_yytext+1,"%o",&res); … … 251 324 252 325 /* Other escapes: just copy the character behind the slash */ 253 <STRING>\\. { 326 327 \\. { 254 328 buffer_add_char(&sensors_yytext[1]); 255 329 } 256 330 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\"]+ { 259 341 buffer_add_string(sensors_yytext); 260 342 } 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 } 271 344 272 345 %% … … 290 363 291 364 sensors_yy_switch_to_buffer(scan_buf); 365 sensors_yylineno = 1; 292 366 return 0; 293 367 }
