refactor: remove boilerplate parser
This commit is contained in:
parent
78ef878fb2
commit
24b83c8448
@ -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)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user