refactor: implemented labelAndExplain(), combining label and explain, and... #9

Merged
gc1523 merged 18 commits from error-messages into master 2025-02-06 20:30:26 +00:00
3 changed files with 65 additions and 19 deletions
Showing only changes of commit 057d625464 - Show all commits

View File

@@ -73,11 +73,15 @@ object parser {
) )
private lazy val `<pair-elem-type>` = private lazy val `<pair-elem-type>` =
(`<base-type>` <**> (`<array-type>` </> identity)) | (`<base-type>` <**> (`<array-type>` </> identity)) |
`<pair-type>` ~> ((`<pair-elems-type>` <**> `<array-type>`.explain("for a pair to contain a pair type, it must be an array or erased pair")) </> UntypedPairType) `<pair-type>` ~> ((`<pair-elems-type>` <**> `<array-type>`.explain(
"for a pair to contain a pair type, it must be an array or erased pair"
)) </> UntypedPairType)
// TODO: better explanation here? // TODO: better explanation here?
// Statements // Statements
private lazy val `<program>` = Program( private lazy val `<program>` = Program(
"begin" ~> many(atomic(`<type>`.label("function declaration") <~> `<ident>` <~ "(") <**> `<partial-func-decl>`).label("function declaration"), "begin" ~> many(
atomic(`<type>`.label("function declaration") <~> `<ident>` <~ "(") <**> `<partial-func-decl>`
).label("function declaration"),
`<stmt>`.label("main program body") <~ "end" `<stmt>`.label("main program body") <~ "end"
) )
private lazy val `<partial-func-decl>` = private lazy val `<partial-func-decl>` =