westes / flex

The Fast Lexical Analyzer - scanner generator for lexing in C and C++
Other
3.6k stars 538 forks source link

Inconsistent handling of in memory buffers compared to file buffers #611

Open ogdenpm opened 11 months ago

ogdenpm commented 11 months ago

Although flex supports yypush_buffer_state for managing nested include files, this cannot be used consistently for in memory files.

Specifically yy_scan_buffer(), uses yy_switch_to_buffer(), which overwrites the top buffer state, this forces managing of in memory files in separate stack, with specific handling also in <>.

As a suggestion replacing the call to yy_switch_to_buffer() with yypush_buffer_state(), would allow consistent usage of a common stack for all buffers. An alternative, which would be more consistent with the file buffers, would be to remove the yy_switch_to_buffer() and get the user to use yypush_buffer_state() explicitly.

I haven't submitted a pull request as the changes could break existing code, although this could be managed by a suitable conditional control.