MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at type-hints-typescript 78 lines 2.0 kB view raw
1#ifndef SILVER_LEXER_H 2#define SILVER_LEXER_H 3 4#include <stdbool.h> 5#include "types.h" 6 7typedef struct { 8 ant_offset_t pos; 9 ant_offset_t toff; 10 ant_offset_t tlen; 11 ant_value_t tval; 12 uint8_t tok; 13 uint8_t consumed; 14 bool had_newline; 15} sv_lexer_state_t; 16 17typedef struct { 18 ant_t *js; 19 const char *code; 20 ant_offset_t clen; 21 bool strict; 22 sv_lexer_state_t st; 23} sv_lexer_t; 24 25typedef struct { 26 const char *str; 27 uint32_t len; 28 bool ok; 29} sv_lex_string_t; 30 31typedef struct { 32 const char *code; 33 ant_offset_t clen; 34 bool strict; 35 sv_lexer_state_t st; 36} sv_lexer_checkpoint_t; 37 38sv_lex_string_t sv_lexer_str_literal(sv_lexer_t *lx); 39 40void sv_lexer_init(sv_lexer_t *lx, ant_t *js, const char *code, ant_offset_t clen, bool strict); 41void sv_lexer_set_error_site(sv_lexer_t *lx); 42 43void sv_lexer_save_state(const sv_lexer_t *lx, sv_lexer_state_t *st); 44void sv_lexer_restore_state(sv_lexer_t *lx, const sv_lexer_state_t *st); 45 46void sv_lexer_push_source(sv_lexer_t *lx, sv_lexer_checkpoint_t *cp, const char *code, ant_offset_t clen); 47void sv_lexer_pop_source(sv_lexer_t *lx, const sv_lexer_checkpoint_t *cp); 48 49uint8_t sv_lexer_next(sv_lexer_t *lx); 50uint8_t sv_lexer_lookahead(sv_lexer_t *lx); 51uint8_t sv_parsekeyword(const char *buf, size_t len); 52 53bool is_space(int c); 54bool is_digit(int c); 55 56bool is_ident_begin(int c); 57bool is_ident_continue(int c); 58 59bool is_eval_or_arguments_name(const char *buf, size_t len); 60bool is_strict_reserved_name(const char *buf, size_t len); 61 62#define CHAR_DIGIT 0x01 63#define CHAR_XDIGIT 0x02 64#define CHAR_ALPHA 0x04 65#define CHAR_IDENT 0x08 66#define CHAR_IDENT1 0x10 67#define CHAR_WS 0x20 68#define CHAR_OCTAL 0x40 69 70extern const uint8_t char_type[256]; 71 72#define IS_DIGIT(c) (char_type[(uint8_t)(c)] & CHAR_DIGIT) 73#define IS_XDIGIT(c) (char_type[(uint8_t)(c)] & CHAR_XDIGIT) 74#define IS_IDENT(c) (char_type[(uint8_t)(c)] & CHAR_IDENT) 75#define IS_IDENT1(c) (char_type[(uint8_t)(c)] & CHAR_IDENT1) 76#define IS_OCTAL(c) (char_type[(uint8_t)(c)] & CHAR_OCTAL) 77 78#endif