antlr / antlr/antlr-php-runtime
Serialization of the Parser Tree
- Dominant language
- PHP
- Stars
- 97
- Forks
- 18
- Avg merge
- 12m
- Merged PRs (30d)
- 2
Description
## ✨ Feature request
Make the parser tree serializable with the `\serialize()` function.
### Motivation
Making the parser tree takes most of the total computation time.
If I could "cache" it somehow, it would be great !
### Example
```php
$tree = $parser->program();
print(\serialize($tree));
```
yields
Serialization of 'Antlr\Antlr4\Runtime\Comparison\Equivalence@anonymous' is not allowed
### Alternatives
- Make the grammar more efficient (there's room, I'm a noob)
- Use a visitor to transpile to target language (but code gen is always tricky)
- Make my own AST from the parser tree, and somehow ensure it is serializable (contexts?)
- How do _YOU_ do it ?
### Additional context
The `vt` time is the visitor. The rest _could_ be cached, perhaps.
On more complex scripts, with nested flow statements, it goes up to seconds.

> `Cyprak` is the name of our budding DSL for an online role playing game (and is a pun on `sprak` == `language`)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.