Pybites Logo Rust Platform

Mini Parser

Medium +3 pts

🎯 In Python, parsing a simple value might use json.loads or manual checking:

import json

def parse_primitive(text):
    text = text.strip()
    if text in ("true", "false"):
        return text == "true"
    if text == "null":
        return None
    return int(text)  # raises ValueError on bad input

Simple, but error handling is implicit — int() raises, json.loads raises, and callers need to know what exceptions to catch.

This exercise combines everything from the intro track: enums with data, pattern matching, Result for errors, string processing, and character-level parsing. You'll build a parser that handles JSON-style primitives with explicit, type-safe error handling.

Enums as both values and …

Login to see the full exercise.