diff --git a/lapis.c b/lapis.c index c3b55ca..78cd9e8 100644 --- a/lapis.c +++ b/lapis.c @@ -81,8 +81,12 @@ lapis_token_t *lapis_parse_tokens(size_t *ntokens, FILE *f) { lapis_token_t *tokens = NULL; lapis_token_t tmptok = { .type = LAPIS_TTYPE_NONE, .str = NULL, .len = 0 }; + _Bool end_of_expression = false; + int c; - while ( (c = fgetc(f)) != EOF ) { + while ( (c = fgetc(f)) != EOF && !end_of_expression ) { + + _Bool in_escape = false; // skip over comments if ( c == '#' ) { @@ -90,6 +94,18 @@ lapis_token_t *lapis_parse_tokens(size_t *ntokens, FILE *f) { if ( c == EOF ) break; } + // detect line escapes + if ( c == '\\' ) { + in_escape = true; + c = fgetc(f); + if ( c == EOF ) break; + } + + if ( c == ';' || (!in_escape && c == '\n') ) { + c = ' '; + if ( num_tokens ) end_of_expression = true; + } + enum lapis_ttype cur_ttype; if ( (tmptok.type == LAPIS_TTYPE_IDENT && isdigit(c)) || isalpha(c) || c == '_' ) {