Skip to content

Commit

Permalink
parser: fix (#119) and improve handling of function declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jan 25, 2025
1 parent 019554c commit 052db60
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions std/jule/parser/parser.jule
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ impl parser {
ret
}
t.Kind, ok = unsafe { self.buildType(tokens, &i, true) }
// If result type analysis failed, set i to -1 for error mark.
if !ok {
i = -1
}
ret
}
i++
Expand Down Expand Up @@ -821,9 +825,14 @@ impl parser {
fn buildFunc(mut &self, mut &tokens: []&token::Token, method: bool, prototype: bool): &ast::Func {
mut i := 0
mut f := self.buildFuncPrototype(tokens, i, method)
// If i == -1, there is critical error for analysis.
// Return nil immediately.
if i == -1 {
ret nil
}
if prototype {
if i < len(tokens) {
self.pushErr(tokens[i+1], build::LogMsg.InvalidSyntax)
self.pushErr(tokens[i], build::LogMsg.InvalidSyntax)
}
ret f
} else if f == nil {
Expand All @@ -845,7 +854,7 @@ impl parser {
}
} else {
self.stop()
self.pushErr(f.Token, build::LogMsg.BodyNotExist)
self.pushErr(tokens[i], build::LogMsg.BodyNotExist)
self.pushSuggestion(build::LogMsg.ExpectedBody)
ret nil
}
Expand Down

0 comments on commit 052db60

Please sign in to comment.