Skip to main content

ast_roller

An expressive, abstract syntax tree-based dice roller.

Installation

TBD

Usage

As a library:

>>> from ast_roller.grammar import parser, transformer
>>> roll_string = '2 2d20 kh1 + 8'
>>> eval_root = transformer.transform(parser.parse(roll_string))
>>> result_root = eval_root.evaluate()
>>> print(result_root.pretty_print())
List Expansion: 2 (2d20 kh1 + 8)
  Count: 2 => 2
  Expression: (2d20 kh1 + 8)
  Results: [21, 26]
  0: 
    (2d20 kh1 + 8) => ([13, 8] + 8) => 13 + 8 = 21
  1: 
    (2d20 kh1 + 8) => ([6, 18] + 8) => 18 + 8 = 26

As a command-line tool:

TBD

Design

This package processes dice rolls in tree main steps:

    1. Parse dice roll strings into syntax trees using Lark and a defined roll string grammar.
    1. Transforming the parse tree into an evaluation tree
    1. Recursively call evaluate() from the root of the evaluation tree.

This logic is spread across three files:

  • grammar.py: Contains the dice roll grammar and logic for transforming parse trees into eval trees.
  • evaluators.py: Handles evaluation logic.
  • results.py: Handles

Contributing

Contributions are welcome and should be pretty manageable. New roll features can be included by adding a definition for the new rule to the grammar and adding or modifying corresponding EvaluatorNode and ResultNode definitions to implement the actual logic.

Code changes must be accompanied by new or reconciled spec code in src/tests.

I feel lukewarm at best about the current output formats so if anyone has better ideas, I'd love an issue suggesting the changes.

Metadata

Release files for ast-roller 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ast-roller 0.0.1
File Size Uploaded Provenance
ast_roller-0.0.1.tar.gz 17.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ast-roller 0.0.1
File Interpreter ABI Platform
ast_roller-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 36.9 kB

Release files / ast_roller-0.0.1.tar.gz

Download URL ast_roller-0.0.1.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
04acaff62bf2a631a9b63bbcf02df8c246ad0db751dcf3a4c5132e25b128acb3
BLAKE2b-256 checksum
How to use checksums
a76faa2651bdba47d932c5661d15e8c6253532001ac24e78ee5ab6f72ddd785a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / ast_roller-0.0.1-py3-none-any.whl

Download URL ast_roller-0.0.1-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a456f933e7725b338da81723aa2615ad55eb048b57f71b1c1c4f29b76f727d27
BLAKE2b-256 checksum
How to use checksums
2b6b1586df644429cea5bba2bc2735d444b55c4633e75507ac217d4abd7a086d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for ast-roller 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page