libexpr: Get rid of unused line tracking fields

This commit is contained in:
Robert Hensing 2024-07-11 12:58:20 +02:00
parent f9243eca75
commit 77e9f9ee82
4 changed files with 18 additions and 6 deletions

View file

@ -4,7 +4,6 @@
void nix::lexer::internal::initLoc(YYLTYPE * loc) void nix::lexer::internal::initLoc(YYLTYPE * loc)
{ {
loc->first_line = loc->last_line = 0;
loc->first_column = loc->last_column = 0; loc->first_column = loc->last_column = 0;
} }

View file

@ -287,7 +287,6 @@ or { return OR_KW; }
\/\*\*[^/*]([^*]|\*+[^*/])*\*+\/ /* doc comments */ { \/\*\*[^/*]([^*]|\*+[^*/])*\*+\/ /* doc comments */ {
LexerState & lexerState = *yyget_extra(yyscanner); LexerState & lexerState = *yyget_extra(yyscanner);
lexerState.docCommentDistance = 0; lexerState.docCommentDistance = 0;
lexerState.lastDocCommentLoc.first_line = yylloc->first_line;
lexerState.lastDocCommentLoc.first_column = yylloc->first_column; lexerState.lastDocCommentLoc.first_column = yylloc->first_column;
lexerState.lastDocCommentLoc.last_column = yylloc->last_column; lexerState.lastDocCommentLoc.last_column = yylloc->last_column;
} }

View file

@ -22,8 +22,8 @@ struct StringToken
struct ParserLocation struct ParserLocation
{ {
int first_line, first_column; int first_column;
int last_line, last_column; int last_column;
// backup to recover from yyless(0) // backup to recover from yyless(0)
int stashed_first_column, stashed_last_column; int stashed_first_column, stashed_last_column;
@ -39,7 +39,7 @@ struct ParserLocation
} }
/** Latest doc comment position, or 0. */ /** Latest doc comment position, or 0. */
int doc_comment_first_line, doc_comment_first_column, doc_comment_last_column; int doc_comment_first_column, doc_comment_last_column;
}; };
struct LexerState struct LexerState

View file

@ -31,6 +31,21 @@
#define YY_DECL int yylex \ #define YY_DECL int yylex \
(YYSTYPE * yylval_param, YYLTYPE * yylloc_param, yyscan_t yyscanner, nix::ParserState * state) (YYSTYPE * yylval_param, YYLTYPE * yylloc_param, yyscan_t yyscanner, nix::ParserState * state)
// For efficiency, we only track offsets; not line,column coordinates
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
} \
else \
{ \
(Current).first_column = (Current).last_column = \
YYRHSLOC (Rhs, 0).last_column; \
} \
while (0)
namespace nix { namespace nix {
typedef std::map<PosIdx, DocComment> DocCommentMap; typedef std::map<PosIdx, DocComment> DocCommentMap;
@ -69,7 +84,6 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParserState * state, const char *
{ {
if (std::string_view(error).starts_with("syntax error, unexpected end of file")) { if (std::string_view(error).starts_with("syntax error, unexpected end of file")) {
loc->first_column = loc->last_column; loc->first_column = loc->last_column;
loc->first_line = loc->last_line;
} }
throw ParseError({ throw ParseError({
.msg = HintFmt(error), .msg = HintFmt(error),