summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2020-11-09 04:26:56 -0500
committerEric S. Raymond <esr@thyrsus.com>2020-11-09 04:26:56 -0500
commitaa782b6233e0914591b0e967d1662449744e9497 (patch)
tree36c1b8b5784e959e40440b712dc0f610378da586
parent2995af0eeb3792506f2b9975788443f67ac4b389 (diff)
downloadflex-git-aa782b6233e0914591b0e967d1662449744e9497.tar.gz
Explain why 3 API functions don't have magic rewrite rules.
The functions are: yy_current_buffer(), yy_flush_current_buffer(), and yy_set_interactive().
-rw-r--r--doc/flex.texi9
-rw-r--r--src/c99-flex.skl96
2 files changed, 57 insertions, 48 deletions
diff --git a/doc/flex.texi b/doc/flex.texi
index 7a52029..0457279 100644
--- a/doc/flex.texi
+++ b/doc/flex.texi
@@ -9041,6 +9041,15 @@ complain about uppercase or underscores or both. It would obviously be best
if the parts of the public API that have to change to conform to
local conventions are small and not commonly used.
+This is also why the functions @code{yy_current_buffer()},
+@code{yy_flush_current_buffer()}, and @code{yy_set_interactive()}
+do not have rewrite rules (see @xref{option-rewrite}); simply
+removing the underscores would have produced names that are
+unncomfortably long and hard on the eyeballs. We leave
+it to the API binding for each individual target language to
+choose whether they should be left as is, camel-cased, or
+otherwise adapted to local conventions.
+
@node Indices, , Appendices, Top
@unnumbered Indices
diff --git a/src/c99-flex.skl b/src/c99-flex.skl
index 3dbdc8d..c2caad1 100644
--- a/src/c99-flex.skl
+++ b/src/c99-flex.skl
@@ -1087,6 +1087,32 @@ static void yy_lineno_rewind_to(char *yy_cp, char *dst, yyscan_t yyscanner) {
}
]])
+/* Returns the top of the stack, or NULL. */
+yybuffer yy_current_buffer(yyscan_t yyscanner) {
+ return ( yyscanner->yy_buffer_stack \
+ ? yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] \
+ : NULL);
+}
+
+void yy_flush_current_buffer(yyscan_t yyscanner) {
+ yy_flush_buffer( yy_current_buffer(yyscanner), yyscanner);
+}
+
+void yy_set_interactive(bool is_interactive, yyscan_t yyscanner) {
+ if ( yy_current_buffer(yyscanner) == NULL ) {
+ yyensure_buffer_stack (yyscanner);
+ yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] =
+ yy_create_buffer( yyscanner->yyin_r, YY_BUF_SIZE, yyscanner);
+ }
+ yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->yy_is_interactive = is_interactive;
+}
+
+
+static void yybumpline( yyscan_t yyscanner) {
+ yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->yy_bs_lineno++;
+ yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->yy_bs_column=0;
+}
+
/* START access macros for use in actions */
#define yyin yyscanner->yyin_r
@@ -1098,32 +1124,6 @@ static void yy_lineno_rewind_to(char *yy_cp, char *dst, yyscan_t yyscanner) {
#define yycolumn (yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->yy_bs_column)
#define yyflexdebug yyscanner->yyflexdebug_r
-static void yybumpline( yyscan_t yyscanner) {
- yylineno++;
- yycolumn=0;
-}
-
-/* We provide macros for accessing buffer states in case in the
- * future we want to put the buffer states in a more general
- * "scanner state".
- *
- * Returns the top of the stack, or NULL.
- */
-#define yy_current_buffer() ( yyscanner->yy_buffer_stack \
- ? yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] \
- : NULL)
-
-#define yy_flush_current_buffer() yy_flush_buffer( yy_current_buffer(), yyscanner)
-
-#define yy_set_interactive(is_interactive) { \
- if ( yy_current_buffer() == NULL ) { \
- yyensure_buffer_stack (yyscanner); \
- yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] = \
- yy_create_buffer( yyscanner->yyin_r, YY_BUF_SIZE, yyscanner); \
- } \
- yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->yy_is_interactive = is_interactive; \
-}
-
/* END access macros for use in actions */
m4_ifdef([[M4_MODE_YYMORE_USED]], [[
@@ -1149,7 +1149,7 @@ m4_define([[YY_RESTORE_YY_MORE_OFFSET]], [[]])
]])
void yysetbol(bool at_bol, yyscan_t yyscanner) {
- if ( yy_current_buffer() == NULL ) {
+ if ( yy_current_buffer(yyscanner) == NULL ) {
yyensure_buffer_stack (yyscanner);
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] =
yy_create_buffer( yyscanner->yyin_r, YY_BUF_SIZE, yyscanner);
@@ -1293,7 +1293,7 @@ m4_ifdef( [[M4_MODE_USES_REJECT]],
if ( yyscanner->yyout_r == NULL ) {
yyscanner->yyout_r = stdout;
}
- if ( yy_current_buffer() == NULL ) {
+ if ( yy_current_buffer(yyscanner) == NULL ) {
yyensure_buffer_stack (yyscanner);
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] =
yy_create_buffer( yyscanner->yyin_r, YY_BUF_SIZE, yyscanner);
@@ -1506,7 +1506,7 @@ m4_ifdef([[M4_MODE_HAS_BACKING_UP]], [[
* possible that this happened because the user
* just pointed yyin at a new source and called
* yylex(). If so, then we have to assure
- * consistency between yy_current_buffer() and our
+ * consistency between yy_current_buffer(yyscanner) and our
* globals. Here is the right place to do so, because
* this is the first action (other than possibly a
* back-up) that will match for the new input source.
@@ -1883,13 +1883,13 @@ m4_ifdef([[M4_MODE_NULTRANS_WRAP]], [[
void yyrestart(FILE * input_file, yyscan_t yyscanner)
{
- if ( yy_current_buffer() == NULL ) {
+ if ( yy_current_buffer(yyscanner) == NULL ) {
yyensure_buffer_stack (yyscanner);
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] =
yy_create_buffer( yyscanner->yyin_r, YY_BUF_SIZE, yyscanner);
}
- yy_init_buffer( yy_current_buffer(), input_file, yyscanner);
+ yy_init_buffer( yy_current_buffer(yyscanner), input_file, yyscanner);
yy_load_buffer_state( yyscanner );
}
@@ -1906,10 +1906,10 @@ void yy_switch_to_buffer(yybuffer new_buffer, yyscan_t yyscanner)
* yypush_buffer_state(new_buffer);
*/
yyensure_buffer_stack (yyscanner);
- if ( yy_current_buffer() == new_buffer ) {
+ if ( yy_current_buffer(yyscanner) == new_buffer ) {
return;
}
- if ( yy_current_buffer() ) {
+ if ( yy_current_buffer(yyscanner) ) {
/* Flush out information for old buffer. */
*yyscanner->yy_c_buf_p = yyscanner->yy_hold_char;
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->yy_buf_pos = yyscanner->yy_c_buf_p;
@@ -1976,7 +1976,7 @@ void yy_delete_buffer(yybuffer b, yyscan_t yyscanner)
if ( b == NULL ) {
return;
}
- if ( b == yy_current_buffer() ) { /* Not sure if we should pop here. */
+ if ( b == yy_current_buffer(yyscanner) ) { /* Not sure if we should pop here. */
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] = (yybuffer) 0;
}
if ( b->yy_is_our_buffer ) {
@@ -2003,7 +2003,7 @@ static void yy_init_buffer(yybuffer b, FILE * file, yyscan_t yyscanner)
* called from yyrestart() or through yy_get_next_buffer.
* In that case, we don't want to reset the lineno or column.
*/
- if (b != yy_current_buffer()) {
+ if (b != yy_current_buffer(yyscanner)) {
b->yy_bs_lineno = 1;
b->yy_bs_column = 0;
}
@@ -2025,7 +2025,7 @@ m4_ifdef( [[M4_YY_ALWAYS_INTERACTIVE]],
}
/** Discard all buffered characters. On the next scan, yyread() will be called.
- * @param b the buffer state to be flushed, usually @c yy_current_buffer().
+ * @param b the buffer state to be flushed, usually @c yy_current_buffer(yyscanner).
* @param yyscanner The scanner object.
*/
void yy_flush_buffer(yybuffer b, yyscan_t yyscanner)
@@ -2047,7 +2047,7 @@ void yy_flush_buffer(yybuffer b, yyscan_t yyscanner)
b->yyatbol_flag = true;
b->yy_buffer_status = YY_BUFFER_NEW;
- if ( b == yy_current_buffer() ) {
+ if ( b == yy_current_buffer(yyscanner) ) {
yy_load_buffer_state( yyscanner );
}
}
@@ -2066,7 +2066,7 @@ void yypush_buffer_state(yybuffer new_buffer, yyscan_t yyscanner)
yyensure_buffer_stack(yyscanner);
/* This block is copied from yy_switch_to_buffer. */
- if ( yy_current_buffer() != NULL ) {
+ if ( yy_current_buffer(yyscanner) != NULL ) {
/* Flush out information for old buffer. */
*yyscanner->yy_c_buf_p = yyscanner->yy_hold_char;
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top]->yy_buf_pos = yyscanner->yy_c_buf_p;
@@ -2074,7 +2074,7 @@ void yypush_buffer_state(yybuffer new_buffer, yyscan_t yyscanner)
}
/* Only push if top exists. Otherwise, replace top. */
- if (yy_current_buffer()) {
+ if (yy_current_buffer(yyscanner)) {
yyscanner->yy_buffer_stack_top++;
}
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] = new_buffer;
@@ -2091,15 +2091,15 @@ void yypush_buffer_state(yybuffer new_buffer, yyscan_t yyscanner)
*/
void yypop_buffer_state (yyscan_t yyscanner)
{
- if (yy_current_buffer() == NULL) {
+ if (yy_current_buffer(yyscanner) == NULL) {
return;
}
- yy_delete_buffer(yy_current_buffer(), yyscanner);
+ yy_delete_buffer(yy_current_buffer(yyscanner), yyscanner);
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] = NULL;
if (yyscanner->yy_buffer_stack_top > 0) {
--yyscanner->yy_buffer_stack_top;
}
- if (yy_current_buffer() != NULL) {
+ if (yy_current_buffer(yyscanner) != NULL) {
yy_load_buffer_state( yyscanner );
yyscanner->yy_did_buffer_switch_on_eof = true;
}
@@ -2326,7 +2326,7 @@ m4_ifdef( [[M4_YY_NO_GET_LINENO]],,
*/
int yyget_lineno (yyscan_t yyscanner) {
- if (yy_current_buffer() == NULL) {
+ if (yy_current_buffer(yyscanner) == NULL) {
return 0;
}
return yylineno;
@@ -2340,7 +2340,7 @@ m4_ifdef( [[M4_YY_NO_GET_COLUMN]],,
*/
int yyget_column (yyscan_t yyscanner) {
- if (yy_current_buffer() == NULL) {
+ if (yy_current_buffer(yyscanner) == NULL) {
return 0;
}
return yycolumn;
@@ -2409,7 +2409,7 @@ m4_ifdef( [[M4_YY_NO_SET_LINENO]],,
void yyset_lineno(int _line_number, yyscan_t yyscanner) {
/* lineno is only valid if an input buffer exists. */
- if (yy_current_buffer() == NULL ) {
+ if (yy_current_buffer(yyscanner) == NULL ) {
yypanic( "yyset_lineno called with no buffer", yyscanner );
}
yylineno = _line_number;
@@ -2425,7 +2425,7 @@ m4_ifdef( [[M4_YY_NO_SET_COLUMN]],,
void yyset_column(int _column_no, yyscan_t yyscanner) {
/* column is only valid if an input buffer exists. */
- if (yy_current_buffer() == NULL ) {
+ if (yy_current_buffer(yyscanner) == NULL ) {
yypanic( "yyset_column called with no buffer", yyscanner );
}
yycolumn = _column_no;
@@ -2603,8 +2603,8 @@ m4_ifdef( [[M4_MODE_YYTEXT_IS_ARRAY]],
int yylex_destroy (yyscan_t yyscanner) {
/* Pop the buffer stack, destroying each element. */
- while(yy_current_buffer()) {
- yy_delete_buffer( yy_current_buffer(), yyscanner );
+ while(yy_current_buffer(yyscanner)) {
+ yy_delete_buffer( yy_current_buffer(yyscanner), yyscanner );
yyscanner->yy_buffer_stack[yyscanner->yy_buffer_stack_top] = NULL;
yypop_buffer_state(yyscanner);
}