Skip to content

Allow "new" as identifier in non-expression contexts - #18

Open
cemrehancavdar wants to merge 1 commit into
b0o:masterfrom
cemrehancavdar:fix/new-as-identifier
Open

Allow "new" as identifier in non-expression contexts#18
cemrehancavdar wants to merge 1 commit into
b0o:masterfrom
cemrehancavdar:fix/new-as-identifier

Conversation

@cemrehancavdar

Copy link
Copy Markdown

Problem

new is currently only recognized as the operator in C++ new expressions
(e.g., new SomeType(args)). When used as a plain identifier — which is valid
Cython and common in real-world code — the parser produces an error.

Example from numpy/random/_generator.pyx#L943:

new = cdf.searchsorted(x, side='right')
new = new.take(unique_indices)

Fix

Add "new" to the keyword_identifier rule in grammar.js. This allows
new to be used as an identifier at lower precedence (-3) while preserving
the existing new_expression rule at precedence 23 for C++ new Type(args)
syntax.

Changes

  • grammar.js: add "new" to keyword_identifier choice list (1 line)
  • test/corpus/expressions.txt: add "New as identifier" test case

All 155 tests pass (154 existing + 1 new).

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.

1 participant