From 8583a815a89330c44a935e25da76f6521ceccd97 Mon Sep 17 00:00:00 2001 From: Guy C Date: Fri, 7 Feb 2025 11:23:18 +0000 Subject: [PATCH] refactor: style fixes in lexer and parser --- src/main/wacc/lexer.scala | 4 ++-- src/main/wacc/parser.scala | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/wacc/lexer.scala b/src/main/wacc/lexer.scala index 8aa4607..a00b004 100644 --- a/src/main/wacc/lexer.scala +++ b/src/main/wacc/lexer.scala @@ -33,7 +33,7 @@ val errConfig = new ErrorConfig { "false" -> Label("boolean literal"), "true" -> Label("boolean literal"), "=" -> Label("assignment"), - "[" -> Label("array index"), + "[" -> Label("array index") ) } object lexer { @@ -88,7 +88,7 @@ object lexer { (lexer.nonlexeme.character.ascii).map(c => s"character literal \'$c\'"), lexer.nonlexeme.string.ascii.map(s => s"string literal \"$s\""), // lexer.nonlexeme.symbol("()").as("function call, bruh use keyword 'call' to call functions"), - character.whitespace.map(_ => ""), + character.whitespace.map(_ => "") ) ++ desc.symbolDesc.hardKeywords.map { k => lexer.nonlexeme.symbol(k).as(s"keyword $k") } diff --git a/src/main/wacc/parser.scala b/src/main/wacc/parser.scala index 654d21b..2f41ab0 100644 --- a/src/main/wacc/parser.scala +++ b/src/main/wacc/parser.scala @@ -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( "begin" ~> many( - atomic((``.label("function declaration") <~> `` <~ "(")) <**> `` + atomic( + (``.label("function declaration") <~> `` <~ "(") + ) <**> `` ).label("function declaration"), - ((`` <~ "(")*> fail("function is missing return type") | ``.label("main program body")) <~ "end" + ((`` <~ "(") *> fail("function is missing return type") | ``.label( + "main program body" + )) <~ "end" ) private lazy val `` = FuncDecl( @@ -156,8 +159,11 @@ object parser { ) | While("while" ~> ``.labelWithType(LabelType.Expr) <~ "do", `` <~ "done") | Block("begin" ~> `` <~ "end") - | VarDecl(``, `` <~ "=".explain("functions must be defined on top of the main block"), - ``.label("valid initial value for variable")) + | VarDecl( + ``, + `` <~ "=".explain("functions must be defined on top of the main block"), + ``.label("valid initial value for variable") + ) | Assign(`` <~ "=", ``) private lazy val ``: Parsley[LValue] = `` | ``