Metadata-Version: 2.4
Name: bet-syntax
Version: 0.1.2
Summary: A parser for betting rules syntax
Author-email: kazatca <kazatca@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/kazatca/bet_syntax
Project-URL: Repository, https://github.com/kazatca/bet_syntax.git
Project-URL: Issues, https://github.com/kazatca/bet_syntax/issues
Keywords: betting,parser,syntax
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.7
Description-Content-Type: text/markdown

# bet-syntax

A parser for betting rules syntax. Parses structured betting rule definitions into JSON format.

## Installation

```bash
pip install bet-syntax
```

## Usage

```python
from bet_syntax import parse_input

rules_text = """
["Group Stage - 3", "Round of 32"] | * :: fh<sh x1
"Round of 16" | * :: fh<sh x1.5
"""

result = parse_input(rules_text)
print(result)
```

## Matching Games Against Rules

You can match a game against single or multiple rules to check if it satisfies any betting condition.

### Single Rule

Use `match_rule_to_game` to check if a game matches one rule:

```python
from bet_syntax import match_rule_to_game

game = {
    "roundName": "Quarter-finals",
    "gameName": "France - Morocco",
    "homeFTResult": 3,
    "awayFTResult": 1,
}

rule = '"Quarter-finals" | "France - Morocco" :: 3:1'
if match_rule_to_game(rule, game):
    print("Game matches the rule!")
```

### Multiple Rules

Use `match_rules_to_game` to check if a game matches ANY rule from a multiline string (OR logic):

```python
from bet_syntax import match_rules_to_game

game = {
    "roundName": "Quarter-finals",
    "gameName": "France - Morocco",
    "homeFTResult": 3,
    "awayFTResult": 1,
}

rules_text = """
"Quarter-finals" | "France - Morocco" :: 2:1 | 3:1 x3
"Quarter-finals" | "Spain - Belgium" :: 2:1 | 3:1 x3
"""

if match_rules_to_game(rules_text, game):
    print("Game matches at least one rule!")
```

The function returns `True` if the game satisfies any of the rules, `False` otherwise.

## Bet Syntax

Each rule has this shape:

```text
round selector | game selector :: bet syntax x multiplier
```

### Selectors

The part before `::` chooses which matches a rule applies to.

- Round selector: matches `roundName`
- Game selector: matches `gameName`

Examples:

```text
"Quarter-finals" :: 3:1
"Quarter-finals" | "France - Morocco" :: 3:1
"Round of 16" | * :: fh<sh
```

- Use a quoted value to match one exact round or game name.
- Use a list like `["Group Stage - 3", "Round of 32"]` to match several round names.
- Use `*` to match any game name.
- If you provide only one selector, it is treated as the round selector and the game selector becomes `*`.

### Bets

The part after `::` describes what result should match.

- Exact score: `3:1`
- Multiple score alternatives: `3:1 | 2:1`
- Half comparison: `fh<sh`, `fh=sh`, `fh>sh`
- Total goals: `total=4`

If a bet has multiple alternatives, `|` means OR. For example, `3:1 | 2:1` matches either final score.

### Multiplier

You can add a multiplier at the end with `x`:

```text
"Quarter-finals" | "France - Morocco" :: 3:1 x3
"Round of 16" :: fh<sh x1.5
```

- `x3` means multiplier `3`
- `x1.5` means multiplier `1.5`
- If no multiplier is provided, the default is `1`

### Example

```text
"Quarter-finals" | "France - Morocco" :: 3:1 | 2:1 x3
```

This rule means:

- apply only to the quarter-finals match between France and Morocco
- match either score `3:1` or `2:1`
- apply multiplier `3`

Or from the command line:

```bash
echo 'your rules here' | bet-syntax
```

## Development

Run tests:

```bash
make test
```

## License

MIT
