diff --git a/libs/ast/include/pslang/ast/location.hpp b/libs/ast/include/pslang/ast/location.hpp index 93fbe46..34813ec 100644 --- a/libs/ast/include/pslang/ast/location.hpp +++ b/libs/ast/include/pslang/ast/location.hpp @@ -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; diff --git a/libs/parser/rules/pslang.l b/libs/parser/rules/pslang.l index d485563..2d859e9 100644 --- a/libs/parser/rules/pslang.l +++ b/libs/parser/rules/pslang.l @@ -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); }