refactor: remove excessive atomics

This commit is contained in:
Gleb Koval 2025-02-01 21:05:42 +00:00
parent a110225c49
commit 0db7a30af0
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

View File

@ -88,38 +88,34 @@ object parser {
private lazy val `<stmt>`: Parsley[NonEmptyList[Stmt]] =
sepBy1(`<basic-stmt>`, ";")
private lazy val `<basic-stmt>` =
(Skip from atomic("skip"))
| Read(atomic("read") ~> `<lvalue>`)
| Free(atomic("free") ~> `<expr>`)
| Return(atomic("return") ~> `<expr>`)
| Exit(atomic("exit") ~> `<expr>`)
| Print(atomic("print") ~> `<expr>`, pure(false))
| Print(atomic("println") ~> `<expr>`, pure(true))
(Skip from "skip")
| Read("read" ~> `<lvalue>`)
| Free("free" ~> `<expr>`)
| Return("return" ~> `<expr>`)
| Exit("exit" ~> `<expr>`)
| Print("print" ~> `<expr>`, pure(false))
| Print("println" ~> `<expr>`, pure(true))
| If(
atomic("if") ~> `<expr>` <~ "then",
"if" ~> `<expr>` <~ "then",
`<stmt>` <~ "else",
`<stmt>` <~ "fi"
)
| While(atomic("while") ~> `<expr>` <~ "do", `<stmt>` <~ "done")
| Block(atomic("begin") ~> `<stmt>` <~ "end")
| VarDecl(atomic(`<type>`), `<ident>` <~ "=", `<rvalue>`)
| While("while" ~> `<expr>` <~ "do", `<stmt>` <~ "done")
| Block("begin" ~> `<stmt>` <~ "end")
| VarDecl(`<type>`, `<ident>` <~ "=", `<rvalue>`)
| Assign(`<ident>` <~ "=", `<rvalue>`)
private lazy val `<lvalue>`: Parsley[LValue] =
atomic(`<pair-elem>`) | atomic(`<ident-or-array-elem>`)
`<pair-elem>` | `<ident-or-array-elem>`
private lazy val `<rvalue>`: Parsley[RValue] =
atomic(`<array-liter>`) |
atomic(
NewPair(
"newpair" ~> "(" ~> `<expr>` <~ ",",
`<expr>` <~ ")"
)
`<array-liter>` |
NewPair(
"newpair" ~> "(" ~> `<expr>` <~ ",",
`<expr>` <~ ")"
) |
atomic(`<pair-elem>`) |
atomic(
Call(
"call" ~> `<ident>` <~ "(",
sepBy(`<expr>`, ",") <~ ")"
)
`<pair-elem>` |
Call(
"call" ~> `<ident>` <~ "(",
sepBy(`<expr>`, ",") <~ ")"
) | `<expr>`
private lazy val `<pair-elem>` =
Fst("fst" ~> `<lvalue>`) | Snd("snd" ~> `<lvalue>`)