{"id":21453442,"url":"https://github.com/lapets/imparse","last_synced_at":"2025-07-14T23:31:36.858Z","repository":{"id":7516910,"uuid":"8867463","full_name":"lapets/imparse","owner":"lapets","description":"Parser generator that can be used to quickly and succinctly define a parser definition, and to deploy an automatically-generated implementations thereof in multiple languages and on multiple platforms.","archived":false,"fork":false,"pushed_at":"2020-05-08T04:44:29.000Z","size":5252,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-09T03:46:27.452Z","etag":null,"topics":["ll-parser","parse","parser","parser-generator","parser-library","parsers","parsing-library","recursive-descent-parser"],"latest_commit_sha":null,"homepage":"https://imparse.org","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/lapets.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":"2013-03-19T00:28:30.000Z","updated_at":"2021-03-04T09:58:20.000Z","dependencies_parsed_at":"2022-08-24T23:53:50.276Z","dependency_job_id":null,"html_url":"https://github.com/lapets/imparse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fimparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fimparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fimparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fimparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lapets","download_url":"https://codeload.github.com/lapets/imparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226002934,"owners_count":17558153,"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":["ll-parser","parse","parser","parser-generator","parser-library","parsers","parsing-library","recursive-descent-parser"],"created_at":"2024-11-23T04:39:39.207Z","updated_at":"2024-11-23T04:39:39.775Z","avatar_url":"https://github.com/lapets.png","language":"JavaScript","readme":"# imparse\n\nLightweight infinite-lookahead parser generator that supports basic grammars defined in a JSON format. More information and interactive examples are available at [imparse.org](http://imparse.org).\n\n[![npm version and link.](https://badge.fury.io/js/imparse.svg)](https://badge.fury.io/js/imparse)\n\nThis library makes it possible to rapidly assemble and deploy a parser for a simple language. It is intended primarily for languages that have an [LL grammar](https://en.wikipedia.org/wiki/LL_grammar).\n\n## Usage\n\n### Representation of Grammars\n\nSuppose we want to represent a grammar of basic arithmetic expressions in the following way (assuming that operators will associate to the right):\n```javascript\nvar grammar = [ \n  {\"Term\": [\n    {\"Add\": [[\"Factor\"], \"+\", [\"Term\"]]},\n    {\"\": [[\"Factor\"]]}\n  ]},\n  {\"Factor\": [\n    {\"Mul\": [[\"Atom\"], \"*\", [\"Factor\"]]},\n    {\"\": [[\"Atom\"]]}\n  ]},\n  {\"Atom\": [\n    {\"Num\": [{\"RegExp\":\"[0-9]+\"}]}\n  ]}\n];\n```\nIt is assumed that grammars are represented as nested objects according to the following conventions:\n\n* a *grammar* consists of an array of production rules;\n* each *production rule* is represented by an object that maps the name of its non-terminal to an array of possible cases;\n* each *case* is represented by an object that maps a case name to a sequence of terminals and non-terminals; and\n* each *entry* in a case sequence can be a terminal (represented as a string), non-terminal (represented by a singleton array with a non-terminal string), or regular expression (represented as an object with a single key `\"RegExp\"` that maps to the actual regular expression string).\n\nNote that the *case name* (i.e., the sole key in each case object) is used within any abstract syntax tree node constructed according to that case. For example, if a token sequence or string is parsed successfully according to the case sequence `{\"Add\": [[\"Factor\"], \"+\", [\"Term\"]]}`, then the resulting abstract syntax tree will be of the form `{\"Add\":[...]}`.\n\n### Basic Parsing\n\nIt is possible to parse a string according to the grammar in the following way:\n```javascript\nimparse.parse(grammar, '1*2 + 3*4')\n```\nThe above yields the following abstract syntax tree:\n```javascript\n{\"Add\":[\n  {\"Mul\":[{\"Num\":[\"1\"]},{\"Num\":[\"2\"]}]},\n  {\"Mul\":[{\"Num\":[\"3\"]},{\"Num\":[\"4\"]}]}\n]}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flapets%2Fimparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flapets%2Fimparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flapets%2Fimparse/lists"}