Skip to content

fix: support Unicode comparison operators ≠ ≥ ≤ (#414) - #452

Open
chenjunwenhao wants to merge 1 commit into
alibaba:mainfrom
chenjunwenhao:fix/issue-414-unicode-comparison-operators
Open

fix: support Unicode comparison operators ≠ ≥ ≤ (#414)#452
chenjunwenhao wants to merge 1 commit into
alibaba:mainfrom
chenjunwenhao:fix/issue-414-unicode-comparison-operators

Conversation

@chenjunwenhao

Copy link
Copy Markdown
Contributor

Summary

  • Add lexer recognition for Unicode comparison operators: ≠ (U+2260), ≥ (U+2265), ≤ (U+2264)
  • Register these Unicode symbols as binary operator aliases in OperatorManager, mapping them to the existing !=, >=, <= implementations
  • Add comprehensive test cases covering basic comparisons, mixed with variables, floating point numbers, negative numbers, and conditional expressions

Closes #414

Problem Analysis

Issue #414 reported that custom Unicode symbols like ≠, ≥, ≤ were not recognized by QLExpress 4's parser, resulting in QLSyntaxException. Users naturally expect these standard mathematical Unicode symbols to work as equivalents to their ASCII counterparts.

The root cause was twofold:

  1. The QLexer did not recognize these Unicode characters as valid operator tokens - they were falling through to the CATCH_ALL default case
  2. The OperatorManager had no operator entries for the Unicode symbols, so even if tokenized, the parser would not find matching binary operators

Fix

  1. QLexer.java: Added three new case entries in the readOperatorOrPunctuation() switch statement:

    • '\u2260' (≠) → emits NOEQ token
    • '\u2265' (≥) → emits GE token
    • '\u2264' (≤) → emits LE token
  2. OperatorManager.java: Registered the Unicode strings as keys in DEFAULT_BINARY_OPERATOR_MAP, pointing to the existing singleton operator instances:

    • "≠"UnequalOperator
    • "≥"GreaterEqualOperator
    • "≤"LessEqualOperator

Test plan

  • New test suite file src/test/resources/testsuite/independent/operator/unicode_comparison.ql covering:
    • Basic ≠, ≥, ≤ comparisons with integer literals
    • Comparisons with variables
    • Mixed Unicode and ASCII operators in the same expression
    • Floating point number comparisons
    • Negative number comparisons
    • Unicode operators inside if/else conditional blocks
  • New Java unit test Express4RunnerTest#unicodeComparisonOperatorsTest verifying the API-level behavior
  • All existing test suite tests continue to pass

Files changed

  • src/main/java/com/alibaba/qlexpress4/aparser/QLexer.java
  • src/main/java/com/alibaba/qlexpress4/runtime/operator/OperatorManager.java
  • src/test/resources/testsuite/independent/operator/unicode_comparison.ql (new)
  • src/test/java/com/alibaba/qlexpress4/Express4RunnerTest.java

Add lexer support for Unicode comparison operators:
- ≠ (U+2260, NOT EQUAL TO) as alias for !=
- ≥ (U+2265, GREATER-THAN OR EQUAL TO) as alias for >=
- ≤ (U+2264, LESS-THAN OR EQUAL TO) as alias for <=

Changes:
- QLexer: recognize Unicode chars and emit NOEQ/GE/LE tokens
- OperatorManager: register Unicode symbols as binary operator aliases
- Add comprehensive test cases in test suite and Express4RunnerTest

Closes alibaba#414
@CLAassistant

CLAassistant commented Jul 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

为什么自定义符号很多不支持 比如 ≠、≥、≤

2 participants