Skip to content

Logical expression

The root expression

ts
export type ESCalcLiteLogicalExpression =
  | ESCalcLiteTernaryExpression
  | ESCalcLiteBinaryExpression
  | ESCalcLiteUnaryExpression
  | ESCalcLiteValueExpression
  | ESCalcLiteFunctionExpression

Ternary expression

Represents a logical ? expression.

ts
export type ESCalcLiteTernaryExpression = {
  type: 'ternary'
  left: ESCalcLiteLogicalExpression
  right: ESCalcLiteLogicalExpression
  middle: ESCalcLiteLogicalExpression
}

Binary expression

Represents an expression that takes two arguments.

ts
export type ESCalcLiteBinaryExpression = {
  type: 'binary'
  operator:
    | 'subtraction'
    | 'addition'
    | 'multiplication'
    | 'division'
    | 'modulus'
    | 'exponentiation'
    | 'more-than'
    | 'less-than'
    | 'more-than-equal'
    | 'less-than-equal'
    | 'not-equals'
    | 'equals'
    | 'and'
    | 'or'
    | 'bit-and'
    | 'bit-or'
    | 'bit-xor'
    | 'bit-left-shift'
    | 'bit-right-shift'
    | 'in'
    | 'not-in'
  left: ESCalcLiteLogicalExpression
  right: ESCalcLiteLogicalExpression
}

Unary expression

Represents an expression that takes a single argument. Such as negation.

ts
export type ESCalcLiteUnaryExpression = {
  type: 'unary'
  operator: 'not' | 'bit-complement' | 'negate'
  expression: ESCalcLiteLogicalExpression
}

Value expression

Represents a single value, could be a parameter or a constant.

ts
export type ESCalcLiteValueExpression = {
  type: 'value'
  value:
    | { type: 'constant'; value: unknown }
    | { type: 'parameter'; name: string }
    | { type: 'list'; items: ESCalcLiteLogicalExpression[] }
}

Function expression

Represents a call to a function which can accept any number of arguments.

ts
export type ESCalcLiteFunctionExpression = {
  type: 'function'
  name: string
  arguments: ESCalcLiteLogicalExpression[]
}