LPeter1997 / CppCmb

A generic C++17 parser-combinator library with a natural grammar notation.
MIT License
122 stars 8 forks source link

Better compiler error messages #4

Open Cthaeeh opened 5 years ago

Cthaeeh commented 5 years ago

Hi, I don't know if its possible but maybe this can be somehow handled better:

If I have a grammar rule like so:

cppcmb_def(expr) = pc::pass
                   | (expr & match<Token::PLUS> & primary) [BinaryExpr::make]
                   | (expr & match<Token::MINUS> & primary) [BinaryExpr::make]
                   | primary
                   %= pc::as_memo_d;

And the method looks like this:

class BinaryExpr: public Expr {
       static ExprPtr  make(ExprPtr left_ ,ExprPtr right_ , Token op_ )
}

Can we have better error messages, that indicate what was wrong?

LPeter1997 commented 5 years ago

Hi! Thank you for your input. I'm aware of this issue and I'm trying to find a way to improve errors - with partial success so far. I'm sure you are aware of how to actually reorder your parameters to fix your issue:

(expr & match<Token::PLUS> & primary) [pc::select<0, 2, 1>] [BinaryExpr::make]

Improved error messages are very important and I'd like to improve them as soon as I can.