Skip to content

Commit

Permalink
Merge pull request #89 from dnicolodi/set-lineno
Browse files Browse the repository at this point in the history
Fix yyset_lineno() Flex compatibility wrappers
  • Loading branch information
genivia-inc authored Sep 20, 2020
2 parents 1159506 + 817c6e4 commit 9877c59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/reflex/abslexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ class AbstractLexer {
{
return matcher().lineno();
}
/// Set or change the starting line number of the last match.
inline void lineno(size_t n)
{
matcher().lineno(n);
}
/// Returns the number of lines that the match spans.
inline size_t lines() const
/// @returns number of lines
Expand Down
2 changes: 1 addition & 1 deletion include/reflex/flexlexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ int yywrap(void);
#define yyget_lineno(s) static_cast<int>(static_cast<FlexLexer*>(s)->lineno())

/// Flex-compatible macro: set the lineno accessor of a reentrant scanner.
#define yyset_lineno(n,s) static_cast<int>(static_cast<FlexLexer*>(s)->lineno(n))
#define yyset_lineno(n,s) static_cast<FlexLexer*>(s)->lineno(n)

/// Flex-compatible macro: the reflex::Input in accessor of a reentrant scanner.
#define yyget_in(s) static_cast<FlexLexer*>(s)->in()
Expand Down
7 changes: 7 additions & 0 deletions src/reflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,7 @@ void Reflex::write()
"YY_EXTERN_C char *" << prefix << "get_text(yyscan_t);\n"
"YY_EXTERN_C yy_size_t " << prefix << "get_leng(yyscan_t);\n"
"YY_EXTERN_C int " << prefix << "get_lineno(yyscan_t);\n"
"YY_EXTERN_C void " << prefix << "set_lineno(int, yyscan_t);\n"
"YY_EXTERN_C FILE *" << prefix << "get_in(yyscan_t);\n"
"YY_EXTERN_C void " << prefix << "set_in(FILE*, yyscan_t);\n"
"YY_EXTERN_C int " << prefix << "get_debug(yyscan_t);\n"
Expand Down Expand Up @@ -2626,6 +2627,12 @@ void Reflex::write_lexer()
" return static_cast<yyscanner_t*>(scanner)->lineno();\n"
"}\n"
"\n"
"#undef " << prefix << "set_lineno\n"
"YY_EXTERN_C void " << prefix << "set_lineno(int n, yyscan_t scanner)\n"
"{\n"
" static_cast<yyscanner_t*>(scanner)->lineno(n);\n"
"}\n"
"\n"
"#undef " << prefix << "get_in\n"
"YY_EXTERN_C FILE *" << prefix << "get_in(yyscan_t scanner)\n"
"{\n"
Expand Down

0 comments on commit 9877c59

Please sign in to comment.