https://github.com/allejo/rosetta-phpscript
A blasphemous AST converter from JS to PHP that should never be used in production
https://github.com/allejo/rosetta-phpscript
Last synced: 10 months ago
JSON representation
A blasphemous AST converter from JS to PHP that should never be used in production
- Host: GitHub
- URL: https://github.com/allejo/rosetta-phpscript
- Owner: allejo
- Created: 2022-04-06T03:36:05.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-28T00:22:52.000Z (about 2 years ago)
- Last Synced: 2025-01-15T03:05:14.291Z (12 months ago)
- Language: PHP
- Homepage:
- Size: 366 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rosetta PhpScript
Oh dear god, why does this even exist?!
The highlight.php project is a PHP port of the highlight.js project allowing for server-side syntax highlighting. The highlight.php project is used widely in the PHP community ranging from a WordPress plugin to Symfony related websites to Laravel plugins. As highlight.js evolved, so did their grammar definitions allowing for intricate callbacks to be used. This made keeping highlight.php near impossible unless I wanted to maintain 190+ languages manually. Enter this project: parse JS grammar definitions and rewrite them as PHP grammar definitions.
Does this mean you can use this tool to convert JavaScript code into production-ready PHP code? Please no. Never do this! The amount of security holes that could be introduced because of that... The purpose of this tool is solely to translate pretty basic highlight.js grammars. So then why did I make this open source? Because it may help someone else with their niche use case.
## How does it work?
It uses Babel's parser to read JavaScript code and convert it into an abstract syntax tree (AST). Then we convert that AST into an AST that nikic's PHP-Parser supports and writes out the PHP.
## License
MIT