A parser analyzes structured input and produces a representation for further processing. A lightweight markup parser can recognize headers, bold, italic, links, and plain text, yet deceptively simple regex implementations fail on nesting, ambiguous delimiters, and parentheses inside URLs. section 8.2
A plausible parser that breaks
An initial Python implementation splits lines for headers, then applies regular expressions for bold, italic, and links. Happy-path inputs work, but nested formatting produces garbage, an unanchored lazy match pairs stray asterisks incorrectly, and URLs containing parentheses break parsing. section 8.2
Treat parser correctness as an evaluated engineering problem:
- Test each supported construct independently, then add combinations such as a header followed by a paragraph containing a link. section 8.2
- Use static analysis to inspect regex behavior rather than accepting the folklore that every regex is slow. section 8.2.2
- Reject or redesign patterns with nested quantifiers when unclosed input can trigger exponential backtracking and denial of service. section 8.2.2
