ark-lang / ark

A compiled systems programming language written in Go using the LLVM framework
https://ark-lang.github.io/
MIT License
682 stars 47 forks source link

TryParse and MustParse #655

Open kiljacken opened 8 years ago

kiljacken commented 8 years ago

Currently the state of the parser is kind of a mess with regards to whether a given function must parse correctly or whether to just try and parse.

The parser should optimally be refactored in such a way that each rule in the grammar has both a MustParse and a TryParse variant, and optimally in a way where most of the code is shared.

MovingtoMars commented 8 years ago

What's the difference between this and

e := parseThing()
if e == nil {
    v.err("oh no")
}
kiljacken commented 8 years ago

The thing is, that if we know we must parse we can do better error messages then if we're just trying to parse. Another solution would be to go through the parser and return (T, error) and then check the error instead of the actual value. This would allow for inclusion of a better error message in these cases.

MovingtoMars commented 8 years ago

ok, I see