← All procedures

algebra.parseExpr

This function parses the arithmetic of a document, or it throws an error that tells where the text stops making sense.

CLI
Package
@procedures/algebra · README
Path
["algebra","parseExpr"]
CLI
mark algebra parseExpr --text <string>
As data
{"$proc":["algebra","parseExpr"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/algebra/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["algebra","parseExpr"], { text: "<text>" });
console.log(JSON.stringify(result));

From the command line

$ mark algebra parseExpr --text <string>

As data, in a program

{ "$proc": ["algebra", "parseExpr"], "input": { "text": "<text>" } }

Input

FieldTypeRequiredDefaultDescription
textstringyes

Output

The schema does not list fields (object | object | object | object | object).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string"
      }
    },
    "required": [
      "text"
    ],
    "additionalProperties": false
  },
  "output": {
    "anyOf": [
      {
        "type": "object",
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "*",
              "+",
              "-",
              "/"
            ]
          },
          "a": {
            "allOf": [
              {
                "$ref": "#"
              }
            ]
          },
          "b": {
            "allOf": [
              {
                "$ref": "#"
              }
            ]
          }
        },
        "required": [
          "op",
          "a",
          "b"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "op": {
            "type": "string",
            "const": "knob"
          },
          "name": {
            "type": "string"
          }
        },
        "required": [
          "op",
          "name"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "op": {
            "type": "string",
            "enum": [
              "ceil",
              "floor",
              "max",
              "min",
              "pow"
            ]
          },
          "args": {
            "type": "array",
            "items": {
              "allOf": [
                {
                  "$ref": "#"
                }
              ]
            }
          }
        },
        "required": [
          "op",
          "args"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "op": {
            "type": "string",
            "const": "neg"
          },
          "a": {
            "allOf": [
              {
                "$ref": "#"
              }
            ]
          }
        },
        "required": [
          "op",
          "a"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "op": {
            "type": "string",
            "const": "num"
          },
          "n": {
            "type": "object",
            "properties": {
              "n": {
                "type": "string",
                "pattern": "^-?(0|[1-9][0-9]*)$",
                "x-procedures-codec": "bigint"
              },
              "d": {
                "type": "string",
                "pattern": "^-?(0|[1-9][0-9]*)$",
                "x-procedures-codec": "bigint"
              }
            },
            "required": [
              "n",
              "d"
            ],
            "additionalProperties": {}
          }
        },
        "required": [
          "op",
          "n"
        ],
        "additionalProperties": {}
      }
    ]
  }
}