refactor: style fixes in lexer and parser

This commit is contained in:
Guy C
2025-02-07 11:23:18 +00:00
parent ee1ea6c63b
commit 8583a815a8
2 changed files with 13 additions and 7 deletions

View File

@@ -53,7 +53,6 @@ object parser {
val _parensCheck =
char('(').verifiedExplain("use keyword 'call' to call functions")
implicit val builder: ErrorBuilder[String] = new DefaultErrorBuilder with LexToken {
def tokens = errTokens
}
@@ -123,9 +122,13 @@ object parser {
// Statements
private lazy val `<program>` = Program(
"begin" ~> many(
atomic((`<type>`.label("function declaration") <~> `<ident>` <~ "(")) <**> `<partial-func-decl>`
atomic(
(`<type>`.label("function declaration") <~> `<ident>` <~ "(")
) <**> `<partial-func-decl>`
).label("function declaration"),
((`<ident>` <~ "(")*> fail("function is missing return type") | `<stmt>`.label("main program body")) <~ "end"
((`<ident>` <~ "(") *> fail("function is missing return type") | `<stmt>`.label(
"main program body"
)) <~ "end"
)
private lazy val `<partial-func-decl>` =
FuncDecl(
@@ -156,8 +159,11 @@ object parser {
)
| While("while" ~> `<expr>`.labelWithType(LabelType.Expr) <~ "do", `<stmt>` <~ "done")
| Block("begin" ~> `<stmt>` <~ "end")
| VarDecl(`<type>`, `<ident>` <~ "=".explain("functions must be defined on top of the main block"),
`<rvalue>`.label("valid initial value for variable"))
| VarDecl(
`<type>`,
`<ident>` <~ "=".explain("functions must be defined on top of the main block"),
`<rvalue>`.label("valid initial value for variable")
)
| Assign(`<lvalue>` <~ "=", `<rvalue>`)
private lazy val `<lvalue>`: Parsley[LValue] =
`<pair-elem>` | `<ident-or-array-elem>`