Packages

o

de.unruh.isabelle.pure

StringInterpolators

object StringInterpolators extends OperationCollection

Provides string interpolators for conveniently creating Isabelle terms and types.

It allows us to write, e.g., term"x+y" to parse the term x+y. Or typ"nat" to parse the type nat

In addition, subterms of terms can refer to already existing Term objects, e.g., term"x+$term" for a Scala variable term of type Term.

We can also refer to existing Typ objects, both in terms and types. E.g., term"x :: $typ or typ"$typ => $typ" for a Scala variable of type Typ.

The support for the interpolators is activated by importing the implicits import de.unruh.isabelle.pure.Implicits._.

To use the interpolators, an implicit Isabelle instance, an implicit ExecutionContext, and an implicit Context must be given. (The latter provides the theory context in which to parse the terms/types.)

Parsing happens at runtime, there is no compile-time validation of the terms/types.

An example how to use type and term interpolators:

import de.unruh.isabelle.pure.Implicits._
import scala.concurrent.ExecutionContext.Implicits.global
implicit isabelle = new Isabelle(...)
implicit context = Context("Main") // Parsing w.r.t. Isabelle theory Main
val typ1 = typ"nat"               // type nat
val typ2 = typ"$typ1 => $typ1"    // type nat => nat
val term1 = term"f :: $typ2"      // term f :: nat => nat
val term2 = term"$term1 1"        // term (f :: nat => nat) (1 :: nat)  (by type inference)

The interpolators can also be used for pattern matching. That is, term"..." and typ"..." can appear in the pattern in a Scala pattern match. Example:

// implicits as above
val term = term"1 + (2::nat)"
term match {
  case term"$t + (_::$u::plus)" => (t,u)  // t : Term is "1::nat", u : Typ is "nat"
}
val typ = typ"nat => nat"
typ match {
  case typ"$t => $dummy" => t    // t : Typ is "nat"
}

(Note: A subtlety is that we write $u::plus instad of just $u in the pattern above. This is because Isabelle otherwise refuses to parse the term: a schematic type variable (into which $u is converted for parsing purposes) needs to be annotated with a sort that makes the overall term well-typed.)

(Note: Another subtlety is that we use $dummy instead of _ to indicate a wildcard in typ"$t => $dummy". This is because Isabelle does not support _ in pattern matches for types. We could also write $_ instead of $dummy here because then _ is a Scala-wildcard, not an Isabelle wildcard.)

Invalid (i.e., unparseable) strings raise an IsabelleException. This also applied if ... in patterns term"..." or typ"..." cannot be parsed.

Source
StringInterpolators.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. StringInterpolators
  2. OperationCollection
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. final class Ops extends AnyRef
    Attributes
    protected
  2. implicit final class TermInterpolator extends AnyRef

    See StringInterpolators for an explanation.

  3. type TermOrTyp = FutureValue with PrettyPrintable

    Best approximation to the union type of Term and Typ that we can easily manage.

  4. implicit final class TypInterpolator extends AnyRef

    See StringInterpolators for an explanation.

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def Ops(implicit isabelle: Isabelle, ec: ExecutionContext): Ops

    Returns an instance of type Ops.

    Returns an instance of type Ops. It is guaranteed that for each instance isabelle, exactly one instance of Obs is created (using the ec from the first such invocation). (If you see this doc string in a class different from OperationCollection but no definition of the class Ops, treat this function as if it was private.)

    Definition Classes
    OperationCollection
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native() @HotSpotIntrinsicCandidate()
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  11. def init()(implicit isabelle: Isabelle, executionContext: ExecutionContext): Unit

    Makes sure an Ops instance for the instance isabelle is initialized.

    Makes sure an Ops instance for the instance isabelle is initialized. This is useful when code needs to be sure that the global initialization inside the Ops class has happened (e.g., declarations of ML types via Isabelle.executeMLCodeNow) even if it does not access any of the fields in the Ops class.

    Can safely be called several times with the same isabelle and/or executionContext.

    Definition Classes
    OperationCollection
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. def newOps(implicit isabelle: Isabelle, ec: ExecutionContext): Ops

    Should construct an instance of type Ops

    Should construct an instance of type Ops

    Attributes
    protected
    Definition Classes
    StringInterpolatorsOperationCollection
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  21. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. object PrivateImplementation

    This object should be considered private.

    This object should be considered private. (It is only visible to be accessible in macro code.)

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] ) @Deprecated
    Deprecated

Inherited from OperationCollection

Inherited from AnyRef

Inherited from Any

Ungrouped