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

com.nicopolyptic.state.verification.OnlineVerifier.scala Maven / Gradle / Ivy

The newest version!
/**
  *
  *     _   ___                        __            __  _
  *    / | / (_)________  ____  ____  / /_  ______  / /_(_)____
  *   /  |/ / / ___/ __ \/ __ \/ __ \/ / / / / __ \/ __/ / ___/
  *  / /|  / / /__/ /_/ / /_/ / /_/ / / /_/ / /_/ / /_/ / /__
  * /_/ |_/_/\___/\____/ .___/\____/_/\__, / .___/\__/_/\___/
  *                   /_/            /____/_/
  *
  **/

package com.nicopolyptic.state.verification

import com.nicopolyptic.state.{Automaton, Exp, Interpretation}

class OnlineVerifier[X](e : Exp[X]) {

  private val a = Automaton.create(e)
  private var state = a.initialState

  def next[S](l: S)(implicit i : Interpretation[X,S]) : OnlineVerificationResult = {
    val xs = a.transitions(state).keys.filter(x => i.matches(x, l) || i.wildcard.equals(x)).toList
    if (xs.isEmpty) {
      return Reject(s"Failed matching ${l} with any of ${a.transitions(state).keys}")
    }
    val x = xs.filterNot(i.wildcard.equals).headOption.getOrElse(xs.head)
    val next = a.transitions(state)(x)
    if (!next.intersect(a.acceptingState).isEmpty) {
      return Accept()
    }
    state = next
    Continue()
  }

  def statusMessage = s"Expecting one of the following matches ${a.transitions(state).keys}"

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy