yhirose / cpp-peglib

A single file C++ header-only PEG (Parsing Expression Grammars) library
MIT License
916 stars 113 forks source link

Providing a base class to AstBase throws exception. #271

Closed gamagan closed 1 year ago

gamagan commented 1 year ago

Checkout [#d9dfc5b] of 2023.3.15 (latest, as of this post)

The following works:

using SharedAst = std::shared_ptr<peg::AstBase<peg::EmptyType>>; // peg::Ast
SharedAst ast;
parser.parse(code, ast);

The following throws a std:bad_any_cast.

struct AstDecor {
    bool mFoobar = false;
};
using SharedAst = std::shared_ptr<peg::AstBase<AstDecor>>;
SharedAst ast;
parser.parse(code, ast);

The error is thrown at this location: image

yhirose commented 1 year ago

@gamagan thanks for the feedback. Here is a workable example. Hope it helps!

https://github.com/yhirose/cpp-peglib/blob/17e069fbc5630300dfcdd017846662b77fb65ae8/test/test1.cc#L403-L418