Changeset 94d484a in mainline for uspace/app/sbi/src/lex.c


Ignore:
Timestamp:
2010-03-07T17:45:33Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d0febca
Parents:
fa36f29
Message:

Update SBI to rev. 90.

File:
1 edited

Legend:

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

    rfa36f29 r94d484a  
    3535#include <stdlib.h>
    3636#include <string.h>
    37 #include "compat.h"
    3837#include "mytypes.h"
    3938#include "input.h"
     39#include "os/os.h"
    4040#include "strtab.h"
    4141
     
    4444#define TAB_WIDTH 8
    4545
     46static bool_t lex_next_try(lex_t *lex);
     47
     48static void lex_skip_comment(lex_t *lex);
    4649static void lex_skip_ws(lex_t *lex);
    4750static bool_t is_wstart(char c);
     
    8790        { lc_nil,       "nil" },
    8891        { lc_override,  "override" },
     92        { lc_packed,    "packed" },
    8993        { lc_private,   "private" },
    9094        { lc_prop,      "prop" },
     
    222226void lex_next(lex_t *lex)
    223227{
     228        bool_t got_lem;
     229
     230        do {
     231                got_lem = lex_next_try(lex);
     232        } while (got_lem == b_false);
     233}
     234
     235/** Try reading next lexical element.
     236 *
     237 * @return @c b_true on success or @c b_false if it needs restarting.
     238 */
     239static bool_t lex_next_try(lex_t *lex)
     240{
    224241        char *bp;
    225242
     
    240257                /* End of input */
    241258                lex->current.lclass = lc_eof;
    242                 return;
     259                return b_true;
    243260        }
    244261
    245262        if (is_wstart(bp[0])) {
    246263                lex_word(lex);
    247                 return;
     264                return b_true;
    248265        }
    249266
    250267        if (is_digit(bp[0])) {
    251268                lex_number(lex);
    252                 return;
     269                return b_true;
    253270        }
    254271
    255272        if (bp[0] == '"') {
    256273                lex_string(lex);
    257                 return;
     274                return b_true;
     275        }
     276
     277        if (bp[0] == '-' && bp[1] == '-') {
     278                lex_skip_comment(lex);
     279                return b_false;
    258280        }
    259281
     
    305327
    306328        lex->ibp = bp;
    307         return;
     329        return b_true;
    308330
    309331invalid:
     
    311333        ++bp;
    312334        lex->ibp = bp;
     335
     336        return b_true;
    313337}
    314338
     
    340364        dp = keywords;
    341365        while (dp->name != NULL) {
    342                 if (strcmp(ident_buf, dp->name) == 0) {
     366                if (os_str_cmp(ident_buf, dp->name) == 0) {
    343367                        /* Match */
    344368                        lex->current.lclass = dp->lclass;
     
    402426
    403427        lex->current.lclass = lc_lit_string;
    404         lex->current.u.lit_string.value = strdup(strlit_buf);
    405 }
    406 
     428        lex->current.u.lit_string.value = os_str_dup(strlit_buf);
     429}
     430
     431/** Lex a single-line comment. */
     432static void lex_skip_comment(lex_t *lex)
     433{
     434        char *bp;
     435
     436        bp = lex->ibp + 2;
     437
     438        while (*bp != '\n' && *bp != '\0') {
     439                ++bp;
     440        }
     441
     442        lex->ibp = bp;
     443}
    407444
    408445/** Skip whitespace characters. */
Note: See TracChangeset for help on using the changeset viewer.