refactor: remove boilerplate parser

This commit is contained in:
Gleb Koval 2025-02-01 00:58:29 +00:00
parent 78ef878fb2
commit 24b83c8448
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

View File

@ -1,20 +1,8 @@
package wacc package wacc
import parsley.{Parsley, Result} import parsley.Result
import parsley.expr.chain
import lexer.implicits.implicitSymbol
import lexer.{integer, fully}
object parser { object parser {
def parse(input: String): Result[String, BigInt] = parser.parse(input) def parse(input: String): Result[String, BigInt] = parser.parse(input)
private val parser = fully(expr) private val parser = lexer.fully(???)
private val add = (x: BigInt, y: BigInt) => x + y
private val sub = (x: BigInt, y: BigInt) => x - y
private lazy val expr: Parsley[BigInt] =
chain.left1(integer | "(" ~> expr <~ ")")(
("+" as add) | ("-" as sub)
)
} }