Skip to content

Add in and not-in expression operators (#170)#179

Closed
Jeckerson wants to merge 1 commit into
masterfrom
feature/not-in-operator
Closed

Add in and not-in expression operators (#170)#179
Jeckerson wants to merge 1 commit into
masterfrom
feature/not-in-operator

Conversation

@Jeckerson
Copy link
Copy Markdown
Member

Summary

Add support for in and not in (! in) as expression-level operators, enabling SQL-like membership tests in Zephir code.

Resolves #170
Related: phalcon/cphalcon#16812

Syntax

// Membership test
if x in [1, 2, 3] {
}

// Negated membership test
if x ! in [1, 2, 3] {
}

AST Output

  • expr in expr produces a node with type "in"
  • expr ! in expr produces a node with type "not-in"

Changes

  • parser/zephir.lemon: Added IN to operator precedence (same level as INSTANCEOF). Added two new xx_common_expr grammar rules for in and not in.
  • CHANGELOG.md: Updated unreleased section.
  • tests/operators/in.phpt: Basic in and not in test.
  • tests/operators/in-for-loop.phpt: Regression test ensuring in inside for loops still works and in as expression works within loop bodies.
  • tests/operators/in-complex.phpt: Complex expressions with method calls, static constants, and parenthesized expressions.

Notes

  • The existing in keyword for for loops is completely unaffected (0 parser conflicts).
  • All 113 tests pass (110 existing + 3 new).
  • The Zephir compiler will need a separate update to handle the new "in" and "not-in" AST node types — a companion issue will be created in zephir-lang/zephir.

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Add support for 'in' and 'not in' (written as '! in') as expression-level
operators, enabling SQL-like membership tests in Zephir code.
Syntax:
  if x in [1, 2, 3] { }
  if x ! in [1, 2, 3] { }
The parser produces AST nodes with types 'in' and 'not-in' respectively.
The existing 'in' keyword for for-loops is unaffected.
Closes #170
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.24%. Comparing base (c2a6cd6) to head (f094983).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
+ Coverage   77.07%   77.24%   +0.17%     
==========================================
  Files           5        5              
  Lines        2992     2997       +5     
  Branches      131      131              
==========================================
+ Hits         2306     2315       +9     
+ Misses        686      682       -4     
Flag Coverage Δ
Linux 77.24% <100.00%> (+0.17%) ⬆️
unittests 77.24% <100.00%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 2, 2026

@Jeckerson
Copy link
Copy Markdown
Member Author

Closing this PR.

After investigating the original cphalcon issue (phalcon/cphalcon#16812), the root cause is a string literal typo in phalcon/Mvc/Model/Query.zep line ~2093 where "BETWEEN NOT" should be "NOT BETWEEN". This is a one-line fix in cphalcon, not a Zephir parser issue.

The PHQL scanner/parser already handles NOT IN (PHQL_T_NOTIN) and NOT BETWEEN (PHQL_T_BETWEEN_NOT) correctly at the C level. Adding in/not in as Zephir language expression operators is not needed to resolve the bug.

See analysis comment: phalcon/cphalcon#16812 (comment)

@Jeckerson Jeckerson closed this Apr 2, 2026
@Jeckerson Jeckerson deleted the feature/not-in-operator branch April 2, 2026 23:17
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.

Add NOT IN or BETWEEN IN support

1 participant