refactor: style fixes in lexer and parser
This commit is contained in:
@@ -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>`
|
||||
|
||||
Reference in New Issue
Block a user