feat(python): support ellipsis in dot-access chain patterns#567
Merged
brandonspark merged 1 commit intomainfrom Mar 4, 2026
Merged
feat(python): support ellipsis in dot-access chain patterns#567brandonspark merged 1 commit intomainfrom
brandonspark merged 1 commit intomainfrom
Conversation
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>
ajbt200128
approved these changes
Mar 4, 2026
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
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
attributerule in the semgrep-python grammar to accept'...'as an alternative toidentifierin the attribute field positiona. ... .dparse correctly for matching call chainsfield_accessoverride (line 166-174 of semgrep-java/grammar.js)Context
Fixes semgrep/semgrep#11545
The Python tree-sitter grammar's
attributerule only allowsidentifierin 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 itsfield_accessoverride.After this grammar change is published, a corresponding mapper fix is needed in
semgrep-proprietary(Parse_python_tree_sitter.ml) to handle the newDOTDOTDOTCST variant and produceDotAccessEllipsisAST nodes.Test plan
make testpasses inlang/semgrep-grammars/src/semgrep-python/(all 117 tests pass)Parse_python_tree_sitter.mlto handle new CST variant🤖 Generated with Claude Code