🤖 AI Summary
This paper addresses the lack of a formal, faithful, and practical semantic model for modern regular expressions—particularly those with backtracking semantics. We present the first mechanized semantics for JavaScript regular expressions, fully supporting backtracking and provably equivalent to the ECMAScript specification. Our approach leverages the Coq proof assistant (Rocq) to achieve full mechanization: we introduce *contextual equivalence* as a novel behavioral characterization of regexes and deliver the first formal correctness proof of the PikeVM algorithm; additionally, we explicitly model the complete backtracking tree to precisely capture all matches and their priority order. Key contributions include: (1) the first fully verified semantic model for JavaScript regular expressions; (2) a concise, faithful, and complete formalization of backtracking semantics; and (3) foundational support for verifying regex rewriting rules and formally guaranteeing mainstream engine algorithms.
📝 Abstract
We present the first mechanized, succinct, practical, complete, and proven-faithful semantics for a modern regular expression language with backtracking semantics. We ensure its faithfulness by proving it equivalent to a preexisting line-by-line embedding of the official ECMAScript specification of JavaScript regular expressions. We demonstrate its practicality by presenting two real-world applications. First, a new notion of contextual equivalence for modern regular expressions, which we use to prove or disprove rewrites drawn from previous work. Second, the first formal proof of the PikeVM algorithm used in many real-world engines. In contrast with the specification and other formalization work, our semantics captures not only the top-priority match, but a full backtracking tree recording all possible matches and their respective priority. All our definitions and results have been mechanized in the Rocq proof assistant.