Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Raises `ValueError` for unknown names.

---

### Serialisation
### Serialization

---

Expand All @@ -225,7 +225,7 @@ Generate `parsertab.py` in the current working directory.

#### `Grammar.to_json() -> str`

Serialise the grammar structure (terminals, non-terminals, productions) to a JSON string. Semantic actions and regexes are **not** included.
Serialize the grammar structure (terminals, non-terminals, productions) to a JSON string. Semantic actions and regexes are **not** included.

---

Expand Down
6 changes: 3 additions & 3 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This project follows [Semantic Versioning](https://semver.org) and the
### Planned — Testing
- Add tests for LR(1) and LALR(1) parsers.
- Add tests for lexer and parser error handling.
- Add tests for serialisation round-trips.
- Add tests for serialization round-trips.
- Add edge-case tests (empty grammar, duplicate symbols, epsilon productions).
- Enforce minimum test coverage threshold.

Expand Down Expand Up @@ -62,7 +62,7 @@ This project follows [Semantic Versioning](https://semver.org) and the
- Improved `RuleList` error API.

### Fixed
- Reset lexer parameters when analysing a new string (`Lexer.__call__`).
- Reset lexer parameters when analyzing a new string (`Lexer.__call__`).

---

Expand All @@ -77,7 +77,7 @@ This project follows [Semantic Versioning](https://semver.org) and the

### Added
- SLR, LR(1), and LALR(1) parsers.
- Serialisation of lexer and parser to Python source files.
- Serialization of lexer and parser to Python source files.
- `@g.terminal` decorator for inline rule definition.
- `@g.production` decorator for inline production rules.
- `@g.lexical_error` and `@g.parsing_error` decorators.
Expand Down
2 changes: 1 addition & 1 deletion docs/defining-grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,4 @@ g2 = Grammar.from_json(json_str)
```

!!! note
JSON serialisation does not preserve terminal regexes, terminal rules, or semantic actions. It is useful for inspecting grammar structure, not for production use. Use [Python file serialisation](serialization.md) for production scenarios.
JSON serialization does not preserve terminal regexes, terminal rules, or semantic actions. It is useful for inspecting grammar structure, not for production use. Use [Python file serialization](serialization.md) for production scenarios.
4 changes: 2 additions & 2 deletions docs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Good error handling is one of PyJapt's core design goals. This page describes ho

## Lexical Error Handling

### Default behaviour
### Default behavior

When the lexer encounters a character that matches no terminal pattern, it calls the *lexical error handler*. By default, this adds an error message to the internal errors list and advances past the bad character.

Expand Down Expand Up @@ -70,7 +70,7 @@ if lexer.contain_errors:

## Syntactic Error Handling

### Default behaviour
### Default behavior

When the parser cannot find an action for the current `(state, token)` pair it enters *panic-mode recovery*: it calls the error handler and then skips input tokens until it finds one that fits the current state.

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| **Three LR parser types** | SLR, LR(1), and LALR(1) — choose the power level you need. |
| **Custom error handling** | Lexical and syntactic error handlers are first-class citizens. |
| **Semantic actions** | Attach a lambda or a decorated function to any production rule. |
| **Serialisation** | Pre-build the parsing tables and serialise them to a Python module for faster startup. |
| **Serialization** | Pre-build the parsing tables and serialize them to a Python module for faster startup. |
| **Decorator-based API** | Define terminals and production rules without leaving Python. |

---
Expand Down
4 changes: 2 additions & 2 deletions docs/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The parsing tables (ACTION and GOTO) encode which action to take for every (stat

When two actions are valid for the same (state, lookahead) pair, a conflict arises:

- **Shift-reduce (SR)** — the parser can either shift or reduce. PyJapt resolves SR conflicts in favour of **shift** (same as most tools, because it handles `if-else` correctly).
- **Shift-reduce (SR)** — the parser can either shift or reduce. PyJapt resolves SR conflicts in favor of **shift** (same as most tools, because it handles `if-else` correctly).
- **Reduce-reduce (RR)** — two different reductions are possible. PyJapt keeps whichever was registered first.

Conflicts are printed to `stderr` and stored in `parser.conflicts`:
Expand Down Expand Up @@ -141,4 +141,4 @@ print(parser.goto)
print(parser.augmented_grammar)
```

These are Python dicts and can be serialised — see [Serialisation](serialization.md).
These are Python dicts and can be serialized — see [Serialization](serialization.md).
14 changes: 7 additions & 7 deletions docs/serialization.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Serialisation
# Serialization

For large grammars, building the parsing tables from scratch on every run can take seconds. PyJapt lets you *serialise* the pre-computed tables into plain Python modules so that subsequent runs skip the construction step entirely.
For large grammars, building the parsing tables from scratch on every run can take seconds. PyJapt lets you *serialize* the pre-computed tables into plain Python modules so that subsequent runs skip the construction step entirely.

---

Expand All @@ -12,7 +12,7 @@ The generated classes extend `Lexer` and `ShiftReduceParser` respectively, so th

---

## Serialising the Lexer
## Serializing the Lexer

```python
import inspect
Expand Down Expand Up @@ -48,7 +48,7 @@ class MyLexer(Lexer):

---

## Serialising the Parser
## Serializing the Parser

```python
if __name__ == '__main__':
Expand Down Expand Up @@ -96,7 +96,7 @@ result = parser(lexer(source_code))

## Full Example

**`grammar.py`** — define the grammar and conditionally serialise:
**`grammar.py`** — define the grammar and conditionally serialize:

```python
import inspect
Expand Down Expand Up @@ -165,6 +165,6 @@ parsertab.py

## Caveats

- **Semantic actions are not serialised.** The generated parser still imports the original grammar module (`grammar_module_name`) at runtime to access production rules and semantic actions.
- **Semantic actions are not serialized.** The generated parser still imports the original grammar module (`grammar_module_name`) at runtime to access production rules and semantic actions.
- **The grammar module must be importable.** Make sure `grammar.py` (or whatever you named it) is on the Python path when running the generated classes.
- **Files are written to the current working directory.** Run the serialisation script from the directory where you want the files to be created.
- **Files are written to the current working directory.** Run the serialization script from the directory where you want the files to be created.