Conversation
`range` is in the keyword table (reserved for the schema index-type
position, `CREATE RANGE INDEX …`) but was omitted from the primary-
expression arm that already accepts the other function-name keywords
(`count`, `type`, `key`). So `range(0, 10)` failed to parse
("unexpected token `range`") even though `range()` is a standard
openCypher list function, and a bare `range` could not be referenced in
expression position either.
`range` is a *contextual* keyword — special only where the index grammar
looks for it (handled separately in `parse_create_clause` /
`parse_create_index`), and an ordinary function/identifier everywhere
else. Adding `KW_RANGE` to the existing name-or-call arm routes it
through the same machinery as `type`/`count`/`key`: `range(start, end
[, step])` now parses as a FUNCTION_INVOCATION and a bare `range` stays a
valid variable name. No lexer change, no new AST, and the
`CREATE RANGE INDEX …` path is unaffected.
Tests (tests/ast_shape.rs, tests/smoke.rs): `range(0, 3)` and
`range(0, 10, 2)` parse as a FunctionCall with the right arity; `range`
remains a valid variable name; `RETURN range(…)` and `UNWIND range(…)`
parse; and a regression guard that `CREATE RANGE INDEX …` still parses.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
NotesThe fix is minimal and correct: Test coverage is thorough—function calls with 2 and 3 arguments, bare variable usage, placement in Reviewed by kimi-k2.6 · Input: 72.7K · Output: 5.6K · Cached: 888.8K |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
range(...)— a standard openCypher list function (UNWIND range(1, n)is idiomatic) — fails to parse in expression position withunexpected token 'range'. This adds the one missing dispatch entry sorangeparses as an ordinary function (and as a variable name), while staying reserved in the schema index-type position.Root cause
rangeis registered in the keyword table (parser/lexer.rs:"RANGE" => KW_RANGE) because it is reserved in the schema index-type position (CREATE RANGE INDEX …). But the primary-expression dispatch inparser/grammar/expr.rsonly routes a specific set of function-name keywords —KW_COUNT | KW_TYPE | KW_KEY— through the name-or-call machinery.KW_RANGEwas omitted, so in expression position it falls through to the error arm.In openCypher,
rangeis not a reserved word or keyword at all — it is an ordinary function name / identifier (grammar/openCypher.bnflists the reserved and non-reserved words;RANGEappears in neither, and function calls go through the generic function-invocation production).decypherreservingKW_RANGEis an implementation choice for theCREATE RANGE INDEXadmin syntax; that reservation should stay scoped to the index grammar (already handled inparse_create_clause/parse_create_index) and not leak into expression position — exactly howtype,count, andkeyare already treated here.Fix
Add
KW_RANGEto that existing arm. It reuses the same code path that already makestype(r)work as both a call and a name — no lexer change, no new AST node, and the schemaCREATE RANGE INDEXpath (which peeks forKW_RANGEbefore expression parsing) is untouched.Before / after
RETURN range(0, 3)FunctionCall"range", 2 args)UNWIND range(1, 5) AS x RETURN xWITH 1 AS range RETURN rangeCREATE RANGE INDEX FOR (n:Person) ON (n.name)Tests
tests/ast_shape.rs—range(0, 3)andrange(0, 10, 2)parse as aFunctionCallnamedrangewith two/three arguments;rangeremains usable as a variable name.tests/smoke.rs—RETURN range(…),UNWIND range(…), and a regression guard thatCREATE RANGE INDEX …still parses.All new tests fail on
mainand pass with the fix; the full test suite is green andcargo fmt/clippyare clean.Conformance
range()has a dedicated openCypher TCK feature,expressions/list/List11.feature("List11 — Create a list from a range"), and is exercised across many others — e.g.clauses/unwind/Unwind1.feature,clauses/return-skip-limit/ReturnSkipLimit1.feature, andexpressions/list/List2.feature(slicing). None of these can be attempted whilerange(...)fails to parse; they are natural downstream coverage for this fix.References
rangeis neither): https://github.com/opencypher/openCypher/blob/main/grammar/openCypher.bnfrange()feature: https://github.com/opencypher/openCypher/blob/main/tck/features/expressions/list/List11.feature