feat: show exact statement which must be returning at the end of a function
This commit is contained in:
parent
a71045867a
commit
cb9796fa87
@ -105,10 +105,16 @@ object ast {
|
|||||||
x3: => Parsley[List[Param]],
|
x3: => Parsley[List[Param]],
|
||||||
x4: => Parsley[NonEmptyList[Stmt]]
|
x4: => Parsley[NonEmptyList[Stmt]]
|
||||||
): Parsley[FuncDecl] =
|
): Parsley[FuncDecl] =
|
||||||
super.apply(x1, x2, x3, x4).guardAgainst {
|
super.apply(
|
||||||
case FuncDecl(_, _, _, body) if !body.isReturning =>
|
x1,
|
||||||
Seq("Function must return on all paths")
|
x2,
|
||||||
}
|
x3,
|
||||||
|
x4.guardAgainst {
|
||||||
|
case body if !body.isReturning =>
|
||||||
|
println(body)
|
||||||
|
Seq("All functions must end in a returning statement")
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Param(paramType: Type, name: Ident)
|
case class Param(paramType: Type, name: Ident)
|
||||||
|
@ -75,15 +75,15 @@ object parser {
|
|||||||
|
|
||||||
// Statements
|
// Statements
|
||||||
private lazy val `<program>` = Program(
|
private lazy val `<program>` = Program(
|
||||||
"begin" ~> many(atomic(`<func>`)),
|
"begin" ~> many(`<func>`),
|
||||||
`<stmt>` <~ "end"
|
`<stmt>` <~ "end"
|
||||||
)
|
)
|
||||||
private lazy val `<func>` = FuncDecl(
|
private lazy val `<func>` = FuncDecl(
|
||||||
`<type>`,
|
atomic(`<type>`),
|
||||||
`<ident>` <~ "(",
|
atomic(`<ident>`) <~ "(",
|
||||||
sepBy(`<param>`, ",") <~ ")" <~ "is",
|
sepBy(`<param>`, ",") <~ ")" <~ "is",
|
||||||
`<stmt>` <~ "end"
|
`<stmt>`
|
||||||
)
|
) <~ "end"
|
||||||
private lazy val `<param>` = Param(`<type>`, `<ident>`)
|
private lazy val `<param>` = Param(`<type>`, `<ident>`)
|
||||||
private lazy val `<stmt>`: Parsley[NonEmptyList[Stmt]] =
|
private lazy val `<stmt>`: Parsley[NonEmptyList[Stmt]] =
|
||||||
sepBy1(`<basic-stmt>`, ";")
|
sepBy1(`<basic-stmt>`, ";")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user