@samatawy/rules
    Preparing search index...

    Class ExpressionParser

    Parser class for parsing expressions from rule syntax. You should normally not need to use this parser directly, as it is primarily used internally by the RuleParser and ExecutableParser when parsing conditions and consequences from rule syntax. This parser handles parsing of literals, variables, function calls, logical expressions (AND/OR), comparison expressions (==, !=, <, >, <=, >=, in), arithmetic expressions (+, -, *, /, %), and ternary expressions (condition ? trueExpr : falseExpr). It uses a recursive descent parsing approach, starting with the most complex expressions (function calls, logical expressions) and working down to simpler expressions (literals, variables). The parser also handles operator precedence by first parsing lower-precedence operators (like + and -) before higher-precedence operators (like * and /).

    Index

    Constructors

    Methods

    • Parse a string expression into an Expression object that can be evaluated within the rule engine.

      Parameters

      • syntax: string

        The string representation of the expression to parse.

      Returns Expression

      An Expression object representing the parsed expression if successful.

      An error if the expression is empty or invalid.

    • Parameters

      • tokens: string[]
      • operators: string[]

      Returns { left: string; operator: string; right: string } | null

    • Safely split function arguments or array items) by commas while respecting nested structures like parentheses, brackets, and string literals.

      Parameters

      • argsSyntax: string

        the whole argument string, e.g. "candidate : scoreCandidate(candidate), otherArg: 5, arr: [1, 2, 3]"

      Returns string[]

      an array of individual argument strings

    • Parameters

      • tokens: string[]
      • target: string
      • startIndex: number

      Returns number