Lines Matching defs:l
46 BcStatus bc_lex_invalidChar(BcLex *l, char c) {
47 l->t = BC_LEX_INVALID;
48 return bc_lex_verr(l, BC_ERROR_PARSE_CHAR, c);
51 void bc_lex_lineComment(BcLex *l) {
52 l->t = BC_LEX_WHITESPACE;
53 while (l->i < l->len && l->buf[l->i] != '\n') l->i += 1;
56 BcStatus bc_lex_comment(BcLex *l) {
59 const char *buf = l->buf;
63 l->i += 1;
64 l->t = BC_LEX_WHITESPACE;
66 for (i = l->i; !end; i += !end) {
71 l->i = i;
72 return bc_lex_err(l, BC_ERROR_PARSE_COMMENT);
78 l->i = i + 2;
79 l->line += nlines;
84 void bc_lex_whitespace(BcLex *l) {
86 l->t = BC_LEX_WHITESPACE;
87 for (c = l->buf[l->i]; c != '\n' && isspace(c); c = l->buf[++l->i]);
90 void bc_lex_commonTokens(BcLex *l, char c) {
91 if (!c) l->t = BC_LEX_EOF;
92 else if (c == '\n') l->t = BC_LEX_NLINE;
93 else bc_lex_whitespace(l);
96 static size_t bc_lex_num(BcLex *l, char start, bool int_only) {
98 const char *buf = l->buf + l->i;
126 bc_vec_push(&l->str, &c);
132 BcStatus bc_lex_number(BcLex *l, char start) {
134 l->t = BC_LEX_NUMBER;
136 bc_vec_npop(&l->str, l->str.len);
137 bc_vec_push(&l->str, &start);
139 l->i += bc_lex_num(l, start, false);
143 char c = l->buf[l->i];
149 BcStatus s = bc_lex_err(l, BC_ERROR_POSIX_EXP_NUM);
154 bc_vec_push(&l->str, &c);
155 l->i += 1;
156 c = l->buf[l->i];
159 bc_vec_push(&l->str, &c);
160 l->i += 1;
161 c = l->buf[l->i];
165 return bc_lex_verr(l, BC_ERROR_PARSE_CHAR, c);
167 l->i += bc_lex_num(l, 0, true);
172 bc_vec_pushByte(&l->str, '\0');
177 void bc_lex_name(BcLex *l) {
180 const char *buf = l->buf + l->i - 1;
183 l->t = BC_LEX_NAME;
187 bc_vec_string(&l->str, i, buf);
190 l->i += i - 1;
193 void bc_lex_init(BcLex *l) {
194 assert(l != NULL);
195 bc_vec_init(&l->str, sizeof(char), NULL);
198 void bc_lex_free(BcLex *l) {
199 assert(l != NULL);
200 bc_vec_free(&l->str);
203 void bc_lex_file(BcLex *l, const char *file) {
204 assert(l != NULL && file != NULL);
205 l->line = 1;
209 BcStatus bc_lex_next(BcLex *l) {
213 assert(l != NULL);
215 l->last = l->t;
216 l->line += (l->i != 0 && l->buf[l->i - 1] == '\n');
218 if (BC_ERR(l->last == BC_LEX_EOF)) return bc_lex_err(l, BC_ERROR_PARSE_EOF);
220 l->t = BC_LEX_EOF;
222 if (l->i == l->len) return BC_STATUS_SUCCESS;
227 s = vm->next(l);
228 } while (BC_NO_ERR(!s) && l->t == BC_LEX_WHITESPACE);
233 BcStatus bc_lex_text(BcLex *l, const char *text) {
234 assert(l != NULL && text != NULL);
235 l->buf = text;
236 l->i = 0;
237 l->len = strlen(text);
238 l->t = l->last = BC_LEX_INVALID;
239 return bc_lex_next(l);