Changes in uspace/app/sbi/src/lex.c [051bc69a:38aaacc2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/lex.c
r051bc69a r38aaacc2 35 35 #include <stdlib.h> 36 36 #include "bigint.h" 37 #include "cspan.h"38 37 #include "mytypes.h" 39 38 #include "input.h" … … 75 74 /** Keyword names. Used both for printing and recognition. */ 76 75 static struct lc_name keywords[] = { 77 { lc_and, "and" },78 76 { lc_as, "as" }, 79 77 { lc_bool, "bool" }, 80 { lc_ break, "break" },78 { lc_char, "char" }, 81 79 { lc_builtin, "builtin" }, 82 { lc_char, "char" },83 80 { lc_class, "class" }, 81 { lc_constructor, "constructor" }, 84 82 { lc_deleg, "deleg" }, 85 83 { lc_do, "do" }, 86 { lc_elif, "elif" },87 84 { lc_else, "else" }, 88 85 { lc_end, "end" }, 89 { lc_enum, "enum" },90 86 { lc_except, "except" }, 91 87 { lc_false, "false" }, … … 100 96 { lc_is, "is" }, 101 97 { lc_new, "new" }, 102 { lc_not, "not" },103 98 { lc_nil, "nil" }, 104 { lc_or, "or" },105 99 { lc_override, "override" }, 106 100 { lc_packed, "packed" }, … … 239 233 void lem_print_coords(lem_t *lem) 240 234 { 241 cspan_print(lem->cspan);235 printf("%d:%d", lem->line_no, lem->col_0); 242 236 } 243 237 … … 261 255 lex->ibp = lex->inbuf; 262 256 lex->col_adj = 0; 263 lex->prev_valid = b_false;264 257 lex->current_valid = b_true; 265 258 } … … 286 279 * @param lex Lexer object. 287 280 * @return Pointer to current lem. Owned by @a lex and only valid 288 * until next call to lex_ xxx().281 * until next call to lex_next(). 289 282 */ 290 283 lem_t *lex_get_current(lex_t *lex) … … 294 287 } 295 288 296 /** Get previous lem if valid.297 *298 * The returned pointer is invalidated by next call to lex_next()299 *300 * @param lex Lexer object.301 * @return Pointer to previous lem. Owned by @a lex and only valid302 * until next call to lex_xxx().303 */304 lem_t *lex_peek_prev(lex_t *lex)305 {306 if (lex->current_valid == b_false) {307 /*308 * This means the head is advanced but next lem was not read.309 * Thus the previous lem is still in @a current.310 */311 return &lex->current;312 }313 314 if (lex->prev_valid != b_true) {315 /* Looks like we are still at the first lem. */316 return NULL;317 }318 319 /*320 * Current lem has been read in. Thus the previous lem was moved to321 * @a previous.322 */323 return &lex->prev;324 }325 326 289 /** Read in the current lexical element (unless already read in). 327 290 * … … 334 297 if (lex->current_valid == b_true) 335 298 return; 336 337 /* Copy previous lem */338 lex->prev = lex->current;339 lex->prev_valid = b_true;340 299 341 300 do { … … 359 318 static bool_t lex_read_try(lex_t *lex) 360 319 { 361 char *bp, *lsp; 362 int line0, col0; 320 char *bp; 363 321 364 322 lex_skip_ws(lex); … … 370 328 * separately using col_adj. 371 329 */ 372 line0 = input_get_line_no(lex->input); 373 col0 = 1 + lex->col_adj + (lex->ibp - lex->inbuf); 374 375 lex->current.cspan = cspan_new(lex->input, line0, col0, line0, col0); 376 377 lsp = lex->ibp; 330 lex->current.line_no = input_get_line_no(lex->input); 331 lex->current.col_0 = 1 + lex->col_adj + (lex->ibp - lex->inbuf); 332 378 333 bp = lex->ibp; 379 334 … … 381 336 /* End of input */ 382 337 lex->current.lclass = lc_eof; 383 goto finish;338 return b_true; 384 339 } 385 340 386 341 if (is_wstart(bp[0])) { 387 342 lex_word(lex); 388 goto finish;343 return b_true; 389 344 } 390 345 391 346 if (bp[0] == '\'') { 392 347 lex_char(lex); 393 goto finish;348 return b_true; 394 349 } 395 350 396 351 if (is_digit(bp[0])) { 397 352 lex_number(lex); 398 goto finish;353 return b_true; 399 354 } 400 355 401 356 if (bp[0] == '"') { 402 357 lex_string(lex); 403 goto finish;358 return b_true; 404 359 } 405 360 406 361 if (bp[0] == '-' && bp[1] == '-') { 407 362 lex_skip_comment(lex); 408 409 /* Compute ending column number */410 lex->current.cspan->col1 = col0 + (lex->ibp - lsp) - 1;411 412 /* Try again */413 363 return b_false; 414 364 } … … 467 417 468 418 lex->ibp = bp; 469 470 finish:471 /* Compute ending column number */472 lex->current.cspan->col1 = col0 + (lex->ibp - lsp) - 1;473 419 return b_true; 474 420
Note:
See TracChangeset
for help on using the changeset viewer.