Hasty Briefsbeta

Bilingual

Parsers don't have to be complicated

21 hours ago
  • Parsers can be built with reusable primitives like bx::Scanner, avoiding complex generators or ad-hoc pointer-chasing code.
  • bx::Scanner is zero-copy, non-owning, and uses StringView to reference original input without allocation.
  • Key design constraints include zero-copy, one cursor, built-in line/column tracking, character classes, and a small public interface.
  • The scanner uses methods like accept, acceptWhile, and acceptUntil to consume tokens, and peek for non-consuming checks.
  • Empty returns indicate both 'no match' and 'matched nothing', useful for cases like URL path absence.
  • Examples include LineReader for reading lines, INI parsing with sub-scanners to bound scope, and file path normalization.
  • bx::Scanner simplifies tasks like URL parsing (75 lines), stack trace symbolication, and reduces dependencies like a removed INI library.
  • The tool replaces repeated whitespace/identifier loops and pattern-matching bugs in ad-hoc parsers.