{"id":28629764,"url":"https://github.com/codebox/top-down-parser","last_synced_at":"2025-06-12T12:13:31.510Z","repository":{"id":57378037,"uuid":"160942980","full_name":"codebox/top-down-parser","owner":"codebox","description":"A simple top-down parser written in JavaScript","archived":false,"fork":false,"pushed_at":"2018-12-27T13:21:31.000Z","size":63,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-25T04:21:34.323Z","etag":null,"topics":["es6","javascript","parser"],"latest_commit_sha":null,"homepage":"https://codebox.net/pages/top-down-parser-in-javascript","language":"JavaScript","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/codebox.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}},"created_at":"2018-12-08T13:40:58.000Z","updated_at":"2023-10-26T13:33:35.000Z","dependencies_parsed_at":"2022-09-19T19:06:26.545Z","dependency_job_id":null,"html_url":"https://github.com/codebox/top-down-parser","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/codebox/top-down-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Ftop-down-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Ftop-down-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Ftop-down-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Ftop-down-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codebox","download_url":"https://codeload.github.com/codebox/top-down-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebox%2Ftop-down-parser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259462578,"owners_count":22861514,"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":["es6","javascript","parser"],"created_at":"2025-06-12T12:13:30.778Z","updated_at":"2025-06-12T12:13:31.500Z","avatar_url":"https://github.com/codebox.png","language":"JavaScript","readme":"# Top-Down Parser\n\nA simple top-down parser written in JavaScript. Every so often I need to write a parser, and keep forgetting how the recursion works.\n This is a simple- and general-as-possible implementation that I can refer back to in the future.\n \nTo use the parser, call the `buildParser()` function with a single string argument containing the grammar. \nEach production rule in the grammar should be on a separate line, and the symbol should be followed by the character sequence `-\u003e`,\n and then by the substitutions. The symbol `|` is used as a delimiter on the RHS of a rule if there are multiple valid substitutions. \n \nBy default the start symbol is the text `START` and `ε` is used to represent an empty string, \n alternate values can be supplied when calling `buildParser()`.  \n\nI have used several ES6 language features in the code, so this won't work in older browsers.\n\n## Example\n\n    const parser = buildParser(`\n        START -\u003e EXPR\n        EXPR  -\u003e NUM | NUM OP EXPR\n        NUM   -\u003e 0 | 1 | 2 | 3 | 4\n        OP    -\u003e + | - | * | /\n    `);\n    \n    parser.parse('1 + 2')\n\nWill return:\n\n    {\n        'remainder : '',\n        'tree' : {\n            'START' : [\n                {'EXPR' : [\n                    {'NUM' : ['1']},\n                    {'OP' : ['+']},\n                    {'EXPR' : [\n                        {'NUM' : ['2']},\n                    ]}\n                ]}\n            ]\n        }\n    }","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebox%2Ftop-down-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodebox%2Ftop-down-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebox%2Ftop-down-parser/lists"}