,
Kim Mens
,
Siegfried Nijssen
Creative Commons Attribution 4.0 International license
Despite the availability of numerous tools and languages for detecting structural patterns in programs, their complexity often presents a steep learning curve. This highlights the need for a program query language that is easier to learn, use, and read while remaining sufficiently expressive for defining and detecting relevant structural coding patterns in program code. To address this challenge, we present Pyttern, a query language that extends Python syntax with regular-expression-inspired wildcards, enabling intuitive pattern-based querying of Python code. Its implementation relies upon a custom pushdown automaton describing how to match patterns over program parse trees, thus providing a robust foundation for structural code analysis. We evaluate Pyttern’s usability and effectiveness through a study involving 35 master’s students, who were asked to write seven different patterns to identify known programming misconceptions. The results demonstrate that Pyttern is both easy to learn and practical to use, at least for analysing small-scale programs.
@InProceedings{lienard_et_al:OASIcs.Programming.2025.23,
author = {Li\'{e}nard, Julien and Mens, Kim and Nijssen, Siegfried},
title = {{The Pyttern Program Query Language}},
booktitle = {Companion Proceedings of the 9th International Conference on the Art, Science, and Engineering of Programming (Programming 2025)},
pages = {23:1--23:15},
series = {Open Access Series in Informatics (OASIcs)},
ISBN = {978-3-95977-382-9},
ISSN = {2190-6807},
year = {2025},
volume = {134},
editor = {Edwards, Jonathan and Perera, Roly and Petricek, Tomas},
publisher = {Schloss Dagstuhl -- Leibniz-Zentrum f{\"u}r Informatik},
address = {Dagstuhl, Germany},
URL = {https://drops.dagstuhl.de/entities/document/10.4230/OASIcs.Programming.2025.23},
URN = {urn:nbn:de:0030-drops-243075},
doi = {10.4230/OASIcs.Programming.2025.23},
annote = {Keywords: Pyttern, Program Query Languages, Python, Pattern Matching, Parse Tree, Pushdown Automaton, Static Code Analysis, Wildcards, Tree Pattern Matching}
}
archived version
archived version