/* As lexer_read_until, but elements of char_set preceded by \ are ignored as stops. */ int lexer_read_escaped_until(struct lexer_book *bk, char *char_set) { char *char_set_slash = string_format("\\%s", char_set); int count = 0; do { count += lexer_read_until(bk, char_set_slash); if(!bk->eof && lexer_next_peek(bk) == '\\') { lexer_next_char(bk); /* Jump the slash */ char c = lexer_next_char(bk); count += 2; if(lexer_next_peek(bk) != CHAR_EOF) lexer_add_to_lexeme(bk, c); } else break; } while(!bk->eof); free(char_set_slash); if(bk->eof && !strchr(char_set, CHAR_EOF)) lexer_report_error(bk, "Missing %s\n", char_set); return count; }
struct token *lexer_read_literal_in_expandable_until(struct lexer_book *bk, char end_marker) { char end_markers[7] = { end_marker, '$', '\\', '"', '\'', '#', CHAR_EOF }; int count = 0; do { count += lexer_read_until(bk, end_markers); if(bk->eof) break; char c = lexer_next_peek(bk); if(c == '\\') { lexer_next_char(bk); /* Jump the slash */ char n = lexer_next_char(bk); count += 2; if(lexer_special_escape(n)) lexer_add_to_lexeme(bk, lexer_special_to_code(n)); else lexer_add_to_lexeme(bk, n); } else if(c == '#') { if(end_marker == '\n') { lexer_discard_comments(bk); break; } } else break; } while(!bk->eof); if(bk->eof && strchr(")\"'", end_marker)) lexer_report_error(bk, "Missing closing %c.\n", end_marker); return lexer_pack_token(bk, LITERAL); }
struct token *lexer_read_syntax_name(struct lexer_book *bk) { int count; count = lexer_read_until(bk, SYNTAX_LIMITS); if(count < 1) lexer_report_error(bk, "Expecting a keyword or a variable name."); return lexer_pack_token(bk, LITERAL); }
struct token *lexer_read_literal_in_expandable_until(struct lexer *lx, char end_marker) { const char end_markers[8] = { end_marker, '$', '\\', '"', '\'', '#', CHAR_EOF ,0}; int count = 0; do { count += lexer_read_until(lx, end_markers); if(lx->eof) break; char c = lexer_next_peek(lx); if(c == '\\') { lexer_next_char(lx); /* Jump the slash */ char n = lexer_next_char(lx); count += 2; if(lexer_special_escape(n)) { lexer_add_to_lexeme(lx, lexer_special_to_code(n)); } else if(n == '\n') { lexer_add_to_lexeme(lx, ' '); } else { lexer_add_to_lexeme(lx, n); } } else if(c == '#') { if(end_marker == '\n') { lexer_discard_comments(lx); break; } } else break; } while(!lx->eof); if(lx->eof && strchr(")\"'", end_marker)) lexer_report_error(lx, "Missing closing %c.\n", end_marker); return lexer_pack_token(lx, TOKEN_LITERAL); }