Hasty Briefsbeta

Writing a JSON Parser in BQN

a day ago
  • #BQN
  • #JSON-parser
  • #array-programming
  • BQN is an array programming language in the APL family.
  • The article describes writing a JSON parser in BQN, focusing on parsing lists of integers and strings.
  • The parser avoids branching and uses flat arrays for efficiency.
  • Tokenization involves replacing numbers with '0' and removing commas, then returning tokenized arrays and numbers.
  • Parsing involves reconstructing nested lists from flat representations using depth scans and permutations.
  • Strings are handled by identifying and escaping quotes, with backslash-based escaping supported.
  • Objects are parsed by distinguishing keys and values, using depth and nesting information.
  • The parser is compact, efficient, and handles typical JSON structures like lists, strings, and objects.
  • Debugging is straightforward due to the lack of branching and flat array operations.
  • The article concludes that while writing parsers in array languages is challenging, it is also highly enjoyable.