All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jaskell.parsec.ChNone.scala Maven / Gradle / Ivy

package jaskell.parsec

import scala.util.{Try, Success}

case class ChNone(val content: String, val caseSensitive: Boolean=true) extends Parsec[Char, Char] {
  val contentSet: Set[Char] = if (caseSensitive) content.toSet else content.toLowerCase.toSet

  def apply(s: State[Char]): Try[Char]  = {
    s.next() flatMap { c =>
      if (caseSensitive) {
        if (!(contentSet contains c)) {
          return Success(c)
        }
      } else {
        if (!(contentSet contains c.toLower)) {
          return Success(c)
        }
      }
      s.trap(s"expect any char none of $content (case sensitive $caseSensitive) but get $c")
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy