package utils
This package defines various MMT-independent high-level APIs. Various basic functions are declared directly in this package object in order to be easily available.
Most other files in this package are self-contained and independent of the rest of MMT and each other. We describe them in groups below.
Data structures*
- Union disjoint union of Scala types - MyList extensions of Scala's lists (via implicit conversions) - HashRelation, HashMapToSet, and HashEquality: hash-related data structures for - While while loops that allow for break and continue
General purpose utilities
- Killable tasks that can be notified that they should be canceled. In particular, MMTTasks can be aborted without risking an inconsistent state. - Unparsed for simple parsing of strings - ScalaTo serialization helpers for Scala objects - ValueCache factory methods that introduce structure sharing by resuing previous pointers - XMLToScala framework for conveniently turning a set of case classes into an XML parser for the corresponding schema
Wrappers for low-level APIs
MMT provides various APIs that extend or simplify APIs provided Java or Scala: - File file paths and interacting with files - URI URIs - xml various helper function for working with XML and dereferencing URLs (not really a wrapper but fits best here) - ShellCommand commands executed on the system shell
APIs for external languages
- Dot the dot languages for graph layouting - JSON the JSON language - HTML API for building HTML pages programmatically
- Source
- package.scala
- Alphabetic
- By Inheritance
- utils
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- case class A(a: String, b: Int, c: Boolean, d: B, e: List[B], f: Option[B], g: Option[C], _cs: List[C]) extends Product with Serializable
-
abstract
class
AccessibleCompanion[+T] extends AnyRef
Abstract class to be used as a class for a companion object to be tracked by a AccessibleCompanionCollection
Abstract class to be used as a class for a companion object to be tracked by a AccessibleCompanionCollection
- T
class that this is a Companion Object for \
-
abstract
class
AccessibleCompanionCollection[T, CompanionType <: AccessibleCompanion[T]] extends AnyRef
Represents a collection of AccessibleCompanion objects
Represents a collection of AccessibleCompanion objects
- T
type of class to store companions for
- CompanionType
the conrete type of AccessibleCompanions this collection is for
- case class B(a: String, _bs: List[B]) extends Product with Serializable
-
case class
BacktrackableExtractError(token: Int, msg: String) extends Exception with Product with Serializable
thrown on all errors where extraction succeeded but the wrong type was found; these can be backtracked, e.g., if they follow a list
-
case class
Bracket(begin: String, end: String) extends Product with Serializable
a pair of an open and a closing bracket
-
case class
BracketPair(open: String, close: String, ignore: Boolean) extends Product with Serializable
a pair of matching brackets, e.g., BracketPair("[","]",false) or BracketPair("//","\n",true)
- abstract class C extends AnyRef
- case class Ca(a: String) extends C with Product with Serializable
-
trait
CanonicalForm[A] extends AnyRef
objects that have a canonical form
objects that have a canonical form
- A
the type of the objects
- case class Cb(_c1: C, _c2: C) extends C with Product with Serializable
- case class Cc(a: String, bc: G, d: String) extends C with Product with Serializable
- case class Cd(_bs: List[B], _c: Option[C]) extends C with Product with Serializable
- case class Ce(_js: List[J], _c: Option[C]) extends C with Product with Serializable
- trait CompParser extends AnyRef
- trait CompRegexParsers extends CompParser
-
class
ComplexHashSet[H, A] extends Set[A]
a hash set that uses a complex (possibly infinite) type as hash values
- case class ConcatNestable[+A](left: NestableList[A], right: NestableList[A]) extends NestableList[A] with Product with Serializable
- abstract class ConcreteBaseType extends ConcreteType
- abstract class ConcreteType extends AnyRef
- case class ConsNestable[+A](hd: A, tl: NestableList[A]) extends NestableList[A] with Product with Serializable
- case class ConverterNotApplicable(json: JSON) extends Exception with Product with Serializable
-
trait
DotEdge extends DotObject
a node to be used in a DotGraph
-
case class
DotError(m: String) extends Error with Product with Serializable
thrown by DotToSVG
-
trait
DotGraph extends AnyRef
a graph that can be converted to SVG by DotToSVG
-
trait
DotNode extends DotObject
a node to be used in a DotGraph
- sealed trait DotObject extends AnyRef
-
class
DotToSVG extends AnyRef
converts a graph to SVG using the dot tool
- case class EmptyNestable[+A]() extends NestableList[A] with Product with Serializable
-
abstract
class
Escaping extends AnyRef
escapes all non-legal characters according to some rules
-
abstract
class
ExtractError extends Exception
thrown on all errors, e.g., when expected classes are not present or XML nodes are not present
-
case class
FatalExtractError(msg: String) extends Exception with Product with Serializable
default case
-
case class
Field(name: String, value: ScalaTo) extends Product with Serializable
auxiliary class for FieldsToXML
-
trait
FieldWiseScalaTo extends ScalaTo
mix in this trait to get add systematic serialization defined by a list of fields
-
case class
File(toJava: java.io.File) extends Product with Serializable
File wraps around java.io.File to extend it with convenience methods
File wraps around java.io.File to extend it with convenience methods
see implicit conversions with java.io.File at the end of this file
-
case class
FilePath(segments: List[String]) extends Product with Serializable
a relative file path usually within an archive below a dimension
- case class G(b: String, h: H) extends Group with Product with Serializable
-
trait
Group extends AnyRef
a marker for classes representing groups of attributes/children, used by XMLToScala
- case class H(c: String) extends Group with Product with Serializable
-
abstract
class
HTML extends AnyRef
a partial implementation of HTML designed for easily building and emitting HTML documents
a partial implementation of HTML designed for easily building and emitting HTML documents
see archives.HTMLExporter for a usage example
-
class
HTMLBuilder extends HTML
collects HTML in a String
-
class
HTMLFileWriter extends HTML
collects HTML in a file
-
trait
HashEquality[A] extends AnyRef
adds an equality method that is guarded by equality of cached hashcodes
adds an equality method that is guarded by equality of cached hashcodes
This can be mixed into immutable inductive data structures whose values are often tested for equality. Failing equality tests do not traverse the value anymore the first time.
- A
the type into which this is mixed in (only needed to constrain the type of hasheq)
- abstract class HashMapToOrderedSet[A, B] extends HashMap[A, ListBuffer[B]]
-
class
HashMapToSet[A, B] extends HashMap[A, HashSet[B]]
This implements a relation on A and B as a mutable total map from A to the power set of B.
-
class
HashRelation[A, B] extends AnyRef
This implements a binary relation between A and B.
This implements a binary relation between A and B. The entries are hashed twice so that lookups of both image and preimage are efficient.
-
class
IncrementalTransitiveClosure[T] extends AnyRef
efficiently maintains the transitive closure a changing relation on a type T the generating relation is defined calls to add and delete
efficiently maintains the transitive closure a changing relation on a type T the generating relation is defined calls to add and delete
lookup is constant time adding/deleting is linear in the number of paths using the new/deleted edge
- case class IntVal(value: Int) extends OptionValue with Product with Serializable
- case class J(_b: B, _c: C) extends Group with Product with Serializable
-
sealed abstract
class
JSON extends ScalaTo
straightforward API for JSON objects
- case class JSONArray(values: JSON*) extends JSON with Product with Serializable
- case class JSONBoolean(value: Boolean) extends JSONValue with Product with Serializable
- case class JSONFloat(value: BigDecimal) extends JSONValue with Product with Serializable
- case class JSONInt(value: BigInt) extends JSONValue with Product with Serializable
-
class
JSONListBuffer extends AnyRef
A convenience class to construct JSON Arrays
-
class
JSONListParser extends AnyRef
A convenience class to parse JSON Arrays
- case class JSONObject(map: List[(JSONString, JSON)]) extends JSON with Product with Serializable
-
class
JSONObjectBuffer extends AnyRef
A convenience class to construct JSON Objects
-
class
JSONObjectParser extends AnyRef
A convenience class to deconstruct JSON Objects
- case class JSONString(value: String) extends JSONValue with Product with Serializable
- sealed abstract class JSONValue extends JSON
-
class
KillButton extends AnyRef
a flag that can be used in multi-threaded applications to signal that processing should be aborted see Killable
-
trait
Killable extends AnyRef
killable objects have a list of kill button any of which can be pressed to abort processing
killable objects have a list of kill button any of which can be pressed to abort processing
objects working with killable objects must regularly check the state of the kill button and abort gracefully if pressed
multiple killable objects can share the same kill button; when creating a new killable object, it is often necessary to pass along an existing kill button
-
case class
LazySerialization(baseURL: String, id: Int) extends ScalaTo with Product with Serializable
an object whose lazy serialization can be retrieved from a URL
-
class
LazySerializationStore extends AnyRef
a class for storing objects that are serialized lazily
- case class Left[A, B](value: A) extends Union[A, B] with Product with Serializable
- case class ListType(entry: ConcreteType) extends ConcreteType with Product with Serializable
-
abstract
class
ListWrapper[A, W <: ListWrapper[A, W]] extends AnyRef
adds convenience methods to a class that wraps around a list
-
trait
ListWrapperCompanion[A, W <: ListWrapper[A, W]] extends AnyRef
should be mixed into the companion object of a ListWrapper subclass
-
class
MMT_TODO extends deprecated
The MMT_TODO class is an alternative to the {{@deprecated}} annotation.
The MMT_TODO class is an alternative to the {{@deprecated}} annotation. This allows us to mark a part of the code as needing review and/or re-work
-
case class
MyList[A](l: List[A]) extends Product with Serializable
Wrapper around List to provide some custom extensions
- case class NOSuchKey(key: String) extends Exception with Product with Serializable
- sealed abstract class NestableList[+A] extends Iterable[A]
-
abstract
class
OS extends AnyRef
type of operating systems as used in OS
-
sealed abstract
class
OptionArgument extends AnyRef
describe the kind of a command line option
-
case class
OptionDescr(long: String, short: String, arg: OptionArgument, description: String) extends Product with Serializable
a description of one option
- case class OptionType(entry: ConcreteType) extends ConcreteType with Product with Serializable
-
sealed abstract
class
OptionValue extends AnyRef
the possible values given by options
- case class RecordType(fields: List[(String, ConcreteType)]) extends ConcreteType with Product with Serializable
-
class
ReflTransHashRelation[A] extends HashRelation[A, A]
This implements the reflexive and transitive closure of a HashRelation[A,A].
This implements the reflexive and transitive closure of a HashRelation[A,A]. The closure is not maintained and lookups use depth-first search. In particular, the methods += and -= change the underlying relation, not only the closure.
-
class
ResultCache[A, B] extends AnyRef
An auxiliary trait for introducing tabling a function and introducing structure sharing of result values
An auxiliary trait for introducing tabling a function and introducing structure sharing of result values
- A
the input type
- B
the output type
- case class Right[A, B](value: B) extends Union[A, B] with Product with Serializable
-
trait
ScalaTo extends AnyRef
objects that can be serialized as XML or JSON
-
trait
SingletonAccessibleCompanion[+T <: Singleton] extends AccessibleCompanion[T]
Represents the companion of a singleton
-
class
StandardPrintWriter extends OutputStreamWriter
MMT's default way to write to files; uses buffering, UTF-8, and \n
- case class StringListVal(value: List[String]) extends OptionValue with Product with Serializable
-
class
StringMatcher extends AnyRef
matches S1 in "before S1 after"
-
class
StringMatcher2 extends AnyRef
matches S1, S2 in "before S1 middle S2 after"
matches S1, S2 in "before S1 middle S2 after"
first occurrence of 'middle' after 'before' is used if ambiguous
-
class
StringMatcher2Sep extends AnyRef
matches S1, ..., Sn in "before S1 sep ...
matches S1, ..., Sn in "before S1 sep ... sep Sn after"
-
class
StringMatcher3 extends AnyRef
matches S1, S2, S3 in "before S1 middle1 S2 middle2 S3 after"
matches S1, S2, S3 in "before S1 middle1 S2 middle2 S3 after"
first occurrence of 'middle1' after 'before' and 'middle2' after 'middle1' is used if ambiguous
-
case class
StringSlice(s: String, from: Int, to: Int) extends CharSequence with Product with Serializable
helper class for working with substrings without copying (standard Java substring method creates a copy)
- case class StringVal(value: String) extends OptionValue with Product with Serializable
-
class
Timer extends AnyRef
allows timing of operations
-
class
TrustAllX509TrustManager extends X509TrustManager
a trust manager that does nothing
- case class TupleType(entries: List[ConcreteType]) extends ConcreteType with Product with Serializable
-
case class
URI(scheme: Option[String], authority: Option[String], path: List[String] = Nil, abs: Boolean = false, query: Option[String] = None, fragment: Option[String] = None) extends Product with Serializable
Custom implementation of the URI RFC that's better than java.net.URI
Custom implementation of the URI RFC that's better than java.net.URI
- abs
true if the path is absolute (ignored if scheme or authority are present)
-
sealed abstract
class
Union[A, B] extends AnyRef
disjoint union of two types
- abstract class Unix extends OS
-
class
Unparsed extends Reader[Char]
\n, \r, and \r\n are read as \n
- trait UnparsedParsers extends RegexParsers with PackratParsers
-
class
ValueCache[A <: AnyRef] extends AnyRef
An auxiliary trait for introducing structure sharing of values the most recent values are cached, if a new value is in the cache, it is discarded and replaced with the cached one
An auxiliary trait for introducing structure sharing of values the most recent values are cached, if a new value is in the cache, it is discarded and replaced with the cached one
- A
the type values to cache
- case class VectorType(entry: ConcreteType, length: Int) extends ConcreteType with Product with Serializable
-
class
XMLToScala extends AnyRef
This class uses Scala reflection to parse XML into user-defined case classes.
This class uses Scala reflection to parse XML into user-defined case classes.
The effect is that the classes encode the XML grammar, and the parser picks the corresponding class for each XML tag. This is kind of the opposite of generating a parser, where the grammar is fixed and the classes are generated.
-
trait
JSONConverter[T] extends AnyRef
A class to quickly convert objects between Scala and JSON
A class to quickly convert objects between Scala and JSON
- Annotations
- @MMT_TODO( message = ... )
- Deprecated
this is unused, but is kept to be unified with ScalaTo in a future refactor
Value Members
-
def
associate[A](l: List[A], unit: A)(comp: (A, A) ⇒ A): A
variant of fold such that associate(List(a), unit)(comp) = a instead of comp(unit, a)
- def charAt(s: String, i: Int): Option[Char]
-
def
diff[A](l: Seq[A], m: Seq[A]): Seq[A]
difference of two lists
-
def
disjoint[A](l: Seq[A], m: Seq[A]): Boolean
disjointness of two lists (fast if first argument is empty)
-
def
downcast[A, B <: A](cls: Class[B])(a: A): Option[B]
a cast function that allows only casting into a subtype and returns None if the cast fails
-
def
firstDefined[T](alternatives: (Unit) ⇒ Option[T]*): Option[T]
calls a list of functions in order and finds the first defined one or None
-
implicit
def
fromList[A](l: List[A]): MyList[A]
implicit conversion into lists with extra functionality
-
def
hasDuplicates[A](l: Iterable[A]): Boolean
checks if a list has duplicates
-
def
histogram[T1, T2](lst: Seq[T1], pf: PartialFunction[T1, T2]): Seq[(T2, Int)]
returns a histogram of pf over lst, i.e.
returns a histogram of pf over lst, i.e. counts how often each return value occurs
-
def
insertSep[A](l: List[A], sep: A): List[A]
inserts a separator element in between all elements of a list
-
def
inter[A](l: Seq[A], m: Seq[A]): Seq[A]
intersection of two lists
-
def
invlistmap[A, B](l: Iterable[(A, B)], b: B): Option[A]
applies a list of pairs seen as the inverse of a map
-
def
listToString[A](l: Iterable[A], sep: String): String
turns a list into a string by inserting a separator
-
def
listmap[A, B](l: Iterable[(A, B)], a: A): Option[B]
applies a list of pairs seen as a map
-
def
mapInContext[A, B](l: Iterable[A])(f: (List[(A, B)], A) ⇒ B): List[B]
like map, but the map function knows what previous values produced
-
def
moduloLength(s: String, i: Int): Int
string index modulo string length
-
def
readFullStream(is: InputStream): String
slurps an entire stream into a string
-
def
repeatString(s: String, n: Int, sep: String = ""): String
repeats a strings a number of times, optionally with a separator
-
def
splitAtWhitespace(s: String): List[String]
splits a string at whitespace, quoted segments may contain whitespace, \" for quote, ignores leading/trailing whitespace
-
def
stringToInt(s: String): Option[Int]
converts a string to an integer, returns None on format exception
-
def
stringToList(s: String, sep: String = "\\s"): List[String]
splits a string at a separator (returns Nil for the empty string)
-
def
subset[A](l: Seq[A], m: Seq[A]): Boolean
subset property of two lists (seen as sets) (fast if first argument is empty)
-
def
substringFrom(s: String, from: Int, length: Int): String
substring of a string given by begin and length, negative index allowed
-
def
substringFromTo(s: String, from: Int, to: Int): String
substring of a string given by begin and end, negative indices allowed
-
object
AnaArgs
function for parsing command line arguments
- object AnyType extends ConcreteType with Product with Serializable
- object BSD extends Unix with Product with Serializable
- object BooleanType extends ConcreteBaseType with Product with Serializable
-
object
Compress
wrappers for streams that allow toggling compressions
- object ConcreteType
- object EmptyList extends Exception with Product with Serializable
- object EmptyPath extends FilePath
- object Escape
-
object
FieldWiseScalaTo
serializable trees
-
object
File extends Serializable
This defines some very useful methods to interact with text files at a high abstraction level.
-
object
FileNameEscaping extends Escaping
escapes a string into one that is a legal file name on Windows and Unix
- object FilePath extends Serializable
-
object
FileURI
Constructs and pattern-matches absolute file:URIs in terms of absolute File's.
- object FloatType extends ConcreteBaseType with Product with Serializable
- object HTML
-
object
IntArg extends OptionArgument with Product with Serializable
expect an integer argument
- object IntType extends ConcreteBaseType with Product with Serializable
- object JSON
- object JSONArray extends Serializable
- object JSONConversions
- object JSONConverter
-
object
JSONFromURL
retrieve JSON from a URL
- object JSONNull extends JSON with Product with Serializable
- object JSONObject extends Serializable
- object JSONObjectBuffer
-
object
JSONTyping
tuple and vector types are inhabited by arrays, but arrays are never infered as such
-
object
JSONXML
converts between XML and JSON following the jsonML specification
-
object
Javascript
a simple API for generating Javascript expressions
- object Linux extends Unix with Product with Serializable
- object MMTJavascript
- object MMTSystem
- object MacOS extends Unix with Product with Serializable
- object MyList extends Serializable
-
object
NoArg extends OptionArgument with Product with Serializable
just a flag
- object NoVal extends OptionValue with Product with Serializable
- object NullType extends ConcreteType with Product with Serializable
-
object
NumericString
matches a string as an integer
-
object
OS
abstractions for OS-specific behavior
- object OpenMath
-
object
OptIntArg extends OptionArgument with Product with Serializable
expect an optional integer argument that must not be given as a separate argument
- object ProbablyUnix extends Unix with Product with Serializable
- object RunJavaClass
-
object
ScalaTo
implicit conversions to add XML serializations for typical types
- object ShellCommand
- object SkipThis extends Throwable
- object Sourceable
- object StandardStringEscaping extends Escaping
- object StringArg extends OptionArgument with Product with Serializable
-
object
StringListArg extends OptionArgument with Product with Serializable
collect multiple values
-
object
StringMatcher
simpler version of the StringMatcher classes using regexes, but without apply methods
- object StringSlice extends Serializable
- object StringType extends ConcreteBaseType with Product with Serializable
- object Test
-
object
TrustAllX509TrustManager
Some sites use certificates that are not trusted by the JRE by default.
Some sites use certificates that are not trusted by the JRE by default. The clean solution would be to add the appropriate certificates either to the local Java keystore directory or at runtime. As a quick hack, this code simply disables all default certificate checking.
- object URI extends Serializable
-
object
URLEscaping extends Escaping
escapes a string using the %-escapes for URLs
-
object
While
while loops with break and continue
- object Windows extends OS with Product with Serializable
-
object
XMLEscaping extends Escaping
escapes a string using the &-escapes of XML for <>&"
- object XMLToScala
- object mmt
- object xml