amykyta3 / speedy-antlr-tool

Generate an accelerator extension that makes your Antlr parser in Python super-fast!
BSD 3-Clause "New" or "Revised" License
29 stars 7 forks source link

Compilation failure with ANTLR 4.10 #15

Closed Infernio closed 2 years ago

Infernio commented 2 years ago

ANTLR 4.10 switched to std::any, which seems to be causing these compilation failures:

src/grammar/cpp/sa_zoia_cpp_parser.cpp: In function ‘PyObject* do_parse(PyObject*, PyObject*)’:
src/grammar/cpp/sa_zoia_cpp_parser.cpp:100:44: error: ‘class std::any’ has no member named ‘as’
  100 |         result = visitor.visit(parse_tree).as<PyObject *>();
      |                                            ^~
src/grammar/cpp/sa_zoia_cpp_parser.cpp:100:56: error: expected primary-expression before ‘*’ token
  100 |         result = visitor.visit(parse_tree).as<PyObject *>();
      |                                                        ^
src/grammar/cpp/sa_zoia_cpp_parser.cpp:100:57: error: expected primary-expression before ‘>’ token
  100 |         result = visitor.visit(parse_tree).as<PyObject *>();
      |                                                         ^
src/grammar/cpp/sa_zoia_cpp_parser.cpp:100:59: error: expected primary-expression before ‘)’ token
  100 |         result = visitor.visit(parse_tree).as<PyObject *>();
      |                                                           ^

I altered the generated files manually to fix this for now, replacing the as() calls with std::any_casts, but I'm not a C++ expert so I have no idea if that's the right fix :woman_shrugging:

amykyta3 commented 2 years ago

Yep thats the correct fix. Heres a diff of a patch I made when experimenting with the new release in a different project: https://github.com/SystemRDL/systemrdl-compiler/commit/d3e31c366fc938fee96b60811216705f5635c29a I just haven't had the chance to port it over to this tool yet.

Also, you'll have to adjust the setup.py to use C++17: https://github.com/SystemRDL/systemrdl-compiler/blob/dev/antlr-4.10.1/setup.py#L32-L35

goodwanghan commented 2 years ago

I also just encountered this issue, I will add this fix to my branch

goodwanghan commented 2 years ago

The change is included in https://github.com/amykyta3/speedy-antlr-tool/pull/13 And I confirm they are the only things to change to use 4.10, which makes the C++ version even faster.

amykyta3 commented 2 years ago

Fixed