{"id":18305068,"url":"https://github.com/lfkdsk/bnf-ast","last_synced_at":"2025-04-05T16:32:27.206Z","repository":{"id":94081759,"uuid":"118554642","full_name":"lfkdsk/bnf-ast","owner":"lfkdsk","description":"Bnf-Ast Generator is a parser generator framework for parsing EBNF syntaxes with Java code. Unlike other EBNF-Parser must write config file (like yacc, flex) , with BNF-AST Generator you can define EBNF Parser in Java Code.","archived":false,"fork":false,"pushed_at":"2020-10-12T21:31:00.000Z","size":136,"stargazers_count":15,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"lfkdsk/reset-to-queue-lexer","last_synced_at":"2025-04-03T16:54:44.545Z","etag":null,"topics":["ast","ebnf"],"latest_commit_sha":null,"homepage":"","language":"Java","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/lfkdsk.png","metadata":{"files":{"readme":"README.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":"2018-01-23T03:50:42.000Z","updated_at":"2024-05-24T03:28:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"feaceee9-6c6e-4589-8bc3-1bc2dbf0e239","html_url":"https://github.com/lfkdsk/bnf-ast","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfkdsk%2Fbnf-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfkdsk%2Fbnf-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfkdsk%2Fbnf-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lfkdsk%2Fbnf-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lfkdsk","download_url":"https://codeload.github.com/lfkdsk/bnf-ast/tar.gz/refs/heads/lfkdsk/reset-to-queue-lexer","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247366717,"owners_count":20927568,"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","ebnf"],"created_at":"2024-11-05T15:32:34.970Z","updated_at":"2025-04-05T16:32:27.199Z","avatar_url":"https://github.com/lfkdsk.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EBNF-AST Generator\n\n[![](https://jitpack.io/v/lfkdsk/bnf-ast.svg)](https://jitpack.io/#lfkdsk/bnf-ast)\n![](https://travis-ci.org/lfkdsk/bnf-ast.svg?branch=master)\n[![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/lfkdsk/bnf-ast/blob/master/LICENSE)\n![](https://img.shields.io/badge/java--version-1.8%2B-blue.svg)\n[![Coverage Status](https://coveralls.io/repos/github/lfkdsk/bnf-ast/badge.svg?branch=master)](https://coveralls.io/github/lfkdsk/bnf-ast?branch=master)\n\n*Bnf-Ast Generator* is a parser generator framework for parsing EBNF syntaxes with Java code. Unlike other EBNF-Parser must write `config file` (like yacc, flex) , with BNF-AST Generator you can define EBNF Parser in Java Code.\n\n## Install\n\n* with maven:\n  ``` xml\n  \u003c!-- Step 1. Add the JitPack repository to your build file --\u003e\n  \u003crepositories\u003e\n    \u003crepository\u003e\n       \u003cid\u003ejitpack.io\u003c/id\u003e\n       \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n    \u003c/repository\u003e\n  \u003c/repositories\u003e\n  \u003c!-- Step 2. Add the dependency --\u003e\n  \u003cdependency\u003e\n     \u003cgroupId\u003ecom.github.lfkdsk\u003c/groupId\u003e\n     \u003cartifactId\u003ebnf-ast\u003c/artifactId\u003e\n     \u003cversion\u003ev3.16\u003c/version\u003e\n  \u003c/dependency\u003e\n  ```\n\n## Introduce\n\nAs the library's name \"EBNF-AST Generator\", Developers use combinators defined in [BnfComs](src/main/java/bnfgenast/bnf/BnfCom.java) to define DSL syntaxes in Java Code. Library will auto generate parsers with this syntaxes.\n\nHere is an example for you to for parsing Java `switch` syntax.\n\n``` java\n// define number, string, bool ... primary types, expression, body\n// case: { body }\nBnfCom caseExpr = rule(Case.class).token(\"case\").sep(\":\").then(body);\n\n// default: { body }\nBnfCom defaultExpr = rule(Default.class).token(\"default\").sep(\":\").then(body);\n\n// switch ( expr ) {\n//    case* | default\n// }\nBnfCom switchExpr = rule(Switch.class).token(\"switch\").sep(\"(\").then(expr).sep(\")\")\n  .sep(\"{\")\n  .or(\n  wrapper().repeat(caseExpr),\n    defaultExpr\n).sep(\"}\");\n```\n\nNow you can create a `Lisp` Parser quickly with EBNF-AST Generator: \n\n``` java\nBnfCom number = rule().number(NumberLiteral.class);\nBnfCom id = rule().identifier(IDLiteral.class, reservedToken);\nBnfCom string = rule().string(StringLiteral.class);\nBnfCom bool = rule().bool(BoolLiteral.class);\n\n// primary ::= number | id | string | bool\nBnfCom primary = wrapper().or(number, id, string, bool);\nBnfCom expr0 = rule();\n// quote   ::= `expr\nBnfCom quote = rule().token(\"`\").then(expr0);\n// expr    ::= primary | quote | \"(\" expr* \")\"\nBnfCom expr = expr0.reset().or(primary, quote, rule().sep(\"(\").repeat(expr0).sep(\")\"));\n// problem ::= \"(\" expr* \")\"\nBnfCom problem = rule().sep(\"(\").repeat(expr).sep(\")\");\n```\n\nyou can get more information from Lisp test: [Lisp Syntaxes Test](src/test/java/lisp/LispTest.java).\n\n## Support Combinators\n\n*EBNF-AST Generator* support three types basic Combinators: *leaf*, *list*, *capture* .\n\n### Leaf Combinator\n\nThe leaf combinator corresponds to a leaf node in the AST.\n\n| Combinator Name            | Description                              | Usage                                    |\n| -------------------------- | ---------------------------------------- | ---------------------------------------- |\n| token(*string\\**)          | `token` is used to define a reserved token as an `AstLeaf` in Ast. But token string must be marked as `reversed token` that you can use in token operator. | [Leaf Usage](src/test/java/bnfgenast/bnf/leaf/LeafTest.java) |\n| sep(*string\\**)            | `sep` combinator is used to skip an token, this token won't be used in AST. Just like usually function define `lfkdsk()` , token \"(\", \")\" is useless should be skip. | [Skip Usage](src/test/java/bnfgenast/bnf/leaf/SkipTest.java) |\n| maybe(*string*)            | `maybe` contains this string. token won't be used in AST. | [Maybe Usage](src/test/java/bnfgenast/bnf/leaf/SkipORTest.java) |\n| number(*class*)            | `number`  represents number‘s token，EBNF-AST won't provide a default tokenizer, you should splite number token by yourselves. | [Token Test](src/test/java/bnfgenast/bnf/token/TokenTest.java) |\n| string(*class*)            | `string` represents string's token.      | [Token Test](src/test/java/bnfgenast/bnf/token/TokenTest.java) |\n| bool(*class*)              | `bool` represents boolean's token.       | [Token Test](src/test/java/bnfgenast/bnf/token/TokenTest.java) |\n| id(*class*)                | `id` represents id's token.              | [Token Test](src/test/java/bnfgenast/bnf/token/TokenTest.java) |\n| literal(*class*, *string*) | `literal` expects an literal string in AST. | [Literal Test](src/test/java/bnfgenast/bnf/token/LiteralTest.java) |\n\n### List Combinator\n\nThe list combinator corresponds to the non-leaf node in the AST.\n\n| Combinator Name | Description                              | Usage                                    |\n| --------------- | ---------------------------------------- | ---------------------------------------- |\n| ast / then      | `ast/ then` operator expects a subBnf parser in this parser. | [Leaf Usage](src/test/java/bnfgenast/bnf/leaf/LeafTest.java) |\n| or              | `or` combinator expects one of several possible Parser supporters. | [Or Tree](src/test/java/bnfgenast/bnf/tree/OrTreeTest.java) |\n| maybe           | `maybe` combinator expects a Parser option that may exist. Even `maybe` don't exist, maybe will generate an empty List in AST. | [Maybe Tree](src/test/java/bnfgenast/bnf/tree/MaybeTreeTest.java) |\n| option          | `option` combinator expects a Parser option that may exist. Unlike `maybe`, if the `option` is not triggered, there is no empty node in the AST | [Option Tree](src/test/java/bnfgenast/bnf/tree/OptionTreeTest.java) |\n| repeat          | `repeat` combinator represents a Parser that matches repeatedly. | [Repeat Tree](src/test/java/bnfgenast/bnf/tree/RepeatTest.java) |\n| prefix          | The main function of `prefix` is similar to or, but Parser of `or` can only support Parsers with different prefixes, but `prefix` can support multiple Parsers with different prefixes. | [Prefix Tree](src/test/java/bnfgenast/bnf/tree/PrefixTreeTest.java) |\n| expr            | `expr` support binary operator expressions.(support recursive operator) | [Expr Tree](src/test/java/bnfgenast/bnf/tree/ExprTest.java) |\n| insertChoice    | The` insertChoice` combinator and `or` are used together to insert a new Parser among the alternatives of the or combinator. | [Insert Choice Tree](src/test/java/bnfgenast/bnf/tree/InsertChoiceTest.java) |\n| times           | `times` and `repeat` are closer, but times can be used to specify the number of repeated matches. If the number of matched times is not used, an exception occurs. | [Times Tree](src/test/java/bnfgenast/bnf/tree/TimesTest.java) |\n| least           | `Times`'s' sub-function, could set the minimum value of repeated matches. | [Times Tree](src/test/java/bnfgenast/bnf/tree/TimesTest.java) |\n| most            | `Times`'s' sub-function, could set the maximum value of repeated matches. | [Times Tree](src/test/java/bnfgenast/bnf/tree/TimesTest.java) |\n| range           | `Times`'s' sub-function, could set the minimum and maximum values of repeated matches. | [Times Tree](src/test/java/bnfgenast/bnf/tree/TimesTest.java) |\n\n### Capture Combinator\n\nCapture Combinator is a combination of sub-capture and monitor, we can set the monitor to achieve grammar-guided translation of some of the functions (such as testing node function, collect node data, data processing)\n\n| Combinator Name | Description                              | Usage                                    |\n| --------------- | ---------------------------------------- | ---------------------------------------- |\n| consume         | A callback can be inserted in the process of generating the BNF in the process of automatically generating the AST by the BNF. | [Consume Test](src/test/java/bnfgenast/bnf/capturer/CaptureTest.java) |\n| test            | It is possible to test the correctness of the AST node's information during the automatic generation of the AST by the BNF. | [Test Test](src/test/java/bnfgenast/bnf/capturer/AssertCaptureTest.java) |\n| not             | It is possible to test the correctness of the AST node's information during the automatic generation of the AST by the BNF. | [Not Test](src/test/java/bnfgenast/bnf/capturer/PredicateCaptureTest.java) |\n| collect         | The generated AST node can be collected during the process of automatically generating the AST node by the BNF. | [Collect Test](src/test/java/bnfgenast/bnf/capturer/CollectCaptureTest.java) |\n\n\n## License\n\n[MIT License](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfkdsk%2Fbnf-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flfkdsk%2Fbnf-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flfkdsk%2Fbnf-ast/lists"}