All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Using Parser Expression Grammars (PEGs) in Janet Programming Language

By

Bogdanp

7mo ago· 9 min readen

Summary

This article provides a comprehensive tutorial on using Parser Expression Grammars (PEGs) in the Janet programming language. It explains that Janet, a Lisp-like language, uses PEGs instead of regular expressions for string parsing. The guide covers how PEGs are defined using associative data structures with named rules, demonstrates basic PEG syntax and matching, and shows how to build more complex parsers with recursive rules and custom functions. The article includes practical examples of parsing different data formats and discusses advanced PEG features like lookahead and error handling.

Key quotes

· 3 pulled
Janet is a small, Lisp-like language. Unlike most programming languages, it offers no support for regular expressions. Instead, Janet supports parser expression grammars, or PEGs.
A PEG in Janet is usually described by an associative data structure that lists a series of rules. For each rule, the key is the name of the rule and the value is a description of the string that the rule will match.
What makes PEGs especially powerful is the ability for rules to refer to other rules (including recursive references) and for rules to run arbitrary functions.
Snippet from the RSS feed
Instructions on how to use parser expression grammars in Janet.

You might also wanna read