1 /* 2 * Copyright (C) 2020-2021 Jo-Philipp Wich <jo@mein.io> 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef UCODE_LEXER_H 18 #define UCODE_LEXER_H 19 20 #include "source.h" 21 #include "types.h" 22 23 24 typedef enum { 25 TK_LEXP = 1, 26 TK_REXP, 27 TK_LSTM, 28 TK_RSTM, 29 TK_IF, 30 TK_ELSE, 31 TK_COMMA, 32 TK_ASSIGN, 33 TK_ASADD, 34 TK_ASSUB, 35 TK_ASMUL, 36 TK_ASDIV, 37 TK_ASMOD, 38 TK_ASLEFT, 39 TK_ASRIGHT, 40 TK_ASBAND, 41 TK_ASBXOR, 42 TK_ASBOR, 43 TK_QMARK, 44 TK_COLON, 45 TK_OR, 46 TK_AND, 47 TK_BOR, 48 TK_BXOR, 49 TK_BAND, 50 TK_EQS, 51 TK_NES, 52 TK_EQ, 53 TK_NE, 54 TK_LT, 55 TK_LE, 56 TK_GT, 57 TK_GE, 58 TK_IN, 59 TK_LSHIFT, 60 TK_RSHIFT, 61 TK_ADD, 62 TK_SUB, 63 TK_MUL, 64 TK_DIV, 65 TK_MOD, 66 TK_EXP, 67 TK_NOT, 68 TK_COMPL, 69 TK_INC, 70 TK_DEC, 71 TK_DOT, 72 TK_LBRACK, 73 TK_RBRACK, 74 TK_LPAREN, 75 TK_RPAREN, 76 TK_TEXT, 77 TK_LBRACE, 78 TK_RBRACE, 79 TK_SCOL, 80 TK_ENDIF, 81 TK_ELIF, 82 TK_WHILE, 83 TK_ENDWHILE, 84 TK_FOR, 85 TK_ENDFOR, 86 TK_FUNC, 87 TK_LABEL, 88 TK_ENDFUNC, 89 TK_TRY, 90 TK_CATCH, 91 TK_SWITCH, 92 TK_CASE, 93 TK_DEFAULT, 94 TK_ELLIP, 95 TK_RETURN, 96 TK_BREAK, 97 TK_CONTINUE, 98 TK_LOCAL, 99 TK_ARROW, 100 TK_TRUE, 101 TK_FALSE, 102 TK_NUMBER, 103 TK_DOUBLE, 104 TK_STRING, 105 TK_REGEXP, 106 TK_NULL, 107 TK_THIS, 108 TK_DELETE, 109 TK_CONST, 110 TK_QLBRACK, 111 TK_QLPAREN, 112 TK_QDOT, 113 TK_ASEXP, 114 TK_ASAND, 115 TK_ASOR, 116 TK_ASNULLISH, 117 TK_NULLISH, 118 TK_PLACEH, 119 TK_TEMPLATE, 120 TK_IMPORT, 121 TK_EXPORT, 122 123 TK_EOF, 124 TK_ERROR 125 } uc_tokentype_t; 126 127 typedef enum { 128 UC_LEX_IDENTIFY_BLOCK, 129 UC_LEX_BLOCK_EXPRESSION_EMIT_TAG, 130 UC_LEX_BLOCK_COMMENT, 131 UC_LEX_IDENTIFY_TOKEN, 132 UC_LEX_PLACEHOLDER_START, 133 UC_LEX_PLACEHOLDER_END, 134 UC_LEX_EOF 135 } uc_lex_state_t; 136 137 typedef struct { 138 uc_tokentype_t type; 139 uc_value_t *uv; 140 size_t pos; 141 } uc_token_t; 142 143 typedef struct { 144 uc_lex_state_t state; 145 uc_parse_config_t *config; 146 uc_source_t *source; 147 uint8_t no_regexp:1; 148 uint8_t no_keyword:1; 149 uc_token_t curr; 150 int lead_surrogate; 151 size_t lastoff; 152 enum { 153 UNSPEC, 154 PLUS, 155 MINUS, 156 NEWLINE 157 } modifier; 158 enum { 159 NONE, 160 EXPRESSION = '{', 161 STATEMENTS = '%', 162 COMMENT = '#' 163 } block; 164 struct { 165 size_t count; 166 size_t *entries; 167 } templates; 168 struct { 169 size_t count; 170 char *entries; 171 } buffer; 172 unsigned char *rbuf; 173 size_t rlen, rpos; 174 } uc_lexer_t; 175 176 177 __hidden void uc_lexer_init(uc_lexer_t *lex, uc_parse_config_t *config, uc_source_t *source); 178 __hidden void uc_lexer_free(uc_lexer_t *lex); 179 180 __hidden uc_token_t *uc_lexer_next_token(uc_lexer_t *lex); 181 182 __hidden bool uc_lexer_is_keyword(uc_value_t *label); 183 184 __hidden bool utf8enc(char **out, int *rem, int code); 185 186 __hidden const char *uc_tokenname(unsigned type); 187 188 #endif /* UCODE_LEXER_H */ 189
This page was automatically generated by LXR 0.3.1. • OpenWrt