Skip to content

feat(python): support ellipsis in dot-access chain patterns#567

Merged
brandonspark merged 1 commit intomainfrom
bjwu/gh-11545-python-ellipsis-call-chain
Mar 4, 2026
Merged

feat(python): support ellipsis in dot-access chain patterns#567
brandonspark merged 1 commit intomainfrom
bjwu/gh-11545-python-ellipsis-call-chain

Conversation

@brandonspark
Copy link
Contributor

Summary

  • Override the attribute rule in the semgrep-python grammar to accept '...' as an alternative to identifier in the attribute field position
  • This lets semgrep patterns like a. ... .d parse correctly for matching call chains
  • Mirrors the existing Java field_access override (line 166-174 of semgrep-java/grammar.js)
  • Adds tree-sitter test case for the new pattern

Context

Fixes semgrep/semgrep#11545

The Python tree-sitter grammar's attribute rule only allows identifier in the attribute position. When a semgrep pattern uses ... in a dot-access chain (e.g., a. ... .d), the parser produces an ERROR node. Java already supports this via its field_access override.

After this grammar change is published, a corresponding mapper fix is needed in semgrep-proprietary (Parse_python_tree_sitter.ml) to handle the new DOTDOTDOT CST variant and produce DotAccessEllipsis AST nodes.

Test plan

  • make test passes in lang/semgrep-grammars/src/semgrep-python/ (all 117 tests pass)
  • Publish updated grammar and update submodule in semgrep-proprietary
  • Add mapper fix in Parse_python_tree_sitter.ml to handle new CST variant

🤖 Generated with Claude Code

Override the `attribute` rule to accept `'...'` as an alternative to
`identifier` in the attribute field. This lets semgrep patterns like
`a. ... .d` parse correctly for matching call chains, matching the
existing Java `field_access` behavior.

Fixes semgrep/semgrep#11545

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brandonspark brandonspark requested a review from a team as a code owner March 4, 2026 00:12
@brandonspark brandonspark requested a review from emjin March 4, 2026 00:12
@brandonspark brandonspark merged commit d68c1d8 into main Mar 4, 2026
32 of 47 checks passed
@brandonspark brandonspark deleted the bjwu/gh-11545-python-ellipsis-call-chain branch March 4, 2026 21:06
semgrep-ci bot pushed a commit to semgrep/semgrep that referenced this pull request Mar 5, 2026
…emgrep-proprietary#5749)

## Summary

- Bump `semgrep-python` submodule to pick up the grammar change that
allows `...` in the attribute position
- Update `Parse_python_tree_sitter.ml:map_attribute` to handle the new
`DOTDOTDOT` CST variant and produce `DotAccessEllipsis`
- Add test file for ellipsis in dot-access chain patterns

Fixes #11545

## Details

The Python semgrep grammar's `attribute` rule only allowed `identifier`
in the attribute field. When a pattern used `...` in a dot-access chain
(e.g., `a. ... .d`), the tree-sitter parser produced an ERROR node.

The AST node (`DotAccessEllipsis`) and generic mapping already existed
(used by the menhir parser path), so only the grammar extension and
CST-to-AST mapper needed updating.

**Grammar change** (in
[ocaml-tree-sitter-semgrep#567](semgrep/ocaml-tree-sitter-semgrep#567)):
Override `attribute` to accept `choice($.identifier, '...')`, mirroring
Java's `field_access` override.

**Mapper change**: Handle the new `` `DOTDOTDOT `` variant in
`map_attribute` to produce `DotAccessEllipsis(e, tok)`.

## Test plan

- [x] Pattern `a. ... .d` matches `a.b.c.d` in Python
- [x] Pattern `builder(). ... .compact()` matches realistic call chains
- [x] Existing Python parsing and matching tests pass
- [x] No parsing stats regression

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

synced from Pro 8da0218ea57744c0b073260a2fb96d21000b945a
semgrep-ci bot pushed a commit to semgrep/semgrep that referenced this pull request Mar 6, 2026
…emgrep-proprietary#5749)

## Summary

- Bump `semgrep-python` submodule to pick up the grammar change that
allows `...` in the attribute position
- Update `Parse_python_tree_sitter.ml:map_attribute` to handle the new
`DOTDOTDOT` CST variant and produce `DotAccessEllipsis`
- Add test file for ellipsis in dot-access chain patterns

Fixes #11545

## Details

The Python semgrep grammar's `attribute` rule only allowed `identifier`
in the attribute field. When a pattern used `...` in a dot-access chain
(e.g., `a. ... .d`), the tree-sitter parser produced an ERROR node.

The AST node (`DotAccessEllipsis`) and generic mapping already existed
(used by the menhir parser path), so only the grammar extension and
CST-to-AST mapper needed updating.

**Grammar change** (in
[ocaml-tree-sitter-semgrep#567](semgrep/ocaml-tree-sitter-semgrep#567)):
Override `attribute` to accept `choice($.identifier, '...')`, mirroring
Java's `field_access` override.

**Mapper change**: Handle the new `` `DOTDOTDOT `` variant in
`map_attribute` to produce `DotAccessEllipsis(e, tok)`.

## Test plan

- [x] Pattern `a. ... .d` matches `a.b.c.d` in Python
- [x] Pattern `builder(). ... .compact()` matches realistic call chains
- [x] Existing Python parsing and matching tests pass
- [x] No parsing stats regression

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

synced from Pro 8da0218ea57744c0b073260a2fb96d21000b945a
yosefAlsuhaibani pushed a commit to semgrep/semgrep that referenced this pull request Mar 7, 2026
…emgrep-proprietary#5749)

## Summary

- Bump `semgrep-python` submodule to pick up the grammar change that
allows `...` in the attribute position
- Update `Parse_python_tree_sitter.ml:map_attribute` to handle the new
`DOTDOTDOT` CST variant and produce `DotAccessEllipsis`
- Add test file for ellipsis in dot-access chain patterns

Fixes #11545

## Details

The Python semgrep grammar's `attribute` rule only allowed `identifier`
in the attribute field. When a pattern used `...` in a dot-access chain
(e.g., `a. ... .d`), the tree-sitter parser produced an ERROR node.

The AST node (`DotAccessEllipsis`) and generic mapping already existed
(used by the menhir parser path), so only the grammar extension and
CST-to-AST mapper needed updating.

**Grammar change** (in
[ocaml-tree-sitter-semgrep#567](semgrep/ocaml-tree-sitter-semgrep#567)):
Override `attribute` to accept `choice($.identifier, '...')`, mirroring
Java's `field_access` override.

**Mapper change**: Handle the new `` `DOTDOTDOT `` variant in
`map_attribute` to produce `DotAccessEllipsis(e, tok)`.

## Test plan

- [x] Pattern `a. ... .d` matches `a.b.c.d` in Python
- [x] Pattern `builder(). ... .compact()` matches realistic call chains
- [x] Existing Python parsing and matching tests pass
- [x] No parsing stats regression

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

synced from Pro 8da0218ea57744c0b073260a2fb96d21000b945a
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.

[Python] does not support ... in a call chain

2 participants