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
Sectionis a container node that can hold nested sections and commandsCommandis a leaf node with positional argumentsTokenTypedescribes tokenizer output:NEWLINE,BRACE,COMMANDparse_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, andparse_text
Release files for krpgscript 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| krpgscript-0.1.0.tar.gz | 34.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| krpgscript-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:55.4 kB
Release files / krpgscript-0.1.0.tar.gz
| Download URL | krpgscript-0.1.0.tar.gz |
|---|---|
| Size | 34.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa19b05f404e91a0928a1573c061ba10ab59868139ea0a8922f905f74c188140
|
|
BLAKE2b-256 checksum How to use checksums |
e6af1475e37302543c1d8f9f9e081dbc86bd93b8d3d2415bc8b36f356357c355
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / krpgscript-0.1.0-py3-none-any.whl
| Download URL | krpgscript-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
721b3f2856229abd9ee20422f64eb10fe90702c67689fbcc46ceff6825c3ccf0
|
|
BLAKE2b-256 checksum How to use checksums |
07102a8677e3ec18a5147c885442e2666bc8ff89dccf644b25ebfaf9bd8fa16e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|