aoc2023/Common.scala

17 lines
448 B
Scala
Raw Normal View History

2023-12-03 15:50:17 +00:00
//> using dep org.scala-lang.modules::scala-parser-combinators::2.3.0
2023-12-02 14:31:39 +00:00
package aoc
2023-12-03 15:50:17 +00:00
import scala.util.parsing.combinator._
2023-12-02 14:31:39 +00:00
def iterate[T](get: => T | Null) =
Iterator.continually(get).takeWhile(_ != null).map(_.nn)
def lines = iterate(scala.io.StdIn.readLine())
2023-12-03 15:50:17 +00:00
class CommonParser extends RegexParsers:
val num = """(0|[1-9]\d*)""".r ^^ { _.toInt }
2023-12-05 09:08:40 +00:00
val long = """(0|[1-9]\d*)""".r ^^ { _.toLong }
2023-12-03 15:50:17 +00:00
object CommonParser extends CommonParser