antlr / antlr/antlr-php-runtime

Serialization of the Parser Tree

Open
#27 2 comments 0 reactions 0 assignees View on GitHub
enhancement
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.

![image](https://user-images.githubusercontent.com/592545/169416636-a2a3494f-2b1e-4bc4-85a8-6c2e24917224.png)

> `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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.