Buffer state stack and yy_scan_string

[email protected] (Carlos Sánchez de La Lama) Thu, 28 Feb 2013 09:55:27 +0100
Newsgroups gmane.comp.lex.flex.general
Message-ID <[email protected]>
Hi all,

I am trying to use yy_scan_string on a program which also uses buffer
state stacks ({yypush, yypop}_buffer_state). According to the
documentation, yy_scan_string switches current buffer so a string is
parsed, but my desired behaviour is to get back to parsing the file
(using yypop?) once the string has been parsed.

I have seen some references on the web to using

yypush_buffer_state(yy_parse_string(...))

but I have noticed the inner yy_parse_string subsitutes the current
buffer state, which then gets pushed, and the original state gets lost
(no way to get back to file parsing).

The solution I have found is a little bit weird:

yypush_buffer_state (YY_CURRENT_BUFFER);
yy_scan_string (m.definition.c_str());

Thus first the *current* state is pushed (effectively creating a copy),
but then the yy_scan_string changes current buffer to the string.

It works, but just wanted to ask if somebody knows a better way to do
it.

Thanks!

Carlos