Metadata-Version: 2.4
Name: parsil-peg
Version: 0.1.0
Summary: A lightweight PEG parser combinator library for Python.
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Parsil

A lightweight PEG parser combinator library for Python.

Parsil provides a small set of composable parsing rules for building recursive-descent parsers. It is designed to be simple, readable, and easy to extend.

## Features

- Lightweight and dependency-free
- PEG-style parser combinators
- Recursive grammars
- Regular expression support
- Rule composition
- Rule transformation with `Map`
- Full-input parsing

## Installation

```bash
pip install parsil
```

Or install from source:

```bash
pip install -e .
```

## Quick Start

```python
from parsil import *

grammar = Grammar()

grammar["number"] = Regex(r"\d+")

parser = Parser(grammar, "123")

print(parser.parse("number"))
```

Output:

```text
123
```

## Example

```python
from parsil import *

grammar = Grammar()

grammar["word"] = Sequence(
    Literal("hello"),
    Literal(" "),
    Literal("world"),
)

parser = Parser(grammar, "hello world")

print(parser.parse("word"))
```

Output:

```python
["hello", " ", "world"]
```

## Available Rules

| Rule | Description |
|------|-------------|
| `Literal` | Match an exact string |
| `Regex` | Match a regular expression |
| `Sequence` | Match rules in order |
| `Choice` | Match the first successful rule |
| `Repeat` | Repeat a rule |
| `Ref` | Reference another grammar rule |
| `Map` | Transform a matched value |

## Project Structure

```
parsil/
├── grammar.py
├── parser.py
├── rules/
│   ├── literal.py
│   ├── regex.py
│   ├── sequence.py
│   ├── choice.py
│   ├── repeat.py
│   ├── ref.py
│   └── map.py
└── examples/
└── tests/
```

## Running Tests

```bash
pytest
```

## License

This project is licensed under the MIT License.
