refactor: use scalafmt to format code
This commit is contained in:
parent
2b50e3e1f6
commit
252ed1c925
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 4
|
||||||
|
|
2
.scalafmt.conf
Normal file
2
.scalafmt.conf
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
version = 3.8.6
|
||||||
|
runner.dialect = scala36
|
@ -3,13 +3,14 @@ package wacc
|
|||||||
import parsley.{Success, Failure}
|
import parsley.{Success, Failure}
|
||||||
|
|
||||||
def main(args: Array[String]): Unit = {
|
def main(args: Array[String]): Unit = {
|
||||||
println("hello WACC!")
|
println("hello WACC!")
|
||||||
|
|
||||||
args.headOption match {
|
args.headOption match {
|
||||||
case Some(expr) => parser.parse(expr) match {
|
case Some(expr) =>
|
||||||
case Success(x) => println(s"$expr = $x")
|
parser.parse(expr) match {
|
||||||
case Failure(msg) => println(msg)
|
case Success(x) => println(s"$expr = $x")
|
||||||
}
|
case Failure(msg) => println(msg)
|
||||||
case None => println("please enter an expression")
|
}
|
||||||
}
|
case None => println("please enter an expression")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ import parsley.token.Lexer
|
|||||||
import parsley.token.descriptions.*
|
import parsley.token.descriptions.*
|
||||||
|
|
||||||
object lexer {
|
object lexer {
|
||||||
private val desc = LexicalDesc.plain.copy(
|
private val desc = LexicalDesc.plain.copy(
|
||||||
// your configuration goes here
|
// your configuration goes here
|
||||||
)
|
)
|
||||||
private val lexer = Lexer(desc)
|
private val lexer = Lexer(desc)
|
||||||
|
|
||||||
val integer = lexer.lexeme.integer.decimal
|
val integer = lexer.lexeme.integer.decimal
|
||||||
val implicits = lexer.lexeme.symbol.implicits
|
val implicits = lexer.lexeme.symbol.implicits
|
||||||
def fully[A](p: Parsley[A]): Parsley[A] = lexer.fully(p)
|
def fully[A](p: Parsley[A]): Parsley[A] = lexer.fully(p)
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,14 @@ import lexer.implicits.implicitSymbol
|
|||||||
import lexer.{integer, fully}
|
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 = fully(expr)
|
||||||
|
|
||||||
private val add = (x: BigInt, y: BigInt) => x + y
|
|
||||||
private val sub = (x: BigInt, y: BigInt) => x - y
|
|
||||||
|
|
||||||
private lazy val expr: Parsley[BigInt] =
|
private val add = (x: BigInt, y: BigInt) => x + y
|
||||||
chain.left1(integer | "(" ~> expr <~ ")")(
|
private val sub = (x: BigInt, y: BigInt) => x - y
|
||||||
("+" as add) | ("-" as sub)
|
|
||||||
)
|
private lazy val expr: Parsley[BigInt] =
|
||||||
|
chain.left1(integer | "(" ~> expr <~ ")")(
|
||||||
|
("+" as add) | ("-" as sub)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user