Русский | English
Typed parser for a small KRPG DSL.
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.
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
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
}
}
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)uv run python examples/run_example.pyValidate syntax for a file, directory, or glob:
krpgscript check examples/story.krpg examples/Format one or more files in place:
krpgscript format examples/**/*.krpgExport the tree to JSON:
krpgscript json examples/story.krpg -o story.jsonInstall dependencies:
uv sync --devRun tests:
just testRun linting and type checks:
just checkFormat code:
just fmtBuild release artifacts:
just buildValidate the release workflow:
just release-checkkrpgscript/
__init__.py
main.py
parser.py
examples/
run_example.py
story.krpg
tests/
test_parser.py
justfile
- 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