ReCT-Lang / nrc

A compiler for the ReCT programming language
MIT License
3 stars 0 forks source link

[BUG] Fix Error Reporting #4

Open Khhs167 opened 8 months ago

Khhs167 commented 8 months ago

As of right now, a lot of errors are double-reported within the parser code, and should ideally be resolved as soon as possible(most likely via function return codes)

It isn't of top priority, and can be fixed once the compiler is working

mauro-balades commented 8 months ago

Can the parser recover from errors or does it just abort once an error has been found?

Khhs167 commented 8 months ago

It keeps on going, aborting because of errors are up to the CLI/compiler interface

mauro-balades commented 8 months ago

It would be bonkers to add a recovery system

Khhs167 commented 8 months ago

What do you mean with recovery system?

mauro-balades commented 8 months ago

a system where the parser can recover towards a valid grammar state. For example, when parsing function declarations:

// When parsing arguments, we need to have "identifier ':' type"
// parse the identifier, if we fail to do that, skip till we find a ')'
recovered_expect(TokenType::Identifier, "an identifier", TokenType::OpenParen);

This will allow multiple errors to be reported by the parser:

function a(???: int) {
   var a = ???;
}
error(1): Unexpected `???` while parsing function arguments
error(2): Expected a valid expression but found `???` while declaring a variable

rect has exited with 2 errors and 0 warnings