Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/com/alibaba/qlexpress4/aparser/QLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public class QLParser {

public static final int SELECTOR_START = QLexer.SELECTOR_START;

public static final int SELECTOR_END = QLexer.SELECTOR_END;

public static final int ID = QLexer.ID;

public static final int DOUBLE_QUOTE = QLexer.DOUBLE_QUOTE;
Expand Down Expand Up @@ -815,6 +817,8 @@ private PrimaryNoFixPathableContext parsePrimaryNoFixPathable() {
ctx.selectorStart = consumeNode(ctx);
ctx.selectorVariable = new TerminalNode(expect(SelectorVariable_VANME, "selector variable"));
ctx.addChild(ctx.selectorVariable);
ctx.selectorEnd = new TerminalNode(expect(SELECTOR_END, "selector end"));
ctx.addChild(ctx.selectorEnd);
return ctx;
}
if (isVarIdToken(lt().getType())) {
Expand Down Expand Up @@ -2967,6 +2971,8 @@ public static class ContextSelectExprContext extends PrimaryNoFixPathableContext

private TerminalNode selectorVariable;

private TerminalNode selectorEnd;

public TerminalNode SELECTOR_START() {
return selectorStart;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/alibaba/qlexpress4/aparser/QLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ public class QLexer {

public static final int CATCH_ALL = 97;

public static final int SELECTOR_END = 98;

private static final Map<String, Integer> KEYWORDS = new HashMap<>();

static {
Expand Down Expand Up @@ -406,6 +408,10 @@ private void readSelector() {
for (int i = 0; i < selectorEnd.length(); i++) {
advance();
}
int endStart = p;
int endLine = line;
int endCol = col;
add(SELECTOR_END, selectorEnd, endStart, endStart + selectorEnd.length() - 1, endLine, endCol);
return;
}
if (ch() == '\n' || ch() == '\r') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public TracePointTree visitTryCatchExpr(QLParser.TryCatchExprContext ctx) {

@Override
public TracePointTree visitContextSelectExpr(QLParser.ContextSelectExprContext ctx) {
return newPoint(TraceType.PRIMARY, Collections.emptyList(), ctx.getStart());
return newPoint(TraceType.PRIMARY, Collections.emptyList(), ctx.getText(), ctx.getStart());
}

// ==================== Private Helper ====================
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ public void expressionTraceTest() {
+ " | VALUE 2 2\n" + " | STATEMENT break null\n" + " | BLOCK result \n"
+ " | OPERATOR = \n" + " | VARIABLE result \n" + " | VALUE 0 \n",
resultSwitch.getExpressionTraces().get(0).toPrettyString(0));
QLResult resultSelect = express4Runner.execute("${a} + 1 == 2",
Collections.singletonMap("a", 1),
QLOptions.builder().traceExpression(true).build());
Assert.assertEquals(
"OPERATOR == true\n" + " | OPERATOR + 2\n" + " | PRIMARY ${a} 1\n" + " | VALUE 1 1\n"
+ " | VALUE 2 2\n",
resultSelect.getExpressionTraces().get(0).toPrettyString(0));
}

@Test
Expand Down