From 7cc7672780811e948e82f49c8600abf0e88b4a87 Mon Sep 17 00:00:00 2001 From: opaopa6969 Date: Fri, 26 Jun 2026 22:26:44 +0900 Subject: [PATCH] chore: adopt unlaxer-dsl 3.0.7; widen StringConcat/BooleanEquality operands to Object node (#32) unlaxer-dsl 3.0.7 infers transparent-choice assoc operands as Object and resolves them to real AST nodes via mapTransparentValue (parser PR #46), so StringConcatExpr.right and BooleanEqualityExpr.left/right are now Object. - evalStringConcatExpr: node.right() is List. - BooleanEqualityExpr: add Object overload of resolveBooleanSourceOperand / renderBooleanOperandSource that evals a real node directly and falls back to the existing source-snippet path for text (if-source shadow unchanged). String concatenation and boolean-equality operands now evaluate faithfully on the AST instead of via a source re-parse. mvn verify green (check-test-baseline gate OK; only known #38 ternary failure remains). Co-Authored-By: Claude Opus 4.8 (1M context) --- pom.xml | 4 ++-- .../evaluator/ast/P4TypedAstEvaluator.java | 17 ++++++++++++++++- .../javacode/P4DefaultJavaCodeEmitter.java | 13 ++++++++++++- .../javacode/P4TypedJavaCodeEmitter.java | 17 ++++++++++++++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e1f11c4c..fd8df2d7 100644 --- a/pom.xml +++ b/pom.xml @@ -61,12 +61,12 @@ org.unlaxer unlaxer-common - 3.0.6 + 3.0.7 org.unlaxer unlaxer-dsl - 3.0.6 + 3.0.7 org.jetbrains diff --git a/src/main/java/org/unlaxer/tinyexpression/evaluator/ast/P4TypedAstEvaluator.java b/src/main/java/org/unlaxer/tinyexpression/evaluator/ast/P4TypedAstEvaluator.java index 26d70222..bfc9d7f0 100644 --- a/src/main/java/org/unlaxer/tinyexpression/evaluator/ast/P4TypedAstEvaluator.java +++ b/src/main/java/org/unlaxer/tinyexpression/evaluator/ast/P4TypedAstEvaluator.java @@ -381,7 +381,7 @@ private Object resolveVariableAny(String varName) { protected Object evalStringConcatExpr(StringConcatExpr node) { String leftStr = resolveStringLeaf(node.left()); List ops = node.op(); - List rights = node.right(); + List rights = node.right(); if (ops == null || ops.isEmpty()) { return leftStr; } @@ -1992,6 +1992,21 @@ private static boolean hasTopLevelStringConcat(String text) { } + /** + * BooleanComparable は透過 mapped choice のため、operand は実 AST ノード(Object)または + * source テキスト(String)として届く。ノードなら直接 eval(AST 経路に忠実)、 + * それ以外は従来の source-snippet 経路にフォールバックする。(tinyexpression #32) + */ + private boolean resolveBooleanSourceOperand(Object operand) { + if (operand instanceof TinyExpressionP4AST ast) { + return Boolean.TRUE.equals(toBoolean(eval(ast))); + } + if (operand instanceof String text) { + return resolveBooleanSourceOperand(text); + } + return operand != null && Boolean.TRUE.equals(toBoolean(operand)); + } + private boolean resolveBooleanSourceOperand(String rawSource) { String normalized = rawSource == null ? "" : rawSource.strip(); if (normalized.isEmpty()) { diff --git a/src/main/java/org/unlaxer/tinyexpression/evaluator/javacode/P4DefaultJavaCodeEmitter.java b/src/main/java/org/unlaxer/tinyexpression/evaluator/javacode/P4DefaultJavaCodeEmitter.java index f99caab5..6e27fac8 100644 --- a/src/main/java/org/unlaxer/tinyexpression/evaluator/javacode/P4DefaultJavaCodeEmitter.java +++ b/src/main/java/org/unlaxer/tinyexpression/evaluator/javacode/P4DefaultJavaCodeEmitter.java @@ -212,6 +212,17 @@ protected String evalStringComparisonExpr(StringComparisonExpr node) { }; } + /** + * BooleanComparable は透過 mapped choice のため operand は実 AST ノード(Object)または + * source テキスト(String)として届く。ノードなら直接コード生成、それ以外は従来の + * source-snippet 経路にフォールバックする。(tinyexpression #32) + */ + private String renderBooleanOperandSource(Object operand) { + if (operand instanceof TinyExpressionP4AST ast) return eval(ast); + if (operand instanceof String text) return renderBooleanOperandSource(text); + return "false"; + } + private String renderBooleanOperandSource(String rawSource) { String normalized = rawSource == null ? "" : rawSource.strip(); if (normalized.isEmpty()) { @@ -254,7 +265,7 @@ private String renderStringCandidateArguments(List candidates) protected String evalStringConcatExpr(StringConcatExpr node) { String leftExpr = renderStringLeaf(node.left()); List ops = node.op(); - List rights = node.right(); + List rights = node.right(); if (ops == null || ops.isEmpty()) return leftExpr; StringBuilder sb = new StringBuilder("(String.valueOf(").append(leftExpr).append(")"); int count = Math.min(ops.size(), rights.size()); diff --git a/src/main/java/org/unlaxer/tinyexpression/evaluator/javacode/P4TypedJavaCodeEmitter.java b/src/main/java/org/unlaxer/tinyexpression/evaluator/javacode/P4TypedJavaCodeEmitter.java index 1e742750..dbf048bf 100644 --- a/src/main/java/org/unlaxer/tinyexpression/evaluator/javacode/P4TypedJavaCodeEmitter.java +++ b/src/main/java/org/unlaxer/tinyexpression/evaluator/javacode/P4TypedJavaCodeEmitter.java @@ -228,7 +228,7 @@ private static String primitiveAccessor(ExpressionType type) { protected String evalStringConcatExpr(StringConcatExpr node) { String leftExpr = renderStringLeaf(node.left()); List ops = node.op(); - List rights = node.right(); + List rights = node.right(); if (ops == null || ops.isEmpty()) { return leftExpr; } @@ -376,6 +376,21 @@ protected String evalStringComparisonExpr(StringComparisonExpr node) { }; } + /** + * BooleanComparable は透過 mapped choice のため operand は実 AST ノード(Object)または + * source テキスト(String)として届く。ノードなら直接コード生成、それ以外は従来の + * source-snippet 経路にフォールバックする。(tinyexpression #32) + */ + private String renderBooleanOperandSource(Object operand) { + if (operand instanceof TinyExpressionP4AST ast) { + return eval(ast); + } + if (operand instanceof String text) { + return renderBooleanOperandSource(text); + } + return "false"; + } + private String renderBooleanOperandSource(String rawSource) { String normalized = rawSource == null ? "" : rawSource.strip(); if (normalized.isEmpty()) {