Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/lex.c

    r051bc69a r38aaacc2  
    3535#include <stdlib.h>
    3636#include "bigint.h"
    37 #include "cspan.h"
    3837#include "mytypes.h"
    3938#include "input.h"
     
    7574/** Keyword names. Used both for printing and recognition. */
    7675static struct lc_name keywords[] = {
    77         { lc_and,       "and" },
    7876        { lc_as,        "as" },
    7977        { lc_bool,      "bool" },
    80         { lc_break,     "break" },
     78        { lc_char,      "char" },
    8179        { lc_builtin,   "builtin" },
    82         { lc_char,      "char" },
    8380        { lc_class,     "class" },
     81        { lc_constructor,       "constructor" },
    8482        { lc_deleg,     "deleg" },
    8583        { lc_do,        "do" },
    86         { lc_elif,      "elif" },
    8784        { lc_else,      "else" },
    8885        { lc_end,       "end" },
    89         { lc_enum,      "enum" },
    9086        { lc_except,    "except" },
    9187        { lc_false,     "false" },
     
    10096        { lc_is,        "is" },
    10197        { lc_new,       "new" },
    102         { lc_not,       "not" },
    10398        { lc_nil,       "nil" },
    104         { lc_or,        "or" },
    10599        { lc_override,  "override" },
    106100        { lc_packed,    "packed" },
     
    239233void lem_print_coords(lem_t *lem)
    240234{
    241         cspan_print(lem->cspan);
     235        printf("%d:%d", lem->line_no, lem->col_0);
    242236}
    243237
     
    261255        lex->ibp = lex->inbuf;
    262256        lex->col_adj = 0;
    263         lex->prev_valid = b_false;
    264257        lex->current_valid = b_true;
    265258}
     
    286279 * @param lex           Lexer object.
    287280 * @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().
    289282 */
    290283lem_t *lex_get_current(lex_t *lex)
     
    294287}
    295288
    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 valid
    302  *                      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 to
    321          * @a previous.
    322          */
    323         return &lex->prev;
    324 }
    325 
    326289/** Read in the current lexical element (unless already read in).
    327290 *
     
    334297        if (lex->current_valid == b_true)
    335298                return;
    336 
    337         /* Copy previous lem */
    338         lex->prev = lex->current;
    339         lex->prev_valid = b_true;
    340299
    341300        do {
     
    359318static bool_t lex_read_try(lex_t *lex)
    360319{
    361         char *bp, *lsp;
    362         int line0, col0;
     320        char *bp;
    363321
    364322        lex_skip_ws(lex);
     
    370328         * separately using col_adj.
    371329         */
    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
    378333        bp = lex->ibp;
    379334
     
    381336                /* End of input */
    382337                lex->current.lclass = lc_eof;
    383                 goto finish;
     338                return b_true;
    384339        }
    385340
    386341        if (is_wstart(bp[0])) {
    387342                lex_word(lex);
    388                 goto finish;
     343                return b_true;
    389344        }
    390345
    391346        if (bp[0] == '\'') {
    392347                lex_char(lex);
    393                 goto finish;
     348                return b_true;
    394349        }
    395350
    396351        if (is_digit(bp[0])) {
    397352                lex_number(lex);
    398                 goto finish;
     353                return b_true;
    399354        }
    400355
    401356        if (bp[0] == '"') {
    402357                lex_string(lex);
    403                 goto finish;
     358                return b_true;
    404359        }
    405360
    406361        if (bp[0] == '-' && bp[1] == '-') {
    407362                lex_skip_comment(lex);
    408 
    409                 /* Compute ending column number */
    410                 lex->current.cspan->col1 = col0 + (lex->ibp - lsp) - 1;
    411 
    412                 /* Try again */
    413363                return b_false;
    414364        }
     
    467417
    468418        lex->ibp = bp;
    469 
    470 finish:
    471         /* Compute ending column number */
    472         lex->current.cspan->col1 = col0 + (lex->ibp - lsp) - 1;
    473419        return b_true;
    474420
Note: See TracChangeset for help on using the changeset viewer.