{"id":15168551,"url":"https://github.com/antononcube/raku-ebnf-grammar","last_synced_at":"2026-01-20T08:08:18.332Z","repository":{"id":176541822,"uuid":"658183568","full_name":"antononcube/Raku-EBNF-Grammar","owner":"antononcube","description":"Raku package for EBNF parsing and interpretation.","archived":false,"fork":false,"pushed_at":"2024-12-27T17:48:16.000Z","size":67,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-15T09:34:01.840Z","etag":null,"topics":["code-generation","ebnf","grammar","raku"],"latest_commit_sha":null,"homepage":"https://raku.land/zef:antononcube/EBNF::Grammar","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antononcube.png","metadata":{"files":{"readme":"README-work.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2023-06-25T03:07:18.000Z","updated_at":"2024-12-27T17:48:19.000Z","dependencies_parsed_at":"2024-09-14T01:21:59.565Z","dependency_job_id":"814d0630-5264-4dba-a097-9bcdf0913e20","html_url":"https://github.com/antononcube/Raku-EBNF-Grammar","commit_stats":{"total_commits":92,"total_committers":1,"mean_commits":92.0,"dds":0.0,"last_synced_commit":"b3632db4ce6bbe16a6f96efe7baaad65b5244eae"},"previous_names":["antononcube/raku-ebnf-grammar"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-EBNF-Grammar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-EBNF-Grammar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-EBNF-Grammar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antononcube%2FRaku-EBNF-Grammar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antononcube","download_url":"https://codeload.github.com/antononcube/Raku-EBNF-Grammar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248059085,"owners_count":21040882,"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":["code-generation","ebnf","grammar","raku"],"created_at":"2024-09-27T06:22:24.155Z","updated_at":"2026-01-20T08:08:18.293Z","avatar_url":"https://github.com/antononcube.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EBNF::Grammar Raku package\n\n## Introduction\n\nRaku package for Extended Backus-Naur Form (EBNF) parsing and interpretation.\n\nThe grammar follows the description of the Wikipedia entry \n[\"Extended Backus–Naur form\"](https://en.wikipedia.org/wiki/Extended_Backus–Naur_form), [Wk1],\nwhich refers to the *proposed* ISO/IEC 14977 standard, by R. S. Scowen, page 7, table 1. [RS1, ISO1].\n\n### Motivation\n\nThe main motivation for this package is to have:\n1. Multiple EBNF styles parsed (quickly)\n2. Grammar generation for multiple languages\n\nThe motivation comes from the the \"need\" to parse (and interpret) EBNF grammars\ngenerated with Large Language Models (LLMs), like ChatGPT and PaLM. For more details see\n[\"Incremental grammar enhancement\"](https://github.com/antononcube/Raku-EBNF-Grammar/blob/main/doc/Incremental-grammar-enhancement.md).\n\nI considered extending [\"Grammar::BNF\"](https://raku.land/github:tadzik/Grammar::BNF),\nbut ultimately decided that \"Grammar::BNF\" needs too much refactoring for my purposes,\nand, well, it is for BNF not EBNF.\n\n------\n\n## Installation\n\nFrom [Zef ecosystem](https://raku.land):\n\n```\nzef install EBNF::Grammar;\n```\n\nFrom GitHub:\n\n```\nzef install https://github.com/antononcube/Raku-EBNF-Grammar.git\n```\n\n------\n\n## Usage examples\n\nHere is an EBNF grammar for integers and its interpretation into a Raku grammar:\n\n```perl6\nuse EBNF::Grammar;\n\nmy $ebnf = q:to/END/;\n\u003cdigit\u003e = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;\n\u003cinteger\u003e = \u003cdigit\u003e , { \u003cdigit\u003e } ;\n\u003cTOP\u003e = \u003cinteger\u003e ;\nEND\n\nebnf-interpret($ebnf);\n```\n\nHere the obtained Raku grammar is evaluated and used to do a few parsings:  \n\n```perl6\nmy $gr = ebnf-interpret($ebnf):eval;\n\n.say for \u003c212 89 9090\u003e.map({ $gr.parse($_) });\n```\n\n------\n\n### Random sentence generation\n\nRandom sentences of grammars given in EBNF can be generated with additional help of the package \n[\"Grammar::TokenProcessing\"](https://github.com/antononcube/Raku-Grammar-TokenProcessing), [AAp2].\n\nHere is an EBNF grammar:\n\n```perl6\nmy $ebnfCode = q:to/END/;\n\u003cstatement\u003e = \u003cwho\u003e , \u003cverb\u003e , \u003clang\u003e ;\n\u003cwho\u003e = 'I' | 'We' ;\n\u003cverb\u003e = [ 'really' ] , ( 'love' | 'hate' | { '♥️' } | '🤮' );\n\u003clang\u003e = 'Julia' | 'Perl' | 'Python' | 'R' | 'WL' ; \nEND\n```\n\nHere is the corresponding Raku grammar:\n\n```perl6, result=asis, output-prompt=NONE, output-lang=perl6\nebnf-interpret($ebnfCode, name=\u003e'LoveHateProgLang');\n```\n\nHere we generate random sentences:\n\n```perl6\nuse Grammar::TokenProcessing;\n\nmy $gr = ebnf-interpret($ebnfCode, name=\u003e'LoveHateProgLang'):eval;\n\n.say for random-sentence-generation($gr, '\u003cstatement\u003e') xx 12;\n```\n\n------\n\n## CLI\n\nThe package provides a Command Line Interface (CLI) script for parsing EBNF. Here is its usage message:\n\n```shell\nebnf-parse --help\n```\n\n------\n\n## Implementation notes\n\n1. The first version of \"EBNF::Grammar::Standardish\" was *generated* with \"FunctionalParsers\", [AAp1], using the EBNF grammar (given in EBNF) in [Wk1].\n2. Refactored `\u003cterm\u003e` (originally `\u003cpTERM\u003e`) into separate parenthesized, optional, and repeated specs.\n   - This corresponds to the design in \"FunctionalParsers\". \n3. Tokens and regexes were renamed. (More concise, easier to read names.)\n4. Implemented the \"relaxed\" version of the standard EBNF.\n\n------\n\n## Comparison with other packages\n\nThe following table overviews the similarities and differences of this package\nwith the packages \"FunctionalParsers\" and \"Grammar::TokenProcessing\":\n\n| Feature                          | FunctionalParsers | EBNF::Grammar | Grammar::TokenProcessing | \n|:---------------------------------|:-----------------:|:-------------:|:------------------------:|\n| **Parsing EBNF:**                |                   |               |            ✔             |           \n| Standard                         |         ✔         |       ✔       |                          |           \n| Modified versions                |         ✔         |       ✔       |                          |           \n| Whatever                         |         ✔         |               |                          |           \n| Automatic top rule determination |         ✔         |               |                          |           \n| **Parsing Raku grammar:**        |                   |               |            ✔             |           \n| Pick left and pick right         |         ✔         |               |                          |           \n| Skip element                     |                   |               |            ✔             |           \n| Automatic top rule determination |         ✔         |               |            ✔             |           \n| Comprehensive quantifiers        |                   |               |            ✔             |           \n| **Interpretation:**              |         ✔         |       ✔       |                          |           \n| Raku grammar                     |         ✔         |       ✔       |                          |           \n| EBNF grammar (standard)          |         ✔         |               |            ✔             |           \n| WL grammar                       |         ✔         |               |                          |           \n| Java functional parsers          |         ✔         |               |                          |           \n| Raku functional parsers          |         ✔         |               |                          |           \n| Scala functional parsers         |         ✔         |               |                          |           \n| WL functional parsers            |         ✔         |       ✔       |                          |           \n| **Random sentence generation**   |         ✔         |               |            ✔             |           \n| **CLI**                          |         ✔         |       ✔       |            ✔             |           \n\nHere are some additional- and clarification points:\n\n- Since one of the motivations for \"FunctionalParsers\" and \"EBNF::Grammar\" is parsing and interpretation of EBNF\ngrammars derived with Large Language Models (LLMs) multiple EBNF variants have to be parsed.\n  - And a `Whatever` parsing method would be of great convenience.\n\n- It is envisioned that \"EBNF::Grammar\" is completed with functionalities from \"Grammar::TokenProcessing\". \n  - (Like random sentence generation.)  \n\n- Both \"FunctionalParsers\" and \"EBNF::Grammar\" generate Functional Parsers (FPs) for other programming languages\nbecause many languages have packages implementing FPs.\n\n- The interpretations to FPs of other programming languages (Java, Swift) with \"EBNF::Grammar\" will be also implemented.\n\n- In many cases the parsing with \"EBNF::Grammar\" is much faster than \"FunctionalParsers\".\n  - The conjecture that that would be case was one of the motivations for implementing of \"EBNF::Grammar\".\n\n- Cross-interfacing:\n  - The package \"Grammar::TokenProcessing\" can translate Raku grammars into EBNFs.\n  - Both \"FunctionalParsers\" and \"EBNF::Grammar\" can translate EBNFs into Raku grammars.\n  - \"EBNF::Grammar\" can generate parser classes that are utilizing the FPs of \"FunctionalParsers\". \n  \nThe following diagram summarizes the relationships (and implied workflows) in the comparison table\nand clarification points above:\n\n```mermaid\ngraph TD\n    EBNF\u003eEBNF]\n    RakuGrammar\u003e\"Raku grammar\"]\n    FPClass\u003e\"Functional parsers class\u003cbr/\u003e(grammar)\"]\n    FPs[[FunctionalParsers::EBNF]]\n    FPsEBNFMmdGraph[[FunctionalParsers::EBNF::Actions::MermaidJS::Graph]]\n    FPsEBNFWLGraph[[FunctionalParsers::EBNF::Actions::WL::Graph]]\n    EBNFGram[[EBNF::Grammar]]\n    GT[[Grammar::TokenProcessing]]\n    RS\u003eRandom sentences]\n    RakuAST\u003eRaku AST]\n    MmdGraph\u003eMermaid JS\u003cbr\u003egraph]\n    WLGraph\u003eMathematica/WL\u003cbr\u003egraph]\n    EBNF --\u003e FPs \n    EBNF --\u003e EBNFGram\n    EBNFGram --\u003e |ebnf-interpret|FPClass\n    EBNFGram --\u003e |ebnf-grammar-graph|RakuAST\n    FPs --\u003e |fp-ebnf-parse|FPClass\n    GT --\u003e |random-sentence-generation|RS\n    FPClass --\u003e |fp-random-sentence|RS\n    FPs --\u003e |fp-ebnf-parse|RakuAST\n    RakuAST --\u003e |fp-grammar-graph|FPsEBNFMmdGraph\n    FPsEBNFMmdGraph --\u003e MmdGraph\n    RakuAST --\u003e |fp-grammar-graph|FPsEBNFWLGraph\n    FPsEBNFWLGraph --\u003e WLGraph\n    EBNFGram --\u003e |ebnf-interpret|RakuGrammar\n    FPs --\u003e |fp-ebnf-interpret|RakuGrammar\n    RakuGrammar --\u003e GT\n```\n\n------\n\n## TODO\n\n- [ ] TODO Parsing of EBNF\n    - [X] DONE Parse apply function, `\u003c@` \n    - [ ] TODO Sequence-pick-left, `\u003c\u0026`\n    - [ ] TODO Sequence-pick-right, `\u0026\u003e`\n    - [ ] TODO \"Named\" tokens\n        - [ ] `'_?StringQ'` or `'_String'`\n        - [ ] `'_WordString'`, `'_LetterString'`, and `'_IdentifierString'`\n        - [ ] `'_?NumberQ'` and `'_?NumericQ'`\n        - [ ] `'_Integer'`\n        - [ ] `'Range[*from*, *to*]'`\n- [ ] TODO Interpreters of EBNF\n    - [ ] TODO Java\n        - [ ] TODO [\"funcj.parser\"](https://github.com/typemeta/funcj/tree/master/parser)\n    - [ ] TODO Mermaid JS\n      - [X] DONE Simple\n      - [ ] TODO Proper\n        - Most likely, via \"FunctionalParsers\"\n    - [ ] TODO Scala\n        - [ ] TODO built-in\n        - [ ] TODO [parsley](https://github.com/j-mie6/parsley)\n    - [ ] MAYBE Python\n    - [ ] TODO Raku\n        - [X] DONE Grammar\n        - [X] DONE FunctionalParsers\n        - [ ] TODO MermaidJS\n        - [ ] Other EBNF styles\n    - [ ] TODO WL\n        - [X] DONE FunctionalParsers, [AAp1, AAp2]\n        - [ ] TODO GrammarRules\n- [X] DONE Implement grammar-graph translator\n  - Introduced dependency on [\"FunctionalParsers\"](https://github.com/antononcube/Raku-FunctionalParsers) \n- [X] DONE CLI\n\n------\n\n## References\n\n### Articles\n\n[Wk1] Wikipedia entry, [\"Extended Backus–Naur form\"](https://en.wikipedia.org/wiki/Extended_Backus–Naur_form).\n\n[RS1] Roger S. Scowen: Extended BNF — A generic base standard. Software Engineering Standards Symposium 1993.\n\n[ISO1] [ISO/IEC 14977:1996](https://www.iso.org/standard/26153.html).\n\n### Packages, repositories\n\n[AAp1] Anton Antonov,\n[FunctionParsers Raku package](https://github.com/antononcube/Raku-FunctionalParsers),\n(2023),\n[GitHub/antononcube](https://github.com/antononcube).\n\n[AAp2] Anton Antonov,\n[Grammar::TokenProcessing Raku package](https://github.com/antononcube/Raku-Grammar-TokenProcessing),\n(2022-2023),\n[GitHub/antononcube](https://github.com/antononcube).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fraku-ebnf-grammar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantononcube%2Fraku-ebnf-grammar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantononcube%2Fraku-ebnf-grammar/lists"}