From 0db7a30af0dc088ea50eb093b11ef466e5fbc7ca Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sat, 1 Feb 2025 21:05:42 +0000 Subject: [PATCH] refactor: remove excessive atomics --- src/main/wacc/parser.scala | 44 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main/wacc/parser.scala b/src/main/wacc/parser.scala index 0d4b03b..237b6b5 100644 --- a/src/main/wacc/parser.scala +++ b/src/main/wacc/parser.scala @@ -88,38 +88,34 @@ object parser { private lazy val ``: Parsley[NonEmptyList[Stmt]] = sepBy1(``, ";") private lazy val `` = - (Skip from atomic("skip")) - | Read(atomic("read") ~> ``) - | Free(atomic("free") ~> ``) - | Return(atomic("return") ~> ``) - | Exit(atomic("exit") ~> ``) - | Print(atomic("print") ~> ``, pure(false)) - | Print(atomic("println") ~> ``, pure(true)) + (Skip from "skip") + | Read("read" ~> ``) + | Free("free" ~> ``) + | Return("return" ~> ``) + | Exit("exit" ~> ``) + | Print("print" ~> ``, pure(false)) + | Print("println" ~> ``, pure(true)) | If( - atomic("if") ~> `` <~ "then", + "if" ~> `` <~ "then", `` <~ "else", `` <~ "fi" ) - | While(atomic("while") ~> `` <~ "do", `` <~ "done") - | Block(atomic("begin") ~> `` <~ "end") - | VarDecl(atomic(``), `` <~ "=", ``) + | While("while" ~> `` <~ "do", `` <~ "done") + | Block("begin" ~> `` <~ "end") + | VarDecl(``, `` <~ "=", ``) | Assign(`` <~ "=", ``) private lazy val ``: Parsley[LValue] = - atomic(``) | atomic(``) + `` | `` private lazy val ``: Parsley[RValue] = - atomic(``) | - atomic( - NewPair( - "newpair" ~> "(" ~> `` <~ ",", - `` <~ ")" - ) + `` | + NewPair( + "newpair" ~> "(" ~> `` <~ ",", + `` <~ ")" ) | - atomic(``) | - atomic( - Call( - "call" ~> `` <~ "(", - sepBy(``, ",") <~ ")" - ) + `` | + Call( + "call" ~> `` <~ "(", + sepBy(``, ",") <~ ")" ) | `` private lazy val `` = Fst("fst" ~> ``) | Snd("snd" ~> ``)