satya-das / cppparser

A library to parse C/C++ source as AST
Other
278 stars 36 forks source link

Error handling #6

Closed BlueCannonBall closed 2 years ago

BlueCannonBall commented 2 years ago

Is there a way to customize syntax error messages?

satya-das commented 2 years ago

As of now there is none. But what kind of customization you are thinking about?

BlueCannonBall commented 2 years ago

I was thinking of a way to customize the way that the line number is shown (filename:linenumber instead of line#number) and a way to customize the "beginning" of the error message. (Right now errors are prepended with "Error: ")

satya-das commented 2 years ago

Adding filename in the error report can be done and is useful. Can you provide the use case why you would like to change the beginning of the error message? You can certainly replace the error message with something else as part of post-processing. Is that not that possible in your use case?

BlueCannonBall commented 2 years ago

Adding filename in the error report can be done and is useful.

Yes this would be great.

Can you provide the use case why you would like to change the beginning of the error message?

I want to prefix error messages with the name of the program. For instance:

cib: Error: ...

You can certainly replace the error message with something else as part of post-processing.

What do you mean by this?

satya-das commented 2 years ago

I have made it possible to supply custom error handler with commit 5c417c6. Please give it a try. And indeed, your suggestion will actually help my cib project too. :).

BlueCannonBall commented 2 years ago

Thank you! This is exactly the kind of customization I wanted.