Interface ExpressionParser


public interface ExpressionParser
Expression Parser Interface 表达式解析器接口

Parses expression strings into Expression objects.

将表达式字符串解析为Expression对象。

Features | 主要功能:

  • Parse expression strings into evaluable Expression objects - 将表达式字符串解析为可求值的Expression对象
  • Support template expressions with embedded variables - 支持嵌入变量的模板表达式

Usage Examples | 使用示例:

ExpressionParser parser = OpenExpression.parser();
Expression expr = parser.parseExpression("price * quantity");
Object result = expr.getValue(context);

// Template parsing
Expression template = parser.parseTemplate("Hello #{name}");

Security | 安全性:

  • Thread-safe: Depends on implementation - 线程安全: 取决于实现
  • Null-safe: No, null expression throws exception - 空值安全: 否,null表达式抛出异常

Performance | 性能特性:

  • Time complexity: O(n) for parseExpression where n is the expression length - 时间复杂度: parseExpression 为 O(n),n为表达式长度
  • Space complexity: O(n) for the resulting AST - 空间复杂度: O(n),存储生成的 AST
Since:
JDK 25, opencode-base-expression V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    parseExpression(String expressionString)
    Parse expression string 解析表达式字符串
    default Expression
    parseTemplate(String templateString)
    Parse expression with template 使用模板解析表达式
  • Method Details

    • parseExpression

      Expression parseExpression(String expressionString)
      Parse expression string 解析表达式字符串
      Parameters:
      expressionString - the expression string | 表达式字符串
      Returns:
      the parsed expression | 解析后的表达式
      Throws:
      OpenExpressionException - if parsing fails | 如果解析失败
    • parseTemplate

      default Expression parseTemplate(String templateString)
      Parse expression with template 使用模板解析表达式

      Parses expressions embedded in template strings like "Hello #{name}".

      解析嵌入在模板字符串中的表达式,如"Hello #{name}"。

      Parameters:
      templateString - the template string | 模板字符串
      Returns:
      the parsed expression | 解析后的表达式