Two naive questions #4668
Unanswered
mk-solidat
asked this question in
Q&A
Replies: 2 comments 1 reply
-
And while we're at it... Wouldn't it be kinda nice if - in this example - we had exact method signatures like template<typename Result>
class GrammarTypeidentifierParserVisitor
{
protected:
virtual Result visit1(const SCALARTYPE & arg0) = 0;
virtual Result visit2(const IDENTIFIER & arg0) = 0;
virtual Result visit3(const typeidentifier & arg0, const std::vector<std::tuple<X_MIN, typeidentifier>> & arg1) = 0;
virtual Result visit4(const typeidentifier & arg0, const ARROW & arg1, const typeidentifier & arg1) = 0;
public:
Result visit(const typeidentifier & ctx)
{
// generated code will safely unwrap the and call the relevant overload
// or better still, typeidentifier might be (or contain) a std::variant containing all the relevant data directly
}
}; |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can get a visitor method for each alt in the rule, but you need to use alt labeling.
Then, the Antlr Tool will generate:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there,
I'm new to ANTLR and parsing in general, so I apologize if the following two questions sound naive.
What antlr seems to do then (at least in c++) is to generate a visitor class with a method to visit
typeidentifier
.Question: why don't I get a class just to visit typeidentifier and a method for each possible pattern? That would allow me to be way more specific in what I return when I see a typeidentifier and what I get for each method. Also, it would break if I change the grammar (eg add a pattern for typeidentifier) - which seems desirable.
Beta Was this translation helpful? Give feedback.
All reactions