Changeset 051bc69a in mainline for uspace/app/sbi/src/lex.c


Ignore:
Timestamp:
2010-05-08T08:10:44Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
640ffe6, c5cb943d
Parents:
25a76ab8
Message:

Update SBI to rev. 244.

File:
1 edited

Legend:

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

    r25a76ab8 r051bc69a  
    3535#include <stdlib.h>
    3636#include "bigint.h"
     37#include "cspan.h"
    3738#include "mytypes.h"
    3839#include "input.h"
     
    7475/** Keyword names. Used both for printing and recognition. */
    7576static struct lc_name keywords[] = {
     77        { lc_and,       "and" },
    7678        { lc_as,        "as" },
    7779        { lc_bool,      "bool" },
     80        { lc_break,     "break" },
     81        { lc_builtin,   "builtin" },
    7882        { lc_char,      "char" },
    79         { lc_builtin,   "builtin" },
    8083        { lc_class,     "class" },
    81         { lc_constructor,       "constructor" },
    8284        { lc_deleg,     "deleg" },
    8385        { lc_do,        "do" },
     86        { lc_elif,      "elif" },
    8487        { lc_else,      "else" },
    8588        { lc_end,       "end" },
     89        { lc_enum,      "enum" },
    8690        { lc_except,    "except" },
    8791        { lc_false,     "false" },
     
    96100        { lc_is,        "is" },
    97101        { lc_new,       "new" },
     102        { lc_not,       "not" },
    98103        { lc_nil,       "nil" },
     104        { lc_or,        "or" },
    99105        { lc_override,  "override" },
    100106        { lc_packed,    "packed" },
     
    233239void lem_print_coords(lem_t *lem)
    234240{
    235         printf("%d:%d", lem->line_no, lem->col_0);
     241        cspan_print(lem->cspan);
    236242}
    237243
     
    255261        lex->ibp = lex->inbuf;
    256262        lex->col_adj = 0;
     263        lex->prev_valid = b_false;
    257264        lex->current_valid = b_true;
    258265}
     
    279286 * @param lex           Lexer object.
    280287 * @return              Pointer to current lem. Owned by @a lex and only valid
    281  *                      until next call to lex_next().
     288 *                      until next call to lex_xxx().
    282289 */
    283290lem_t *lex_get_current(lex_t *lex)
     
    287294}
    288295
     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 */
     304lem_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
    289326/** Read in the current lexical element (unless already read in).
    290327 *
     
    297334        if (lex->current_valid == b_true)
    298335                return;
     336
     337        /* Copy previous lem */
     338        lex->prev = lex->current;
     339        lex->prev_valid = b_true;
    299340
    300341        do {
     
    318359static bool_t lex_read_try(lex_t *lex)
    319360{
    320         char *bp;
     361        char *bp, *lsp;
     362        int line0, col0;
    321363
    322364        lex_skip_ws(lex);
     
    328370         * separately using col_adj.
    329371         */
    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 
     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;
    333378        bp = lex->ibp;
    334379
     
    336381                /* End of input */
    337382                lex->current.lclass = lc_eof;
    338                 return b_true;
     383                goto finish;
    339384        }
    340385
    341386        if (is_wstart(bp[0])) {
    342387                lex_word(lex);
    343                 return b_true;
     388                goto finish;
    344389        }
    345390
    346391        if (bp[0] == '\'') {
    347392                lex_char(lex);
    348                 return b_true;
     393                goto finish;
    349394        }
    350395
    351396        if (is_digit(bp[0])) {
    352397                lex_number(lex);
    353                 return b_true;
     398                goto finish;
    354399        }
    355400
    356401        if (bp[0] == '"') {
    357402                lex_string(lex);
    358                 return b_true;
     403                goto finish;
    359404        }
    360405
    361406        if (bp[0] == '-' && bp[1] == '-') {
    362407                lex_skip_comment(lex);
     408
     409                /* Compute ending column number */
     410                lex->current.cspan->col1 = col0 + (lex->ibp - lsp) - 1;
     411
     412                /* Try again */
    363413                return b_false;
    364414        }
     
    417467
    418468        lex->ibp = bp;
     469
     470finish:
     471        /* Compute ending column number */
     472        lex->current.cspan->col1 = col0 + (lex->ibp - lsp) - 1;
    419473        return b_true;
    420474
Note: See TracChangeset for help on using the changeset viewer.