fix(lexer): $# and backslash implemented (partial version)

This commit is contained in:
matteo 2026-01-23 20:11:21 +01:00
parent 0c80663d7c
commit e853249fbf
3 changed files with 15 additions and 11 deletions

View file

@ -178,12 +178,19 @@ static bool is_end_of_line(char c)
return c == EOF || c == '\n';
}
bool is_special_char(char c)
bool is_special_char(char *stream, ssize_t i)
{
char c = stream[i];
if (c == EOF)
return true;
if (i > 0 && c == '#' && stream[i - 1] == '$')
return false; // the edge case of $#
if (i > 0 && stream[i - 1] == '\\')
return false; // TODO handle backslash better
// this doesnt work, ex : echo \\#comment
// (need to count the previous consequtive backslashes)
char special_chars[] = "\n'\"`;#|&\\(){}<>*";
char special_chars[] = "\n'\"`;#|&(){}<>*";
return strchr(special_chars, c) != NULL;
}
@ -247,7 +254,7 @@ void stream_init(struct lexer_context *ctx)
ssize_t len_op_sepchar(char *stream, ssize_t i)
{
if (!is_special_char(stream[i]))
if (!is_special_char(stream, i))
return -1; // should never happen
if (stream[i] != '>' && stream[i] != '<')