{"id":13616402,"url":"https://github.com/phplrt/phplrt","last_synced_at":"2026-01-11T16:51:27.086Z","repository":{"id":34724784,"uuid":"182423953","full_name":"phplrt/phplrt","owner":"phplrt","description":"PHP Language Recognition Tool","archived":false,"fork":false,"pushed_at":"2024-02-21T00:53:48.000Z","size":6949,"stargazers_count":204,"open_issues_count":3,"forks_count":6,"subscribers_count":9,"default_branch":"3.x","last_synced_at":"2024-04-01T09:34:13.426Z","etag":null,"topics":["ast","combinator","compiler","grammar","lexer","library","ll1","llk","lookahead","parser","php","phplrt","recursive-descent-parser","tool","trace"],"latest_commit_sha":null,"homepage":"https://phplrt.org","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phplrt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-04-20T15:42:57.000Z","updated_at":"2024-04-15T01:51:42.100Z","dependencies_parsed_at":"2023-02-15T20:00:59.356Z","dependency_job_id":"7d9dc8d8-49a6-437c-a4fd-88e389ea324c","html_url":"https://github.com/phplrt/phplrt","commit_stats":{"total_commits":415,"total_committers":8,"mean_commits":51.875,"dds":"0.41445783132530123","last_synced_commit":"24c0613c9f9b8ef6639e297c58752225baf94a1a"},"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phplrt%2Fphplrt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phplrt%2Fphplrt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phplrt%2Fphplrt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phplrt%2Fphplrt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phplrt","download_url":"https://codeload.github.com/phplrt/phplrt/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223611991,"owners_count":17173559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","combinator","compiler","grammar","lexer","library","ll1","llk","lookahead","parser","php","phplrt","recursive-descent-parser","tool","trace"],"created_at":"2024-08-01T20:01:28.046Z","updated_at":"2026-01-11T16:51:27.060Z","avatar_url":"https://github.com/phplrt.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://phplrt.org/\"\u003e\n        \u003cimg src=\"https://avatars.githubusercontent.com/u/49816277?s=256\u0026v=4\" width=\"128\" alt=\"Phplrt\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/phplrt/phplrt\"\u003e\u003cimg src=\"https://poser.pugx.org/phplrt/phplrt/require/php?style=for-the-badge\" alt=\"PHP 7.4+\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/phplrt/phplrt\"\u003e\u003cimg src=\"https://poser.pugx.org/phplrt/phplrt/version?style=for-the-badge\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/phplrt/phplrt\"\u003e\u003cimg src=\"https://poser.pugx.org/phplrt/phplrt/v/unstable?style=for-the-badge\" alt=\"Latest Unstable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/phplrt/phplrt\"\u003e\u003cimg src=\"https://poser.pugx.org/phplrt/phplrt/downloads?style=for-the-badge\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://raw.githubusercontent.com/phplrt/phplrt/master/LICENSE.md\"\u003e\u003cimg src=\"https://poser.pugx.org/phplrt/phplrt/license?style=for-the-badge\" alt=\"License MIT\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/phplrt/phplrt/actions\"\u003e\u003cimg src=\"https://github.com/phplrt/phplrt/workflows/build/badge.svg?branch=3.x\u0026event=push\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Introduction\n\nThe phplrt is a set of tools for programming languages recognition. The library \nprovides lexer, parser, grammar compiler, library for working with errors, \ntext analysis and so on.\n\n## Installation\n\nPhplrt is available as composer repository and can be \ninstalled using the following command in a root of your project:\n\n```bash\n$ composer require phplrt/phplrt\n```\n\nMore detailed installation instructions [are here](https://phplrt.org/docs/installation).\n\n## Documentation\n\n- https://phplrt.org/\n\n## Quick Start\n\nFirst, we will create the grammar for our parser. \n\n\u003e You can read more about the grammar syntax [here](https://phplrt.org/docs/compiler/grammar).\n\n```php\n\u003c?php\n\nuse Phplrt\\Compiler\\Compiler;\n\n$compiler = new Compiler();\n$compiler-\u003eload(\u003c\u003c\u003cEBNF\n   \n    %token T_DIGIT          \\d\n    %token T_PLUS           \\+\n    %token T_MINUS          \\-\n    %token T_POW            \\*\n    %token T_DIV            /\n    %skip  T_WHITESPACE     \\s+\n    \n    #Expression\n      : \u003cT_DIGIT\u003e (Operator() \u003cT_DIGIT\u003e)* \n      ;\n\n    #Operator\n      : \u003cT_PLUS\u003e\n      | \u003cT_MINUS\u003e\n      | \u003cT_POW\u003e\n      | \u003cT_DIV\u003e\n      ;\n\nEBNF);\n```\n\n### Execution\n\nIn order to quickly check the performance of what has been written, you can use \nthe simple `parse()` method. As a result, it will output the recognized abstract \nsyntax tree along with the predefined AST classes which can be converted to their \nstring representation.\n\n```php\n\u003c?php\n\necho $compiler-\u003eparse('2 + 2');\n\n//\n// Output:\n//\n// \u003cExpression offset=\"0\"\u003e\n//     \u003cT_DIGIT offset=\"0\"\u003e2\u003c/T_DIGIT\u003e\n//     \u003cOperator offset=\"2\"\u003e\n//         \u003cT_PLUS offset=\"2\"\u003e+\u003c/T_PLUS\u003e\n//     \u003c/Operator\u003e\n//     \u003cT_DIGIT offset=\"4\"\u003e2\u003c/T_DIGIT\u003e\n// \u003c/Expression\u003e\n//\n```\n\n### Compilation\n\nAfter your grammar is ready and tested, it should be compiled. After that, \nyou no longer need the `phplrt/compiler` dependency (see https://phplrt.org/docs/installation#runtime-only).\n\n```php\nfile_put_contents(__DIR__ . '/grammar.php', (string)$compiler-\u003ebuild());\n```\n\nThis file will contain your compiled data that can be used in your custom parser.\n\n```php\nuse Phplrt\\Lexer\\Lexer;\nuse Phplrt\\Parser\\Parser;\nuse Phplrt\\Parser\\BuilderInterface;\nuse Phplrt\\Parser\\Context;\n\n$data = require __DIR__ . '/grammar.php';\n\n// Create Lexer from compiled data\n$lexer = new Lexer($data['tokens']['default'], $data['skip']);\n\n// Create Parser from compiled data\n$parser = new Parser($lexer, $data['grammar'], [\n\n    // Recognition will start from the specified rule\n    Parser::CONFIG_INITIAL_RULE =\u003e $data['initial'],\n\n    // Rules for the abstract syntax tree builder. \n    // In this case, we use the data found in the compiled grammar.\n    Parser::CONFIG_AST_BUILDER =\u003e new class($data['reducers']) implements BuilderInterface {\n        public function __construct(private array $reducers) {}\n\n        public function build(Context $context, $result)\n        {\n            $state = $context-\u003egetState();\n\n            return isset($this-\u003ereducers[$state])) \n                ? $this-\u003ereducers[$state]($context, $result)\n                : $result\n            ;\n        }\n    }\n]);\n\n// Now we are ready to parse any code using the compiled grammar\n\n$parser-\u003eparse(' ..... ');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphplrt%2Fphplrt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphplrt%2Fphplrt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphplrt%2Fphplrt/lists"}