Genivia / RE-flex

A high-performance C++ regex library and lexical analyzer generator with Unicode support. Extends Flex++ with Unicode support, indent/dedent anchors, lazy quantifiers, functions for lex and syntax error reporting and more. Seamlessly integrates with Bison and other parsers.
https://www.genivia.com/doc/reflex/html
BSD 3-Clause "New" or "Revised" License
504 stars 85 forks source link

RE-flex not generating FSM transitions when outfile has cxx extension. #163

Closed SouravKB closed 1 year ago

SouravKB commented 1 year ago

RE-flex tool is not generating FSM transitions when outfile has cxx transitions. I'm not sure whether this is intended behavior. But in documentation, I didn't find this being mentioned.

Steps to reproduce:

  1. Write a valid lex program.
  2. Add line %o outfile=lex.cxx.
  3. RE-flex tool will now leave TABLES part empty in the generated output.
genivia-inc commented 1 year ago

Indeed, only .hpp, .cpp and .cc are recognized filename extensions at this time. This is decided in lib/pattern.cpp function gencode_dfa.

Should we add .cxx as well as upper case versions like .CPP, .CC and .CXX?

genivia-inc commented 1 year ago

lib/pattern.cpp:2812 gencode_dfa change to:

    if ((len > 2 && filename.compare(len - 2, 2, ".h"  ) == 0)
     || (len > 3 && filename.compare(len - 3, 3, ".hh" ) == 0)
     || (len > 4 && filename.compare(len - 4, 4, ".hpp") == 0)
     || (len > 4 && filename.compare(len - 4, 4, ".hxx") == 0)
     || (len > 3 && filename.compare(len - 3, 3, ".cc" ) == 0)
     || (len > 4 && filename.compare(len - 4, 4, ".cpp") == 0)
     || (len > 4 && filename.compare(len - 4, 4, ".cxx") == 0))
SouravKB commented 1 year ago

I don't want to use .cxx in particular. However, if this is the case, it should probably mentioned in the documentation explicitly. I had to spend time in-order to figure out why reflex suddenly stopped generating tables without giving any warnings or errors.

Note that, GCC recognizes .cc, .C, .cp, .cpp, .CPP, .cxx, .c++ file extensions as C++ source file & .h, .hh, .H, .hp, .hpp, .HPP, .hxx, .h++, .tcc file extensions as C++ header file.

SouravKB commented 1 year ago

My personal suggestion is that, if user is allowed to specify the filename, then let user use whatever extension he wants. Why constrain that. If you want, you may generate a warning instead.

genivia-inc commented 1 year ago

Nope. There are cases where we want to generate a graphviz file with extension .gv, i.e. extensions affect the type of output produced.