Support multiline comments

This commit is contained in:
Nikita Lisitsa 2026-08-05 14:47:53 +03:00
parent 26b0e6771d
commit e0bc4a361d
2 changed files with 16 additions and 1 deletions

View file

@ -37,6 +37,16 @@ namespace pslang::ast
end.column = add(end.column, count, 1);
}
void advance(char const * begin, char const * end)
{
for (; begin != end; ++begin) {
if (*begin == '\n')
move_lines(1);
else
move_columns(1);
}
}
static std::size_t add(std::size_t lhs, std::size_t rhs, std::size_t min)
{
return lhs + rhs < min ? min : lhs + rhs;

View file

@ -21,7 +21,12 @@ using bp = ::pslang::parser::bison::parser;
[ \r\t]+ { ctx.location.step(); }
"//"[^\n]* { ctx.location.step(); }
"//".* ;
"/*"([^*]|\*+[^*/])*\*+"/" {
ctx.location.move_columns(-yyleng);
ctx.location.advance(yytext, yytext + yyleng);
ctx.location.step();
}
const { return bp::make_const(ctx.location); }
let { return bp::make_let(ctx.location); }