https://github.com/notjustanna/dice-notation
Dice Notation parsing library, based off Kaiper
https://github.com/notjustanna/dice-notation
dice dice-notation java
Last synced: 10 months ago
JSON representation
Dice Notation parsing library, based off Kaiper
- Host: GitHub
- URL: https://github.com/notjustanna/dice-notation
- Owner: NotJustAnna
- License: apache-2.0
- Created: 2018-04-17T14:35:56.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-08-11T04:59:36.000Z (almost 7 years ago)
- Last Synced: 2025-01-02T03:46:19.620Z (over 1 year ago)
- Topics: dice, dice-notation, java
- Language: Java
- Size: 146 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DiceNotation Library
A full fledged Dice Notation (a.k.a `d20 + 2`) Java library.
The library was based of [Kaiper](https://github.com/Avarel/Kaiper) and even do mathematical expressions like `2 + 8 / 5`.
Licensed under the [Apache 2.0 License](https://github.com/arudiscord/dice-notation/blob/master/LICENSE).
### Installation

Using in Gradle:
```gradle
repositories {
jcenter()
}
dependencies {
compile 'pw.aru.libs:dice-notation:LATEST' // replace LATEST with the version above
}
```
Using in Maven:
```xml
central
bintray
http://jcenter.bintray.com
pw.aru.libs
dice-notation
LATEST
```
### Usage
The easiest way to start is by using the `SimpleDice` class.
```java
SimpleDice dice = new SimpleDice();
int value = dice.resolve("d20 + 2").intValue();
```
You can extend the class and override behaviour to your liking.
Alternatively, you can use the classes `DiceLexer`, `DiceParser`, `DiceSolver`, `DicePreEvaluator` and `DiceEvaluatorBuilder`.
```java
int value = new DiceParser(new DiceLexer("d20 + 2"))
.parse()
.accept(new DiceSolver(this::roll).andFinally(builder.build()));
```
The `DiceParser` generates AST which prints the original notation back with `Expr#toString`.
```java
String rolledDice = new DiceParser(new DiceLexer("d20+2"))
.parse()
.accept(new DiceSolver(this::roll)).toString();
```
### Support
Support is given on [Aru's Discord Server](https://discord.gg/URPghxg)
[](https://discord.gg/URPghxg)