implement line comments

This commit is contained in:
tocariimaa 2025-01-31 21:46:28 -03:00
parent 9e592c57d7
commit 873b691ca0

View file

@ -190,6 +190,19 @@ read_chr(LexState *ls)
return Some(MaybeChr, *ls->fwd++); return Some(MaybeChr, *ls->fwd++);
} }
static MaybeChr
skip_line_comment(LexState *ls)
{
MaybeChr c;
do {
c = read_chr(ls);
if (!c.ok)
break;
++ls->lbegin;
} while (c.val != '\n');
return c;
}
static MaybeChr static MaybeChr
skip_whitespace(LexState *ls) skip_whitespace(LexState *ls)
{ {
@ -203,7 +216,9 @@ skip_whitespace(LexState *ls)
for (;;) { for (;;) {
c = read_chr(ls); c = read_chr(ls);
if (!c.ok) if (!c.ok)
return None(MaybeChr); break;
if (c.val == '/' && peek(ls) == '/')
c = skip_line_comment(ls);
if (!ascii_isspace(c.val)) if (!ascii_isspace(c.val))
break; break;
++ls->lbegin; ++ls->lbegin;