Package-level declarations

Contains all the types, functions and properties that can be used in the Karith API.

Types

Link copied to clipboard
interface KthBuilder

Common builder interface for KthContext.Builder and KthModule.Builder.

Link copied to clipboard

Represents exceptions that can be thrown while calculating the result, after parsing the expression.

Link copied to clipboard

Constant token to be included in a KthModule or KthContext and used in an expression.

Link copied to clipboard
interface KthContext

Contexts are the main entrypoint of the Karith API. Their primary function is to parse strings into expressions, which can then be calculated to obtain a result.

Link copied to clipboard
sealed interface KthElement : KthToken

Common interface for KthOperator, KthFunction and KthConstant.

Link copied to clipboard
sealed class KthException : Exception

Base class for all exceptions thrown by Karith.

Link copied to clipboard
interface KthExpression

Expressions contain all the data needed to calculate an arithmetic expression when given input variables (if any are needed).

Link copied to clipboard

Function token to be included in a KthModule or KthContext and used in an expression.

Link copied to clipboard
class KthIllegalTokenException(val token: String, val position: Int) : KthParsingException

Thrown during tokenization if the input string contains an illegal token.

Link copied to clipboard

Thrown during calculation if a function / operator doesn't have enough arguments / operands.

Link copied to clipboard

Thrown during token sorting if the input string contains mismatched parentheses.

Link copied to clipboard
interface KthModule

A module is a collection of KthElements to be included in a KthContext.

Link copied to clipboard

Operator token to be included in a KthModule or KthContext and used in an expression.

Link copied to clipboard

Represents exceptions that can be thrown while parsing the expression, before calculating the result.

Link copied to clipboard
sealed interface KthResult<T, E : KthException>

The base result class returned by all API methods used in parsing an expression or calculating a result. Can be either Success or Error.

Link copied to clipboard
sealed interface KthToken

Base interface for all tokens can be parsed in a KthExpression.

Link copied to clipboard

Thrown during tokenization if the input string requires a combiner operator and the context does not provide one.

Link copied to clipboard

Thrown during calculation if an input variable is not defined.

Link copied to clipboard

Thrown during calculation if it encounters an unknown token.

Functions

Link copied to clipboard

Helper function to create a KthConstant using the receiving String as key.

Link copied to clipboard

Helper function to create a KthFunction with one argument using the receiving String as key.

Helper function to create a KthFunction with two arguments using the receiving String as key.

fun String.asFunction(argCount: Int, function: (DoubleArray) -> Double): KthFunction

Helper function to create a KthFunction using the receiving String as key.

Link copied to clipboard
fun String.asOperator(precedence: Int, leftAssociative: Boolean = true, operation: (Double, Double) -> Double): KthOperator

Helper function to create a KthOperator using the receiving String as key.

Link copied to clipboard

Helper function to build a KthContext.

Link copied to clipboard

Parses an arithmetic expression from the given string using the default context, then return its result.

Link copied to clipboard
@JvmName(name = "calculateResultExt")
fun String.calculateResult(): KthParsingAndCalculationResult

Parses an arithmetic expression from the receiving string using the default context, then return its result.

Link copied to clipboard

Parses an arithmetic expression from the given string using the default context, then return its result.

Link copied to clipboard
@JvmName(name = "calculateResultWithExt")
fun String.calculateResultWith(vararg inputVars: Pair<String, Number>): KthParsingAndCalculationResult

Parses an arithmetic expression from the receiving string using the default context, then return its result.

Link copied to clipboard

Helper function to create a KthConstant.

Link copied to clipboard
fun createFunction(key: String, function: (Double) -> Double): KthFunction

Helper function to create a KthFunction with one argument.

fun createFunction(key: String, function: (Double, Double) -> Double): KthFunction

Helper function to create a KthFunction with two arguments.

fun createFunction(key: String, argCount: Int, function: (DoubleArray) -> Double): KthFunction

Helper function to create a KthFunction.

Link copied to clipboard
fun createOperator(key: String, precedence: Int, leftAssociative: Boolean = true, operation: (Double, Double) -> Double): KthOperator

Helper function to create a KthOperator.

Link copied to clipboard
Link copied to clipboard

Parses an arithmetic expression from the given string using the default context.

Link copied to clipboard
@JvmName(name = "parseExpressionExt")
fun String.parseExpression(): KthParsingResult

Parses an arithmetic expression from the receiving string using the default context.

Link copied to clipboard
fun parseExpressionWith(expression: String, vararg declaredVars: String): KthParsingResult

Parses an arithmetic expression from the given string and declared variables using the default context.

Link copied to clipboard
@JvmName(name = "parseExpressionWithExt")
fun String.parseExpressionWith(vararg declaredVars: String): KthParsingResult

Parses an arithmetic expression from the receiving string and declared variables using the default context.

Link copied to clipboard

Helper function to add the Operators.POWER operator to a KthContext builder.