ammonite.kernel.Parsers.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ammonite-kernel_2.12 Show documentation
Show all versions of ammonite-kernel_2.12 Show documentation
Stripped down version of ammonite
package ammonite.kernel
import fastparse.noApi._
import scalaparse.Scala._
import WhitespaceApi._
private[kernel] object Parsers {
val splitter = P(statementBlocl(Fail) ~ WL ~ End)
private val prelude = P((Annot ~ OneNLMax).rep ~ (Mod ~/ Pass).rep)
private val statement = P(scalaparse.Scala.TopPkgSeq | scalaparse.Scala.Import | prelude ~ BlockDef | StatCtx.Expr)
private def statementBlocl(blockSep: P0) =
P(Semis.? ~ (!blockSep ~ statement ~~ WS ~~ (Semis | End)).!.repX)
// /**
// * Attempts to break a code blob into multiple statements. Returns `None` if
// * it thinks the code blob is "incomplete" and requires more input
// */
// def split(code: String): Option[fastparse.core.Parsed[Seq[String]]] =
// splitter.parse(code) match {
// case Failure(_, index, extra) if code.drop(index).trim() == "" => None
// case x => Some(x)
// }
}