Skip to main content

Typed parser and runtime engine for tiny text RPG scripts

Project description

krpgscript

Русский | English

Typed parser for a small KRPG DSL.

What It Does

krpgscript parses a brace-based text format into a tree of Section and Command nodes. It is intentionally small and focused on syntax parsing, not on game runtime execution.

Core Concepts

  • Section is a container node that can hold nested sections and commands
  • Command is a leaf node with positional arguments
  • TokenType describes tokenizer output: NEWLINE, BRACE, COMMAND
  • parse_text() is the main entry point for parsing raw text into an AST

Example Syntax

See examples/story.krpg for a minimal demo.

game {
    title "Small Demo"
    version 1

    player "Aria" {
        hp 100
        mp 25
        skill "quick strike"
    }

    scene intro {
        say "You wake up in a quiet room."
        choice "Open the door" goto hall
        choice "Go back to sleep" goto sleep
    }
}

Usage

Parse text in Python

from pathlib import Path

from krpgscript import Command, Section, parse_text

root = parse_text(Path("examples/story.krpg").read_text(encoding="utf-8"))

game = root.get("game", command=False, section=True)
assert isinstance(game, Section)

for child in game.children:
    if isinstance(child, Command):
        print(child.name, child.args)
    else:
        print(child.name, child.args)

Run the demo example

uv run python examples/run_example.py

CLI

Validate syntax for a file, directory, or glob:

krpgscript check examples/story.krpg examples/

Format one or more files in place:

krpgscript format examples/**/*.krpg

Export the tree to JSON:

krpgscript json examples/story.krpg -o story.json

Development

Install dependencies:

uv sync --dev

Run tests:

just test

Run linting and type checks:

just check

Format code:

just fmt

Build release artifacts:

just build

Validate the release workflow:

just release-check

Project Layout

krpgscript/
  __init__.py
  main.py
  parser.py
examples/
  run_example.py
  story.krpg
tests/
  test_parser.py
justfile

Notes

  • The package has no runtime dependencies
  • The public API lives in krpgscript/init.py
  • The current parser API is Section, Command, TokenType, tokenize, parse, and parse_text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

krpgscript-0.1.0.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

krpgscript-0.1.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file krpgscript-0.1.0.tar.gz.

File metadata

  • Download URL: krpgscript-0.1.0.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for krpgscript-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa19b05f404e91a0928a1573c061ba10ab59868139ea0a8922f905f74c188140
MD5 997e54529a027ed0b2f5dba03f640191
BLAKE2b-256 e6af1475e37302543c1d8f9f9e081dbc86bd93b8d3d2415bc8b36f356357c355

See more details on using hashes here.

File details

Details for the file krpgscript-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: krpgscript-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for krpgscript-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 721b3f2856229abd9ee20422f64eb10fe90702c67689fbcc46ceff6825c3ccf0
MD5 b4ba4389bd12fec8b4179a64dd6ec961
BLAKE2b-256 07102a8677e3ec18a5147c885442e2666bc8ff89dccf644b25ebfaf9bd8fa16e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page