Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement yyset_interactive #291

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/flex.skl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ m4_ifelse(M4_YY_PREFIX,yy,,
M4_GEN_PREFIX(`get_text')
M4_GEN_PREFIX(`get_lineno')
M4_GEN_PREFIX(`set_lineno')
M4_GEN_PREFIX(`set_interactive')
m4_ifdef( [[M4_YY_REENTRANT]],
[[
M4_GEN_PREFIX(`get_column')
Expand Down Expand Up @@ -618,16 +619,8 @@ void yyfree ( void * M4_YY_PROTO_LAST_ARG );

m4_ifdef( [[M4_YY_NOT_IN_HEADER]],
[[

#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
if ( ! YY_CURRENT_BUFFER ){ \
yyensure_buffer_stack (M4_YY_CALL_ONLY_ARG); \
YY_CURRENT_BUFFER_LVALUE = \
yy_create_buffer( yyin, YY_BUF_SIZE M4_YY_CALL_LAST_ARG); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
}
#define yy_set_bol(at_bol) \
{ \
if ( ! YY_CURRENT_BUFFER ){\
Expand Down Expand Up @@ -849,6 +842,11 @@ m4_ifdef( [[M4_YY_NO_SET_IN]],,
void yyset_in ( FILE * _in_str M4_YY_PROTO_LAST_ARG );
]])

m4_ifdef( [[M4_YY_NO_SET_INTERACTIVE]],,
[[
void yyset_interactive (int is_interactive M4_YY_PROTO_LAST_ARG );
]])

m4_ifdef( [[M4_YY_NO_GET_OUT]],,
[[
FILE *yyget_out ( M4_YY_PROTO_ONLY_ARG );
Expand Down Expand Up @@ -2662,6 +2660,24 @@ void yyset_column YYFARGS1( int , _column_no)
]])
]])

m4_ifdef( [[M4_YY_NO_SET_INTERACTIVE]],,
[[
void yyset_interactive YYFARGS1(int, is_interactive)
{
M4_YY_DECL_GUTS_VAR();

m4_ifdef( [[M4_YY_REENTRANT]],
[[
if ( ! YY_CURRENT_BUFFER ) {
yyensure_buffer_stack (M4_YY_CALL_ONLY_ARG);
YY_CURRENT_BUFFER_LVALUE =
yy_create_buffer( yyin, YY_BUF_SIZE M4_YY_CALL_LAST_ARG);
}
]])

(YY_CURRENT_BUFFER_LVALUE)->yy_is_interactive = is_interactive;
}
]])

m4_ifdef( [[M4_YY_NO_SET_IN]],,
[[
Expand Down Expand Up @@ -2750,6 +2766,8 @@ void yyset_lloc YYFARGS1( YYLTYPE * ,yylloc_param)
]])
]])



%endif


Expand Down Expand Up @@ -3422,7 +3440,6 @@ m4_ifdef( [[M4_YY_IN_HEADER]],
#undef YY_FLUSH_BUFFER
#undef yy_set_bol
#undef yy_new_buffer
#undef yy_set_interactive
#undef YY_DO_BEFORE_ACTION

#ifdef YY_DECL_IS_OURS
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,10 @@ void flexinit (int argc, char **argv)
//buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1");
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0);
break;
case OPT_NO_YYSET_INTERACTIVE:
//buf_strdefine (&userdef_buf, "YY_NO_SET_INTERACTIVE", "1");
buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_INTERACTIVE",0);
break;
case OPT_HEX:
trace_hex = 1;
break;
Expand Down
2 changes: 2 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ optspec_t flexopts[] = {
,
{"--noyyset_lloc", OPT_NO_YYSET_LLOC, 0}
,
{"--noyyset_interactive", OPT_NO_YYSET_INTERACTIVE, 0}
,
{"--unsafe-no-m4-sect3-escape", OPT_NO_SECT3_ESCAPE, 0}
,
{0, 0, 0} /* required final NULL entry. */
Expand Down
1 change: 1 addition & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum flexopt_flag_t {
OPT_NO_YYSET_LINENO,
OPT_NO_YYSET_COLUMN,
OPT_NO_YYSET_LLOC,
OPT_NO_YYSET_INTERACTIVE,
OPT_NO_YYSET_LVAL,
OPT_NO_YYSET_OUT,
OPT_NO_YYWRAP,
Expand Down
1 change: 1 addition & 0 deletions src/scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ M4QEND "]""]"
yyset_lval ACTION_M4_IFDEF("M4""_YY_NO_SET_LVAL", ! option_sense);
yyget_lloc ACTION_M4_IFDEF("M4""_YY_NO_GET_LLOC", ! option_sense);
yyset_lloc ACTION_M4_IFDEF("M4""_YY_NO_SET_LLOC", ! option_sense);
yyset_interactive ACTION_M4_IFDEF("M4""_YY_NO_SET_INTERACTIVE", ! option_sense);

extra-type return TOK_EXTRA_TYPE;
outfile return TOK_OUTFILE;
Expand Down
4 changes: 3 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ simple_tests = \
string_nr \
string_r \
top \
yyextra
yyextra \
yyset_interactive

reject_tests = \
reject_nr.reject \
Expand Down Expand Up @@ -182,6 +183,7 @@ string_r_SOURCES = string_r.l
top_SOURCES = top.l top_main.c
nodist_top_SOURCES = top.h
yyextra_SOURCES = yyextra.l
yyset_interactive_SOURCES = yyset_interactive.l

# Normally, automake would distribute files built by flex. Since the
# point of the test suite is to test the files that flex builds, and
Expand Down
122 changes: 122 additions & 0 deletions tests/yyset_interactive.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* This file is part of flex.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/

%{
/* A file to build "scanner.c". */
/* This tests that we can use "yyextra".
We buffer all input into a growable array, then print it.
We run diff on the input and output.
*/

#include <stdio.h>
#include <stdlib.h>
#include "config.h"


/* We'll store the entire input in this buffer, growing as necessary. */
struct Buffer {
int curr_len;
int max_len;
int grow_len;
char * data;
};
#define YY_EXTRA_TYPE struct Buffer *

/* Save char into junk array at next position. */
static void append_char (char c, yyscan_t scanner );

%}

%option 8bit prefix="test"
%option nounput nomain noyywrap nodefault noinput
%option warn
%option reentrant


%%

.|\r|\n { append_char (yytext[0],yyscanner); }

%%

int main(void);

int
main (void)
{
yyscan_t scanner;
struct Buffer * buf;
int i;

buf = malloc(sizeof(struct Buffer));
buf->curr_len =0;
buf->max_len = 4;
buf->grow_len = 100;
buf->data = malloc((size_t) buf->max_len);

testlex_init(&scanner);
testset_in( stdin, scanner);
testset_interactive(0, scanner);
testset_out( stdout, scanner);
testset_extra( buf, scanner );
testlex(scanner);

buf = testget_extra(scanner);
for(i=0; i < buf->curr_len; i++)
fputc( buf->data[i], stdout );
free( buf->data);
free( buf);

testlex_destroy(scanner);
return 0;
}

/* Save char into junk array at next position. */
static void append_char (char c, yyscan_t scanner )
{
struct Buffer *buf, *new_buf;
buf = testget_extra(scanner);

/* Grow buffer if necessary. */

if( buf->curr_len >= buf->max_len )
{
new_buf = malloc(sizeof(struct Buffer));
new_buf->max_len = buf->max_len + buf->grow_len;
new_buf->grow_len = buf->grow_len;
new_buf->data = malloc((size_t) new_buf->max_len);
for( new_buf->curr_len = 0;
new_buf->curr_len < buf->curr_len;
new_buf->curr_len++ )
{
new_buf->data[ new_buf->curr_len] = buf->data [ new_buf->curr_len];
}
free( buf->data );
free( buf );
buf = new_buf;
testset_extra( buf, scanner );
}


buf->data[ buf->curr_len++ ] = c;
}